diff options
Diffstat (limited to 'scripts/embedded_scripts')
-rwxr-xr-x | scripts/embedded_scripts | 107 |
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 | ||
3 | target="$1" | 3 | target="$1" |
4 | loc="$2" | 4 | custom_loc="$2" |
5 | applet_loc="$3" | ||
5 | 6 | ||
6 | test "$target" || exit 1 | 7 | test "$target" || exit 1 |
7 | test "$SED" || SED=sed | 8 | test "$SED" || SED=sed |
@@ -14,46 +15,102 @@ if test $? != 0; then | |||
14 | exit 1 | 15 | exit 1 |
15 | fi | 16 | fi |
16 | 17 | ||
17 | exec >"$target.$$" | 18 | custom_scripts="" |
18 | 19 | if [ -d "$custom_loc" ] | |
19 | scripts="" | ||
20 | if [ -d "$loc" ] | ||
21 | then | 20 | then |
22 | scripts=$(cd $loc; ls * 2>/dev/null) | 21 | custom_scripts=$(cd $custom_loc; ls * 2>/dev/null) |
23 | fi | 22 | fi |
23 | all_scripts=$(applets/busybox.mkscripts) | ||
24 | |||
25 | # all_scripts includes applet scripts and custom scripts, sort them out | ||
26 | applet_scripts="" | ||
27 | for i in $all_scripts | ||
28 | do | ||
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 | ||
43 | done | ||
24 | 44 | ||
25 | n=$(echo $scripts | wc -w) | 45 | # we know the custom scripts are present but applet scripts might have |
46 | # become detached from their configuration | ||
47 | for i in $applet_scripts | ||
48 | do | ||
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 | ||
55 | done | ||
26 | 56 | ||
27 | if [ $n -ne 0 ] | 57 | n=$(echo $custom_scripts $applet_scripts | wc -w) |
58 | nall=$(echo $all_scripts | wc -w) | ||
59 | |||
60 | if [ $n -ne $nall ] | ||
28 | then | 61 | then |
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 | 64 | fi |
65 | |||
66 | concatenate_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 | |||
79 | exec >"$target.$$" | ||
80 | |||
81 | if [ $n -ne 0 ] | ||
82 | then | ||
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' |
39 | fi | 100 | fi |
40 | printf "#define NUM_SCRIPTS $n\n\n" | 101 | |
102 | printf "\n" | ||
103 | printf '#define NUM_SCRIPTS %d\n' $n | ||
104 | printf "\n" | ||
41 | 105 | ||
42 | if [ $n -ne 0 ] | 106 | if [ $n -ne 0 ] |
43 | then | 107 | then |
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' \ |