aboutsummaryrefslogtreecommitdiff
path: root/scripts/embedded_scripts
diff options
context:
space:
mode:
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' \