Debian Codegraph @

scripts/embedded_scripts

raw symbols SCIP
1 #!/bin/sh
2
3 . ./.config || exit 1
4
5 target="$1"
6 custom_loc="$2"
7 applet_loc="$3"
8
9 test "$target" || exit 1
10 test "$SED" || SED=sed
11 test "$DD" || DD=dd
12
13 if [ x"$CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS" != x"y" ]
14 then
15 printf '#define NUM_SCRIPTS 0\n' >"$target"
16 exit 0
17 fi
18
19 # Some people were bitten by their system lacking a (proper) od
20 od -v -b </dev/null >/dev/null
21 if test $? != 0; then
22 echo 'od tool is not installed or cannot accept "-v -b" options'
23 exit 1
24 fi
25
26 bzip2 </dev/null >/dev/null
27 if test $? != 0; then
28 echo 'bzip2 is not installed'
29 exit 1
30 fi
31
32 custom_scripts=""
33 if [ -d "$custom_loc" ]
34 then
35 custom_scripts=$(cd $custom_loc; ls * 2>/dev/null)
36 fi
37 all_scripts=$($srctree/applets/busybox.mkscripts)
38
39 # all_scripts includes applet scripts and custom scripts, sort them out
40 applet_scripts=""
41 for i in $all_scripts
42 do
43 found=0
44 for j in $custom_scripts
45 do
46 if [ "$i" = "$j" ]
47 then
48 found=1
49 break;
50 fi
51 done
52 if [ $found -eq 0 ]
53 then
54 # anything that isn't a custom script is an applet script
55 applet_scripts="$applet_scripts $i"
56 fi
57 done
58
59 # we know the custom scripts are present but applet scripts might have
60 # become detached from their configuration
61 for i in $applet_scripts
62 do
63 #if [ ! -f "$applet_loc/$i" -a ! -f "$custom_loc/$i" ]
64 if [ ! -f "$applet_loc/$i" ]
65 then
66 echo "missing applet script $i"
67 exit 1
68 fi
69 done
70
71 n=$(echo $custom_scripts $applet_scripts | wc -w)
72 nall=$(echo $all_scripts | wc -w)
73
74 if [ $n -ne $nall ]
75 then
76 echo "script mismatch $n != $nall"
77 exit 1
78 fi
79
80 concatenate_scripts() {
81 for i in $custom_scripts
82 do
83 cat $custom_loc/$i
84 printf '\000'
85 done
86 for i in $applet_scripts
87 do
88 cat $applet_loc/$i
89 printf '\000'
90 done
91 }
92
93 exec >"$target.$$"
94
95 if [ $n -ne 0 ]
96 then
97 printf '#ifdef DEFINE_SCRIPT_DATA\n'
98 printf 'const uint16_t applet_numbers[] = {\n'
99 for i in $custom_scripts $applet_scripts
100 do
101 # TODO support applets with names including invalid characters
102 printf '\tAPPLET_NO_%s,\n' $i
103 done
104 printf '};\n'
105 printf '#else\n'
106 printf 'extern const uint16_t applet_numbers[];\n'
107 printf '#endif\n'
108 fi
109
110 printf "\n"
111 printf '#define NUM_SCRIPTS %d\n' $n
112 printf "\n"
113
114 if [ $n -ne 0 ]
115 then
116 printf '#define UNPACKED_SCRIPTS_LENGTH '
117 concatenate_scripts | wc -c
118
119 printf '#define PACKED_SCRIPTS \\\n'
120 concatenate_scripts | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | \
121 od -v -b \
122 | grep -v '^ ' \
123 | $SED -e 's/^[^ ]*//' \
124 -e 's/ //g' \
125 -e '/^$/d' \
126 -e 's/\(...\)/0\1,/g' \
127 -e 's/$/ \\/'
128 printf '\n'
129 fi
130
131 mv -- "$target.$$" "$target"