This repository has been archived by the owner on Nov 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb.bat
145 lines (117 loc) · 3.3 KB
/
bb.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
: ; [ $# -gt 0 ] || exec sed -n "s/^:: \?//p" << '::::'
:: 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 "script"
::
:: 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
::::
: << '____CMD____'
@echo off
setlocal
set "BB_EXE="
:: First: look for the latest instance next to this script
if not defined BB_EXE for /f "tokens=*" %%f in ( '
dir /b /o-n "%~dp0busybox*.exe" 2^>nul
' ) do if not defined BB_EXE if exist "%~dp0%%~f" set "BB_EXE=%~dp0%%~f"
:: Second: look for the instance in $PATH
for %%f in (
busybox.exe
busybox64.exe
) do if not defined BB_EXE if not "%%~$PATH:f" == "" set "BB_EXE=%%~$PATH:f"
:: Fail, if BusyBox not found and download not required
if not defined BB_EXE if /i not "%~1" == "--download" (
2>nul echo:ERROR: BusyBox executable not found
exit /b 1
)
:: ========================================================================
:: Try to download
if /i "%~1" == "--download" (
for %%p in ( "powershell.exe" ) do if "%%~$PATH:p" == "" (
>&2 echo:%%p is required
goto :EOF
)
set "BB_URL="
set "BB_DST="
if /i "%~2" == "win32" (
set "BB_URL=https://frippery.org/files/busybox/busybox.exe"
set "BB_DST=%~dp0busybox.exe"
) else if /i "%~2" == "win64" (
set "BB_URL=https://frippery.org/files/busybox/busybox64.exe"
set "BB_DST=%~dp0busybox64.exe"
) else (
>&2 echo:win32 or win64 required
goto :EOF
)
echo:Downloading started...
set BB_URL
set BB_DST
powershell -NoLogo -NoProfile -Command "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;$w=New-Object System.Net.WebClient;$w.DownloadFile($Env:BB_URL,$Env:BB_DST)"
echo:Downloading completed
goto :EOF
)
:: ========================================================================
:: Locate the history file in the $TEMP directory
set "HISTFILE=%TEMP%\.ash_history"
:: Locate the history file next to Busybox executable
::set "HISTFILE=%~dp0.ash_history"
:: Another way to locate the history file is to set HOME dir
::for %%p in ( "%~dp0." ) do set "HOME=%%~fp"
:: ========================================================================
if defined BB_DEBUG (
@prompt +$S
@echo on
)
"%BB_EXE%" sh "%~f0" %*
exit /b %ERRORLEVEL%
:: ========================================================================
____CMD____
case "$1" in
'' )
# It'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
[[ ";$PATH;" =~ ";$( dirname "$0" );" ]] \
|| PATH="$( dirname "$0" );$PATH"
[ -z "$BB_DEBUG" ] || set -x
case "$1" in
-* | +* )
sh "$@"
;;
* )
eval 'exec "$@"'
;;
esac
# =========================================================================
# EOF