forked from mirror/busybox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ash: allow shell scripts to be embedded in the binary
To assist in the deployment of shell scripts it may be convenient to embed them in the BusyBox binary. 'Embed scripts in the binary' takes any files in the directory 'embed', concatenates them with null separators, compresses them and embeds them in the binary. When scripts are embedded in the binary, scripts can be run as 'busybox SCRIPT [ARGS]' or by usual (sym)link mechanism. embed/nologin is provided as an example. function old new delta packed_scripts - 123 +123 unpack_scripts - 87 +87 ash_main 1103 1171 +68 run_applet_and_exit 78 128 +50 get_script_content - 32 +32 script_names - 10 +10 expmeta 663 659 -4 ------------------------------------------------------------------------------ (add/remove: 4/0 grow/shrink: 2/1 up/down: 370/-4) Total: 366 bytes Signed-off-by: Ron Yorston <[email protected]> Signed-off-by: Denys Vlasenko <[email protected]>
- Loading branch information
Denys Vlasenko
committed
Nov 1, 2018
1 parent
5527967
commit 4f2ef4a
Showing
9 changed files
with
201 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/sh | ||
|
||
target="$1" | ||
loc="$2" | ||
|
||
test "$target" || exit 1 | ||
test "$SED" || SED=sed | ||
test "$DD" || DD=dd | ||
|
||
# Some people were bitten by their system lacking a (proper) od | ||
od -v -b </dev/null >/dev/null | ||
if test $? != 0; then | ||
echo 'od tool is not installed or cannot accept "-v -b" options' | ||
exit 1 | ||
fi | ||
|
||
exec >"$target.$$" | ||
|
||
scripts="" | ||
if [ -d "$loc" ] | ||
then | ||
scripts=$(cd $loc; ls * 2>/dev/null) | ||
fi | ||
|
||
n=$(echo $scripts | wc -w) | ||
|
||
if [ $n -ne 0 ] | ||
then | ||
printf '#ifdef DEFINE_script_names\n' | ||
printf 'const char script_names[] ALIGN1 = ' | ||
for i in $scripts | ||
do | ||
printf '"%s\\0"' $i | ||
done | ||
printf '"\\0";\n' | ||
printf '#else\n' | ||
printf 'extern const char script_names[] ALIGN1;\n' | ||
printf '#endif\n' | ||
fi | ||
printf "#define NUM_SCRIPTS $n\n\n" | ||
|
||
if [ $n -ne 0 ] | ||
then | ||
printf '#define UNPACKED_SCRIPTS_LENGTH ' | ||
for i in $scripts | ||
do | ||
cat $loc/$i | ||
printf '\000' | ||
done | wc -c | ||
|
||
printf '#define PACKED_SCRIPTS \\\n' | ||
for i in $scripts | ||
do | ||
cat $loc/$i | ||
printf '\000' | ||
done | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \ | ||
| grep -v '^ ' \ | ||
| $SED -e 's/^[^ ]*//' \ | ||
-e 's/ //g' \ | ||
-e '/^$/d' \ | ||
-e 's/\(...\)/0\1,/g' \ | ||
-e 's/$/ \\/' | ||
printf '\n' | ||
fi | ||
|
||
mv -- "$target.$$" "$target" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters