aboutsummaryrefslogtreecommitdiff
path: root/scripts/embedded_scripts
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-11-17 17:48:14 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2018-11-17 21:16:33 +0100
commit3778898f97a64e7b42b53194af7f3b93cc9c07a3 (patch)
tree9452b954be8861feff32a40072615ee95caaa4c6 /scripts/embedded_scripts
parente6a63bf683f47027d36dc21b62b2f5cc3eb30a30 (diff)
downloadbusybox-w32-3778898f97a64e7b42b53194af7f3b93cc9c07a3.tar.gz
busybox-w32-3778898f97a64e7b42b53194af7f3b93cc9c07a3.tar.bz2
busybox-w32-3778898f97a64e7b42b53194af7f3b93cc9c07a3.zip
Treat custom and applet scripts as applets
BusyBox has support for embedded shell scripts. Two types can be distinguished: custom scripts and scripts implementing applets. Custom scripts should be placed in the 'embed' directory at build time. They are given a default applet configuration and appear as applets to the user but no further configuration is possible. Applet scripts are integrated with the BusyBox build system and are intended to be used to ship standard applets that just happen to be implemented as scripts. They can be configured at build time and appear just like native applets. Such scripts should be placed in the 'applets_sh' directory. A stub C program should be written to provide the usual applet configuration details and placed in a suitable subsystem directory. It may be helpful to have a configuration option to enable any dependencies the script requires: see the 'nologin' applet for an example. function old new delta scripted_main - 41 +41 applet_names 2773 2781 +8 applet_main 1600 1604 +4 i2cdetect_main 672 674 +2 applet_suid 100 101 +1 applet_install_loc 200 201 +1 applet_flags 100 101 +1 packed_usage 33180 33179 -1 tryexec 159 152 -7 evalcommand 1661 1653 -8 script_names 9 - -9 packed_scripts 123 114 -9 complete_cmd_dir_file 826 811 -15 shellexec 271 254 -17 find_command 1007 990 -17 busybox_main 642 624 -18 run_applet_and_exit 100 78 -22 find_script_by_name 51 - -51 ------------------------------------------------------------------------------ (add/remove: 1/2 grow/shrink: 6/9 up/down: 58/-174) Total: -116 bytes text data bss dec hex filename 950034 477 7296 957807 e9d6f busybox_old 949918 477 7296 957691 e9cfb busybox_unstripped 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_scripts107
1 files changed, 82 insertions, 25 deletions
diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts
index 7245ba6e0..b7a023ce0 100755
--- a/scripts/embedded_scripts
+++ b/scripts/embedded_scripts
@@ -1,7 +1,8 @@
1#!/bin/sh 1#!/bin/sh
2 2
3target="$1" 3target="$1"
4loc="$2" 4custom_loc="$2"
5applet_loc="$3"
5 6
6test "$target" || exit 1 7test "$target" || exit 1
7test "$SED" || SED=sed 8test "$SED" || SED=sed
@@ -14,46 +15,102 @@ if test $? != 0; then
14 exit 1 15 exit 1
15fi 16fi
16 17
17exec >"$target.$$" 18custom_scripts=""
18 19if [ -d "$custom_loc" ]
19scripts=""
20if [ -d "$loc" ]
21then 20then
22 scripts=$(cd $loc; ls * 2>/dev/null) 21 custom_scripts=$(cd $custom_loc; ls * 2>/dev/null)
23fi 22fi
23all_scripts=$(applets/busybox.mkscripts)
24
25# all_scripts includes applet scripts and custom scripts, sort them out
26applet_scripts=""
27for i in $all_scripts
28do
29 found=0
30 for j in $custom_scripts
31 do
32 if [ "$i" = "$j" ]
33 then
34 found=1
35 break;
36 fi
37 done
38 if [ $found -eq 0 ]
39 then
40 # anything that isn't a custom script is an applet script
41 applet_scripts="$applet_scripts $i"
42 fi
43done
24 44
25n=$(echo $scripts | wc -w) 45# we know the custom scripts are present but applet scripts might have
46# become detached from their configuration
47for i in $applet_scripts
48do
49 #if [ ! -f "$applet_loc/$i" -a ! -f "$custom_loc/$i" ]
50 if [ ! -f "$applet_loc/$i" ]
51 then
52 echo "missing applet script $i"
53 exit 1
54 fi
55done
26 56
27if [ $n -ne 0 ] 57n=$(echo $custom_scripts $applet_scripts | wc -w)
58nall=$(echo $all_scripts | wc -w)
59
60if [ $n -ne $nall ]
28then 61then
29 printf '#ifdef DEFINE_script_names\n' 62 echo "script mismatch $n != $nall"
30 printf 'const char script_names[] ALIGN1 = ' 63 exit 1
31 for i in $scripts 64fi
65
66concatenate_scripts() {
67 for i in $custom_scripts
68 do
69 cat $custom_loc/$i
70 printf '\000'
71 done
72 for i in $applet_scripts
32 do 73 do
33 printf '"%s\\0"' $i 74 cat $applet_loc/$i
75 printf '\000'
34 done 76 done
35 printf ';\n' 77}
78
79exec >"$target.$$"
80
81if [ $n -ne 0 ]
82then
83 printf '#ifdef DEFINE_SCRIPT_DATA\n'
84 if [ $n -ne 0 ]
85 then
86 printf 'const uint16_t applet_numbers[] = {\n'
87 for i in $custom_scripts $applet_scripts
88 do
89 # TODO support applets with names including invalid characters
90 printf '\tAPPLET_NO_%s,\n' $i
91 done
92 printf '};\n'
93 fi
36 printf '#else\n' 94 printf '#else\n'
37 printf 'extern const char script_names[] ALIGN1;\n' 95 if [ $n -ne 0 ]
96 then
97 printf 'extern const uint16_t applet_numbers[];\n'
98 fi
38 printf '#endif\n' 99 printf '#endif\n'
39fi 100fi
40printf "#define NUM_SCRIPTS $n\n\n" 101
102printf "\n"
103printf '#define NUM_SCRIPTS %d\n' $n
104printf "\n"
41 105
42if [ $n -ne 0 ] 106if [ $n -ne 0 ]
43then 107then
44 printf '#define UNPACKED_SCRIPTS_LENGTH ' 108 printf '#define UNPACKED_SCRIPTS_LENGTH '
45 for i in $scripts 109 concatenate_scripts | wc -c
46 do
47 cat $loc/$i
48 printf '\000'
49 done | wc -c
50 110
51 printf '#define PACKED_SCRIPTS \\\n' 111 printf '#define PACKED_SCRIPTS \\\n'
52 for i in $scripts 112 concatenate_scripts | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | \
53 do 113 od -v -b \
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 '^ ' \ 114 | grep -v '^ ' \
58 | $SED -e 's/^[^ ]*//' \ 115 | $SED -e 's/^[^ ]*//' \
59 -e 's/ //g' \ 116 -e 's/ //g' \