aboutsummaryrefslogtreecommitdiff
path: root/scripts/embedded_scripts
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-11-01 09:53:25 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-11-01 10:15:13 +0100
commit4f2ef4a836be37b25808c94f41c7c85895db6f93 (patch)
treee224e4f3b8513b35655da80b26369d42bd62d24d /scripts/embedded_scripts
parent552796791f8c5aa12dfb790e3a94c2d905f367ee (diff)
downloadbusybox-w32-4f2ef4a836be37b25808c94f41c7c85895db6f93.tar.gz
busybox-w32-4f2ef4a836be37b25808c94f41c7c85895db6f93.tar.bz2
busybox-w32-4f2ef4a836be37b25808c94f41c7c85895db6f93.zip
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 <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'scripts/embedded_scripts')
-rwxr-xr-xscripts/embedded_scripts66
1 files changed, 66 insertions, 0 deletions
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts
new file mode 100755
index 000000000..986e85160
--- /dev/null
+++ b/scripts/embedded_scripts
@@ -0,0 +1,66 @@
1#!/bin/sh
2
3target="$1"
4loc="$2"
5
6test "$target" || exit 1
7test "$SED" || SED=sed
8test "$DD" || DD=dd
9
10# Some people were bitten by their system lacking a (proper) od
11od -v -b </dev/null >/dev/null
12if test $? != 0; then
13 echo 'od tool is not installed or cannot accept "-v -b" options'
14 exit 1
15fi
16
17exec >"$target.$$"
18
19scripts=""
20if [ -d "$loc" ]
21then
22 scripts=$(cd $loc; ls * 2>/dev/null)
23fi
24
25n=$(echo $scripts | wc -w)
26
27if [ $n -ne 0 ]
28then
29 printf '#ifdef DEFINE_script_names\n'
30 printf 'const char script_names[] ALIGN1 = '
31 for i in $scripts
32 do
33 printf '"%s\\0"' $i
34 done
35 printf '"\\0";\n'
36 printf '#else\n'
37 printf 'extern const char script_names[] ALIGN1;\n'
38 printf '#endif\n'
39fi
40printf "#define NUM_SCRIPTS $n\n\n"
41
42if [ $n -ne 0 ]
43then
44 printf '#define UNPACKED_SCRIPTS_LENGTH '
45 for i in $scripts
46 do
47 cat $loc/$i
48 printf '\000'
49 done | wc -c
50
51 printf '#define PACKED_SCRIPTS \\\n'
52 for i in $scripts
53 do
54 cat $loc/$i
55 printf '\000'
56 done | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
57 | grep -v '^ ' \
58 | $SED -e 's/^[^ ]*//' \
59 -e 's/ //g' \
60 -e '/^$/d' \
61 -e 's/\(...\)/0\1,/g' \
62 -e 's/$/ \\/'
63 printf '\n'
64fi
65
66mv -- "$target.$$" "$target"