-
Notifications
You must be signed in to change notification settings - Fork 63
/
compile
executable file
·196 lines (167 loc) · 6.98 KB
/
compile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
compressor="bzip2"
decompressor="bunzip2"
extension="bz2"
if [ -f "src/sakis3g" ]; then
BASEDIR=`pwd`
elif [ -f "../src/sakis3g" ]; then
BASEDIR=`dirname \`pwd\``
else
echo "This script should be run while being within Sakis3G root directory."
exit 1
fi
[ "a${BASEDIR}" = "a" ] && echo "Unable to locate Sakis3G root directory." && exit 2
echo "Base directory: ${BASEDIR}."
cd "${BASEDIR}"
case "a$1" in
"astripped"|"anormal"|"aredist"|"aplain"|"asmall"|"asmallest")
mode="stripped"
requirements="src/sakis3g src/sakis3gz"
dependencies="tar dd ${compressor} stat find touch"
items="src/sakis3g files messages"
;;
"aembedded"|"ano_usb_modeswitch")
mode="embedded"
requirements="src/sakis3g src/sakis3gz"
dependencies="tar dd ${compressor} stat find touch"
items="build Changelog compile COPYING CONTRIB man README scripts src/sakis3g src/sakis3gz files messages docs"
;;
"a"|"afull"|"ayes_usb_modeswitch"|"aall"|"a+usb_modeswitch")
mode="full"
requirements="src/sakis3g src/sakis3gz dependencies/usb-modeswitch/usb_modeswitch.c dependencies/usb-modeswitch/usb_modeswitch.h scripts/device-database-gen"
dependencies="tar dd ${compressor} stat find touch gcc"
items="build Changelog compile COPYING CONTRIB dependencies man README scripts src/sakis3g src/sakis3gz files messages docs"
;;
esac
for file in ${requirements}
do
[ ! -f "${file}" ] && echo "File \"${file}\" not found. Please re-install." && exit 3
done
echo "Source files: All found."
for utility in ${dependencies}
do
[ ! "`which ${utility} 2> /dev/null`" ] && echo "Utility ${utility} not found." && exit 4
done
if [ "a${mode}" = "afull" ]; then
[ ! -d "dependencies/usb-modeswitch-data" ] && echo "Usb-ModeSwitch device database not found." && exit 4
rm -f "build/switchconfig"
./scripts/device-database-gen > "build/switchconfig"
[ ! -f "build/switchconfig" ] && echo "Failed to transform device database." && exit 5
echo "Device database: Found and transformed."
else
echo "Device database: Skipped. Relying on external Usb-ModeSwitch database."
fi
if [ "a${mode}" = "afull" ]; then
rm -f "build/usb_modeswitch.compiled"
gcc -Wall -l usb-1.0 -o build/usb_modeswitch.compiled dependencies/usb-modeswitch/usb_modeswitch.c -I dependencies/usb-modeswitch -lusb-1.0
[ ! -f "build/usb_modeswitch.compiled" ] && echo "Failed to compile usb-modeswitch." && exit 6
[ "`which strip 2> /dev/null`" ] && strip "build/usb_modeswitch.compiled"
rm -f "build/usb_modeswitch" ; mv "build/usb_modeswitch.compiled" "build/usb_modeswitch"
[ ! -f "build/usb_modeswitch" ] && exit 7
echo "Usb-ModeSwitch: Compiled."
else
rm -f "build/"*
echo "Usb-ModeSwitch: NOT embedded. Relying on external Usb-ModeSwitch binary."
fi
mkdir tmp 2> /dev/null
mkdir tmp/sakis3g 2> /dev/null
rm -rf tmp/sakis3g/*
mkdir tmp/sakis3g/src 2> /dev/null
for target in ${items}
do
cp -R "${target}" "tmp/sakis3g/${target}"
done
rm -f "tmp/sakis3g/build/sakis3gz" "tmp/sakis3g/build/.sakis3gz" "tmp/sakis3g.tar" "tmp/sakis3g.tar.${extension}"
chmod +x "tmp/sakis3g/src/sakis3g"
cd tmp
find sakis3g/ -print0 | xargs -0 touch
contents=`tar cvf sakis3g.tar sakis3g`
executables=`find sakis3g/ -executable \! -type d \! -type l`
cd ..
[ ! -f "tmp/sakis3g.tar" ] && echo "Failed to create tar file." && exit 10
tarsize=`stat --printf="%s\n" tmp/sakis3g.tar 2>/dev/null`; tarsize=`echo ${tarsize}`
${compressor} --best tmp/sakis3g.tar
[ ! -f "tmp/sakis3g.tar.${extension}" ] && echo "Failed to compress tar file." && exit 11
echo "Compressed file: Created."
rm -rf tmp/sakis3g/*
rmdir tmp/sakis3g 2> /dev/null
rm -f "build/.sakis3gz"
packagesize=`stat --printf="%s\n" tmp/sakis3g.tar.${extension} 2>/dev/null`; packagesize=`echo ${packagesize}`
echo "#!/bin/bash" > "build/.sakis3gz"
grep "^MYVERSION" src/sakis3g >> "build/.sakis3gz"
grep "^#" src/sakis3gz >> "build/.sakis3gz"
echo "PACKAGE_SIZE=${packagesize}" >> "build/.sakis3gz"
echo "BLOCKSIZE=1024" >> "build/.sakis3gz"
echo "PACKAGE_CONTENTS=\"${contents}\"" >> "build/.sakis3gz"
echo "PACKAGE_EXECUTABLES=\"${executables}\"" >> "build/.sakis3gz"
echo "decompressor=\"${decompressor}\"" >> "build/.sakis3gz"
echo "extension=\"${extension}\"" >> "build/.sakis3gz"
case "${mode}" in
full)
;;
stripped)
echo "binaryfree=\"yes\"" >> "build/.sakis3gz"
echo "stripped=\"yes\"" >> "build/.sakis3gz"
echo "export binaryfree" >> "build/.sakis3gz"
echo "export stripped" >> "build/.sakis3gz"
;;
embedded)
echo "binaryfree=\"yes\"" >> "build/.sakis3gz"
echo "export binaryfree" >> "build/.sakis3gz"
;;
esac
tmpsize=`stat --printf="%s\n" build/.sakis3gz 2>/dev/null`; tmpsize=`echo ${tmpsize}`
size=`stat --printf="%s\n" src/sakis3gz 2>/dev/null`; size=`echo ${size}`
[ "a${size}" = "a" ] && size=0
size=`expr ${size} + 513 + ${tmpsize}`; size=`echo ${size}`
size=`expr ${size} / 1024`; size=`echo ${size}`
size=`expr ${size} + 1`; size=`echo ${size}`
echo "PACKAGE_OFFSET=${size}" >> "build/.sakis3gz"
grep -v "^#" "src/sakis3gz" >> "build/.sakis3gz"
echo "exit 99" >> "build/.sakis3gz"
dd if=tmp/sakis3g.tar.${extension} of=build/.sakis3gz obs=1024 seek=${size} > /dev/null 2>&1
rm -f "tmp/sakis3g.tar.${extension}"
rm -f "build/sakis3gz"; mv "build/.sakis3gz" "build/sakis3gz"
chmod +x "build/sakis3gz"
finalsize=`stat --printf="%s\n" build/sakis3gz 2>/dev/null`; finalsize=`echo ${finalsize}`
ratio=`expr ${finalsize} \* 10000`; ratio=`echo ${ratio}`
ratio=`expr ${ratio} / ${tarsize}`; ratio=`echo ${ratio}`
ratio=`expr 10000 - ${ratio}`; ratio=`echo ${ratio}`
ratio=`echo ${ratio} | sed -e "s/^\([0-9]*\)\([0-9][0-9]\)$/\1.\2/g"`
echo "Compilation complete."
echo "Compression ratio ${ratio}% (${finalsize}/${tarsize})."
echo
echo "Sakis3G script is available at: build/sakis3gz"
case "${mode}" in
full)
echo "This is all you need. You may delete the rest."
echo
echo "If you later want to compile it for another platform, invoke it with"
echo "\"recompile\" argument, or use \"disassemble\" argument to recreate"
echo "source folder."
;;
embedded)
echo "Full functionality is preserved and script is architect independed and"
echo "self-contained. However, for using it with a switchable USB modem:"
echo " * Usb-ModeSwitch must be available within PATH, and "
echo " * Usb-ModeSwitch device database needs to be available at"
echo " /etc/usb_modeswitch.d."
;;
stripped)
echo "Script is architect independed but:"
echo " * Relies on a working Usb-ModeSwitch installation available on PATH."
echo " * Needs Usb-ModeSwitch device database installed at /etc/usb_modeswitch.d"
echo " * It is impossible to \"disassemble\" it back to its contents."
echo " * It is impossible to view man pages using \"man\" argument. You need to"
echo " install files man/* on your system's man subsystem for this to be"
echo " possible."
echo " * Files README, CONTRIB and COPYING are not embedded. You need to ship"
echo " them as well, for being compliant with Sakis3G license."
;;
esac
echo
echo "For installing it, use:"
echo " $ sudo bash || su"
echo " Password:"
echo " # cp build/sakis3gz /usr/bin/sakis3g"
echo