<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15822&amp;type=atom" />
	<updated>2021-08-30T11:37:55Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=15822</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149410#p149410" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>DnsIs пишет:</cite><blockquote><p>чем не устраивает такой вариант</p></blockquote></div><p>Лишние сущности. Хардлинки - хорошо, но плохо распознаются при копировании (бекап). Софтлинки в busybox не работают (по крайней мере, у меня на Win10).</p><div class="quotebox"><cite>DnsIs пишет:</cite><blockquote><p>За clp огромное спасибо</p></blockquote></div><p>Пожалуйста. Аналогичная функция под Cygwin чуточку проще - там не используются Powershell и команда clip, а чтение/запись осуществляется через псевдоустройство /dev/clipboard.</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2021-08-30T11:37:55Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149410#p149410</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=149402#p149402" />
			<content type="html"><![CDATA[<p><strong>Rumata</strong>, а чем не устраивает такой вариант:<br /></p><div class="codebox"><pre><code>busybox --install C:\path\to\directory

Omitting the directory will result in the links being made in the same directory
as the busybox.exe executable you&#039;re running. The --install option creates &#039;hard&#039;
links which are available on NTFS filesystems but not FAT.
Adding the option -s creates symbolic links, but this may not work if you don&#039;t
have the required privileges.</code></pre></div><br /><p><strong>PS За clp огромное спасибо. </strong></p>]]></content>
			<author>
				<name><![CDATA[DnsIs]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26282</uri>
			</author>
			<updated>2021-08-30T08:36:14Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=149402#p149402</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148713#p148713" />
			<content type="html"><![CDATA[<p>Улучшил скрипт для работы с буфером обмена<br />-- копирование из буфера работает правильно<br />-- поддерживаются опции опции для манипуляций с переводами строк</p><p>-u - в юникс-стиле (LF)<br />-d - в дос-стиле (CRLF)</p><p>Все изменения -- в первом сообщении.</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2021-06-30T17:04:40Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148713#p148713</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=148029#p148029" />
			<content type="html"><![CDATA[<p>- перенес обработку параметров командной строки в shell (за исключением --download)<br />- добавил <strong>clp</strong>, внешний скрипт для работы с буфером обмена с обе стороны (копировать в буфер и из буфера)<br />- добавлена проверка переменной окружения $PATH, при необходимости добавляется путь до BusyBox</p><p>Все изменения -- в первом сообщении.</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2021-05-22T05:46:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=148029#p148029</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147368#p147368" />
			<content type="html"><![CDATA[<p>-- добавил поддержку переменной <strong>BB_DEBUG</strong> для отображения процесса запуска<br />-- косметические изменения<br />-- начальный пост отредактирован обновлением исходного кода</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2021-04-16T12:34:59Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147368#p147368</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=147272#p147272" />
			<content type="html"><![CDATA[<p>-- добавил опции <strong>--download win32</strong> и <strong>--download win64</strong><br />-- улучшил и систематизировал способы вызова внутренних функций, внешних команд и однострочных сборных команд</p><p>Последняя на данный момента версия -- в первом сообщении. Все актуальные изменения -- по ссылке.</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2021-04-12T07:11:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=147272#p147272</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=143506#p143506" />
			<content type="html"><![CDATA[<p>Немного &quot;косметических&quot; изменений:<br />-- чуть расширил страницу справки скрипта<br />-- расширил обработку основных опций BusyBox: <strong>--help</strong>, <strong>--list</strong>, <strong>--list-full</strong><br />-- удалил javascript код<br />-- полная справка выводится только средствами самого BusyBox и только при его наличии<br />-- улучшил поиск самого BusyBox</p>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2020-11-16T21:24:18Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=143506#p143506</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: BusyBox запускалка, BusyBox Runner]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=143416#p143416" />
			<content type="html"><![CDATA[<p>Доработал обертку-запускалку для BusyBox, компактного набора консольных утилит Юникс. </p><h5>Требования</h5><p>Для работы необходимо:</p><p>-- Загрузить скрипт bb.bat из репозитория <a href="https://github.com/ildar-shaimordanov/my-scripts/tree/master/cmd/busybox">https://github.com/ildar-shaimordanov/m … md/busybox</a>.<br />-- Загрузить сам BusyBox со страницы <a href="https://frippery.org/busybox/">https://frippery.org/busybox/</a> (любая, 64- или 32-битная, по вашему желанию).<br />-- Поместить оба файла в каталог, видимый из переменной окружения $PATH.</p><p>или...</p><p>-- Загрузить скрипт bb.bat из репозитория <a href="https://github.com/ildar-shaimordanov/my-scripts/tree/master/cmd/busybox">https://github.com/ildar-shaimordanov/m … md/busybox</a>.<br />-- Поместить файл в каталог, видимый из переменной окружения $PATH.<br />-- Чтобы загрузить последнюю версию 32-битной или 64-битной сборки BusyBox, выполнить одну из команд, соответственно: </p><div class="codebox"><pre><code>bb --download win32</code></pre></div><p> или </p><div class="codebox"><pre><code>bb --download win64</code></pre></div><p>Загруженный файл сохранется в одном каталоге со скриптом. Для загрузки требуется PowerShell.</p><h5>Применение</h5><p><strong>1. Запуск встроенных функций BusyBox</strong></p><p>Запустить функцию и передать, если необходимо, опции:</p><div class="codebox"><pre><code>bb function [function-options]</code></pre></div><p>Фактически, это тоже самое, что делает BusyBox:</p><div class="codebox"><pre><code>busybox function [function-options]</code></pre></div><p><strong>2. Запуск команды или скрипта из переменной $PATH</strong></p><p>Выполнить внешнюю команду или скрипт, найденные в переменной $PATH или казанные по абсолютному или относительному пути:</p><div class="codebox"><pre><code>bb [shell-options] [DIR]command [command-options]</code></pre></div><div class="codebox"><pre><code>busybox [sh [shell-options]] [DIR]command [command-options]</code></pre></div><p><strong>3. Запуск однострочного скрипта</strong></p><div class="codebox"><pre><code>bb [shell-options] -c &quot;script&quot;</code></pre></div><div class="codebox"><pre><code>busybox sh [shell-options] -c &quot;script&quot;</code></pre></div><h5>Исходный код</h5><p>Актуальные на момент написания этого текста версии скриптов.</p><p><strong>bb.bat</strong></p><div class="codebox"><pre><code>
: ; [ $# -gt 0 ] || exec sed -n &quot;s/^:: \?//p&quot; &lt;&lt; &#039;::::&#039;
:: Simplify running scripts and commands with BusyBox
::
:: USAGE
::   Print BusyBox help pages
::     bb --help
::     bb --version
::     bb --list[-full]
::
::   Run a built-in BusyBox function
::     bb function [function-options]
::
::   Run an executable from $PATH or specified with DIR
::     bb [shell-options] [DIR]command [command-options]
::
::   Run a one-liner script
::     bb [shell-options] -c &quot;script&quot;
::
::   Download the latest 32-bit or 64-bit build of BusyBox
::     bb --download win32
::     bb --download win64
::
:: SEE ALSO
::   Learn more about BusyBox following these links:
::
::   https://busybox.net/
::   https://frippery.org/busybox/
::   https://github.com/rmyorston/busybox-w32
::::
: &lt;&lt; &#039;____CMD____&#039;
@echo off

setlocal

set &quot;BB_EXE=&quot;

:: First: look for the latest instance next to this script
if not defined BB_EXE for /f &quot;tokens=*&quot; %%f in ( &#039;
	dir /b /o-n &quot;%~dp0busybox*.exe&quot; 2^&gt;nul
&#039; ) do if not defined BB_EXE if exist &quot;%~dp0%%~f&quot; set &quot;BB_EXE=%~dp0%%~f&quot;

:: Second: look for the instance in $PATH
for %%f in (
	busybox.exe
	busybox64.exe
) do if not defined BB_EXE if not &quot;%%~$PATH:f&quot; == &quot;&quot; set &quot;BB_EXE=%%~$PATH:f&quot;

:: Fail, if BusyBox not found and download not required
if not defined BB_EXE if /i not &quot;%~1&quot; == &quot;--download&quot; (
	2&gt;nul echo:ERROR: BusyBox executable not found
	exit /b 1
)

:: ========================================================================

:: Try to download
if /i &quot;%~1&quot; == &quot;--download&quot; (
	for %%p in ( &quot;powershell.exe&quot; ) do if &quot;%%~$PATH:p&quot; == &quot;&quot; (
		&gt;&amp;2 echo:%%p is required
		goto :EOF
	)

	set &quot;BB_URL=&quot;
	set &quot;BB_DST=&quot;

	if /i &quot;%~2&quot; == &quot;win32&quot; (
		set &quot;BB_URL=https://frippery.org/files/busybox/busybox.exe&quot;
		set &quot;BB_DST=%~dp0busybox.exe&quot;
	) else if /i &quot;%~2&quot; == &quot;win64&quot; (
		set &quot;BB_URL=https://frippery.org/files/busybox/busybox64.exe&quot;
		set &quot;BB_DST=%~dp0busybox64.exe&quot;
	) else (
		&gt;&amp;2 echo:win32 or win64 required
		goto :EOF
	)

	echo:Downloading started...
	set BB_URL
	set BB_DST

	powershell -NoLogo -NoProfile -Command &quot;[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;$w=New-Object System.Net.WebClient;$w.DownloadFile($Env:BB_URL,$Env:BB_DST)&quot;

	echo:Downloading completed

	goto :EOF
)

:: ========================================================================

:: Locate the history file in the $TEMP directory
set &quot;HISTFILE=%TEMP%\.ash_history&quot;

:: Locate the history file next to Busybox executable
::set &quot;HISTFILE=%~dp0.ash_history&quot;

:: Another way to locate the history file is to set HOME dir
::for %%p in ( &quot;%~dp0.&quot; ) do set &quot;HOME=%%~fp&quot;

:: ========================================================================

if defined BB_DEBUG (
	@prompt +$S
	@echo on
)

&quot;%BB_EXE%&quot; sh &quot;%~f0&quot; %*
exit /b %ERRORLEVEL%

:: ========================================================================

____CMD____

case &quot;$1&quot; in
&#039;&#039; )
	# It&#039;s never reachable part - learn why at the top of the script
	exit
	;;
--help | --list | --list-full )
	busybox $1
	exit
	;;
--version )
	busybox --help | head -2
	exit
	;;
esac

# Add the BusyBox location to the $PATH
[[ &quot;;$PATH;&quot; =~ &quot;;$( dirname &quot;$0&quot; );&quot; ]] \
|| PATH=&quot;$( dirname &quot;$0&quot; );$PATH&quot;

[ -z &quot;$BB_DEBUG&quot; ] || set -x

case &quot;$1&quot; in
-* | +* )
	sh &quot;$@&quot;
	;;
* )
	eval &#039;exec &quot;$@&quot;&#039;
	;;
esac

# =========================================================================

# EOF
</code></pre></div><p><strong>clp</strong></p><p>Скрипт для работы с буфером обмена в обе стороны (копировать в буфер, копировать из буфера)</p><p><a href="https://github.com/ildar-shaimordanov/my-scripts/tree/master/shell/clipboard">https://github.com/ildar-shaimordanov/m … /clipboard</a></p><div class="codebox"><pre><code>
#!/bin/sh

# =========================================================================

CLIP_GET=&#039;&#039;
CLIP_PUT=&#039;&#039;
CLIP_DEV=&#039;&#039;
CLIP_IMP=&#039;&#039;

CLIP_EOL=&#039;&#039;
DOS2UNIX=&#039;&#039;
UNIX2DOS=&#039;&#039;

CLIP_ENC=&#039;&#039;
ICONV=&#039;&#039;

VERBOSELY=&#039;&#039;

# =========================================================================

print_usage() {
	echo &quot;\
Copy data from and/or to the clipboard

Usage:
	clp [OPTIONS]
	clp [OPTIONS] | ...
	... | clp [OPTIONS]

Formatting options
	-u	dos2unix
	-d	unix2dos

Encoding options
	-f encoding
	-t encoding
		Encodings for input and output, respectively
	-c	Discard silently unconvertible characters

Information options
	-h	Display this help message
	-v	Display the executable command
	-V	Display versions of tools
&quot;
}

# shellcheck disable=SC3028
print_version() {
	exec 2&gt;/dev/null
	uname -s || cmd /c ver || echo &quot;${OSTYPE:-${OS:-unknown}}&quot;
	printf &#039;imp=%s eol=%s enc=%s\n&#039; \
		&quot;${CLIP_DEV:-${CLIP_IMP:-${CLIP_GET%% *},${CLIP_PUT%% *}}}&quot; \
		&quot;${DOS2UNIX%% *},${UNIX2DOS%% *}&quot; \
		&quot;${ICONV%% *}&quot;
}

# =========================================================================

die() {
	warn &quot;$*&quot;
	exit 1
}

warn() {
	echo &quot;$*&quot;&gt;&amp;2
}

not_supported() {
	warn &quot;$1 not supported&quot;
}

# =========================================================================

# shellcheck disable=SC2016
getclip() {
	posh \
	&#039;Get-Clipboard -Raw | Write-Host -NoNewLine&#039;
}

# shellcheck disable=SC2016
putclip() {
	posh \
	&#039;$b = @(); $i = [Console]::OpenStandardInput();&#039; \
	&#039;do { $b += @{ c = 0; d = [byte[]]::new(1048576) } }&#039; \
	&#039;while ( $b[-1].c = $i.Read($b[-1].d, 0, $b[-1].d.count) )&#039; \
	&#039;$a = $b | ForEach-Object { $_.d[0..($_.c - 1)] };&#039; \
	&#039;[System.Text.Encoding]::UTF8.GetString($a) | Set-Clipboard&#039;
}

posh() {
	powershell -NoLogo -NoProfile -ExecutionPolicy Bypass -Command &quot;$*&quot;
}

# =========================================================================

# shellcheck disable=SC3028
case &quot;$OSTYPE&quot; in
darwin*	) CLIP_OS=darwin ;;
*	) CLIP_OS=&#039;&#039; ;;
esac

if command -v xsel &gt;/dev/null
then
	# Unixes: first attempt - preferable way
	CLIP_GET=&#039;xsel --clipboard --output&#039;
	CLIP_PUT=&#039;xsel --clipboard --input&#039;
elif command -v xclip &gt;/dev/null
then
	# Unixes: second attempt - another way
	CLIP_GET=&#039;xclip -selection clipboard -out&#039;
	CLIP_PUT=&#039;xclip -selection clipboard -in&#039;
elif [ &quot;$CLIP_OS&quot; = &quot;darwin&quot; ]
then
	# OSX? It has its own way
	command -v pbpaste &gt;/dev/null &amp;&amp; CLIP_GET=&#039;pbpaste&#039;
	command -v pbcopy  &gt;/dev/null &amp;&amp; CLIP_PUT=&#039;pbcopy&#039;
elif [ -c /dev/clipboard ]
then
	# Cygwin?
	CLIP_DEV=&#039;/dev/clipboard&#039;
	CLIP_GET=&quot;cat - &lt; $CLIP_DEV&quot;
	CLIP_PUT=&quot;cat - &gt; $CLIP_DEV&quot;
elif [ &quot;$OS&quot; = &quot;Windows_NT&quot; ] &amp;&amp; command -v powershell &gt;/dev/null
then
	# BusyBox, UnxUtils or something else similar?
	CLIP_IMP=&#039;powershell&#039;
	CLIP_GET=&#039;getclip&#039;
	CLIP_PUT=&#039;putclip&#039;
fi

# =========================================================================

if command -v dos2unix &gt;/dev/null
then
	DOS2UNIX=dos2unix
elif command -v sed &gt;/dev/null
then
	DOS2UNIX=&#039;sed &quot;s/\r$//&quot;&#039;
elif command -v awk &gt;/dev/null
then
	DOS2UNIX=&#039;awk -v RS=&quot;\r?\n&quot; -v ORS=&quot;\n&quot; 1&#039;
elif command -v gawk &gt;/dev/null
then
	DOS2UNIX=&#039;gawk -v RS=&quot;\r?\n&quot; -v ORS=&quot;\n&quot; 1&#039;
fi

if command -v unix2dos &gt;/dev/null
then
	UNIX2DOS=unix2dos
elif command -v sed &gt;/dev/null
then
	UNIX2DOS=&#039;sed &quot;s/[^\r]$/&amp;\r/&quot;&#039;
elif command -v awk &gt;/dev/null
then
	UNIX2DOS=&#039;awk -v RS=&quot;\r?\n&quot; -v ORS=&quot;\r\n&quot; 1&#039;
elif command -v gawk &gt;/dev/null
then
	UNIX2DOS=&#039;gawk -v RS=&quot;\r?\n&quot; -v ORS=&quot;\r\n&quot; 1&#039;
fi

# =========================================================================

if command -v iconv &gt;/dev/null
then
	ICONV=&#039;iconv&#039;
fi

# =========================================================================

while getopts &quot;:hVvudf:t:c&quot; arg
do
	case &quot;$arg&quot; in
	h ) print_usage ; exit ;;
	V ) print_version ; exit ;;
	v ) VERBOSELY=1 ;;

	u ) CLIP_EOL=&quot;$DOS2UNIX&quot; ; [ -n &quot;$CLIP_EOL&quot; ] || not_supported dos2unix ;;
	d ) CLIP_EOL=&quot;$UNIX2DOS&quot; ; [ -n &quot;$CLIP_EOL&quot; ] || not_supported unix2dos ;;

	f | t | c )
		CLIP_ENC=&quot;$ICONV&quot;
		CLIP_ENC_OPTS=&quot;$CLIP_ENC_OPTS -$arg$OPTARG&quot;
		[ -n &quot;$CLIP_ENC&quot; ] || not_supported iconv
		;;

	: ) die &quot;Argument expected for -$OPTARG&quot; ;;
	* ) die &quot;Illegal option: -$OPTARG&quot; ;;
	esac
done

if [ -t 0 ]
then
	# clp
	# clp | ...
	[ -n &quot;$CLIP_GET&quot; ] || die &quot;No tool to paste from clipboard&quot;
	CLIP_RUN=&quot;$CLIP_GET&quot;
	CLIP_RUN=&quot;$CLIP_RUN${CLIP_EOL:+ | $CLIP_EOL}&quot;
	CLIP_RUN=&quot;$CLIP_RUN${CLIP_ENC:+ | $CLIP_ENC$CLIP_ENC_OPTS}&quot;
elif [ -t 1 ]
then
	# ... | clp
	[ -n &quot;$CLIP_PUT&quot; ] || die &quot;No tool to copy to clipboard&quot;
	CLIP_RUN=&quot;$CLIP_PUT&quot;
	CLIP_RUN=&quot;${CLIP_EOL:+$CLIP_EOL | }$CLIP_RUN&quot;
	CLIP_RUN=&quot;${CLIP_ENC:+$CLIP_ENC$CLIP_ENC_OPTS | }$CLIP_RUN&quot;
fi

# ... | clp | ...
[ -n &quot;$CLIP_RUN&quot; ] || die &quot;Useless use in the middle of the pipe&quot;

[ -n &quot;$VERBOSELY&quot; ] &amp;&amp; set -x
eval &quot;$CLIP_RUN&quot;

# =========================================================================

# EOF
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2020-11-10T12:38:13Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=143416#p143416</id>
		</entry>
</feed>
