-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_static.sh
355 lines (317 loc) · 8.24 KB
/
build_static.sh
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/usr/bin/bash
CPU=`uname -m`
FFMPEG="ffmpeg-3.2.3-1"
MINIDLNA="minidlna-1.2.1-1"
# Partially borrowed from apt-cyg
function wget {
if command wget -h &>/dev/null
then
command wget "$@"
else
warn wget is not installed, using lynx as fallback
set "${*: -1}"
lynx -source "$1" > "${1##*/}"
fi
}
function find-workspace {
# default working directory and mirror
# work wherever setup worked last, if possible
cache=$(awk '
BEGIN {
RS = "\n\\<"
FS = "\n\t"
}
$1 == "last-cache" {
print $2
}
' /etc/setup/setup.rc)
mirror=$(awk '
/last-mirror/ {
getline
print $1
}
' /etc/setup/setup.rc)
mirrordir=$(sed '
s / %2f g
s : %3a g
' <<< "$mirror")
mkdir -p "$cache/$mirrordir/$arch"
cd "$cache/$mirrordir/$arch"
if [ -e setup.ini ]
then
return 0
else
get-setup
return 1
fi
}
function get-setup {
touch setup.ini
mv setup.ini setup.ini-save
wget -N $mirror/$arch/setup.bz2
if [ -e setup.bz2 ]
then
bunzip2 setup.bz2
mv setup setup.ini
echo Updated setup.ini
else
echo Error updating setup.ini, reverting
mv setup.ini-save setup.ini
fi
}
function download-source {
local pkg digest digactual
pkg=$1
# look for package and save desc file
awk '$1 == pc' RS='\n\n@ ' FS='\n' pc=$pkg setup.ini > desc
if [ ! -s desc ]
then
echo Unable to locate package $pkg
exit 1
fi
# download and unpack the bz2 or xz file
# pick the latest version, which comes first
set -- $(awk '$1 == "source:"' desc)
if (( ! $# ))
then
echo 'Could not find "source" in package description: obsolete package?'
exit 1
fi
dn=$(dirname $2)
bn=$(basename $2)
# check the md5
digest=$4
case ${#digest} in
32) hash=md5sum ;;
128) hash=sha512sum ;;
esac
mkdir -p "$cache/$mirrordir/$dn"
cd "$cache/$mirrordir/$dn"
if ! test -e $bn || ! $hash -c <<< "$digest $bn"
then
wget -O $bn $mirror/$dn/$bn
$hash -c <<< "$digest $bn" || exit
fi
cd ~-
mv desc "$cache/$mirrordir/$dn"
echo $dn $bn > /tmp/dwn
}
function install-source {
find-workspace
local pkg dn bn sn
pkg=$1
download-source $pkg
read dn bn </tmp/dwn
echo Unpacking...
cd "$cache/$mirrordir/$dn"
sn=$(basename $bn | sed -E -e 's/-src\.tar\..+$//')
if tar tf $bn | grep -q "\.src/"
then
tar -x -C /usr/src -f $bn
else
mkdir -p /usr/src/$sn.src
tar -x -C /usr/src/$sn.src -f $bn
fi
echo Source package $pkg installed
echo /usr/src/$sn.src > /tmp/dwn
}
function local-install {
local pkg fn bn script
echo $1
fn=$1
bn=$(basename $1)
pkg=$(echo $bn | sed -E -e 's/-[0-9]+\.[0-9]+.*$//')
if [ ! -f $fn ]
then
echo "File $fn doesn't exist"
return 1
fi
echo Installing $pkg
echo Unpacking...
tar -x -C / -f $fn
# update the package database
tar tf $fn | gzip > /etc/setup/"$pkg".lst.gz
awk '
ins != 1 && pkg < $1 {
print pkg, bz, 0
ins = 1
}
1
END {
if (ins != 1) print pkg, bz, 0
}
' pkg="$pkg" bz=$bn /etc/setup/installed.db > /tmp/awk.$$
mv /etc/setup/installed.db /etc/setup/installed.db-save
mv /tmp/awk.$$ /etc/setup/installed.db
# run all postinstall scripts
find /etc/postinstall -name '*.sh' | while read script
do
echo Running $script
$script
mv $script $script.done
done
echo Package $pkg installed
}
readonly arch=${HOSTTYPE/i6/x}
cwd=$(pwd)
# Get apt-cyg
if [ ! -f /bin/apt-cyg ]
then
lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin
rm apt-cyg
fi
# Install prereqs
apt-cyg install wget
apt-cyg install cygport
# Install prereqs
apt-cyg install gperf libiconv-devel libicu-devel libintl-devel \
gettext-devel libreadline-devel tcl-devel openssl-devel \
zlib-devel nasm yasm
# Install minidlna prereqs
export CYGCONF_ARGS="--enable-static"
if [ ! -f /lib/libid3tag.dll.a ]
then
install-source libid3tag-devel
read dir </tmp/dwn
pushd $dir
fn=$(basename $dir | sed -e 's/\.src$//')
cygport $fn.cygport all
for pkg in $(find $fn.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd
fi
if [ ! -f /lib/libsqlite3.dll.a ]
then
install-source libsqlite3-devel
read dir </tmp/dwn
pushd $dir
fn=$(basename $dir | sed -e 's/\.src$//')
cp $fn.cygport $fn.cygport.orig
sed -e 's/libsqlite3\*.dll.a/libsqlite3*.a/' $fn.cygport.orig > $fn.cygport
cygport $fn.cygport prep compile install
# Current packaging seems to be broken, manual hack to fix it
install $fn.$CPU/src/*/spaceanal.tcl $fn.$CPU/inst/usr/bin/sqlite3_analyzer
pushd $fn.$CPU/inst/usr/lib
for d in $(find -type d -name "sqlite3.*")
do
nd=$(echo $d | sed -e 's/sqlite3.*$/sqlite3/')
mv $d $nd
done
popd
cygport $fn.cygport package
rm $fn.cygport
mv $fn.cygport.orig $fn.cygport
for pkg in $(find $fn.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" \
! -iname "*-debuginfo*" ! -iname "*mingw*")
do
local-install $pkg
done
popd
fi
if [ ! -f /lib/libjpeg.dll.a ]
then
install-source libjpeg-devel
read dir </tmp/dwn
pushd $dir
fn=$(basename $dir | sed -e 's/\.src$//')
sed -e 's/CYGCONF_ARGS="/CYGCONF_ARGS="\$CYGCONF_ARGS /' libjpeg-turbo.cygport > libjpeg-turbo.mod.cygport
cygport libjpeg-turbo.mod.cygport all
rm libjpeg-turbo.mod.cygport
for pkg in $(find $fn.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd
fi
if [ ! -f /lib/libexif.dll.a ]
then
install-source libexif-devel
read dir </tmp/dwn
pushd $dir
fn=$(basename $dir | sed -e 's/\.src$//')
sed -e 's/CYGCONF_ARGS="/CYGCONF_ARGS="\$CYGCONF_ARGS /' $fn.cygport > $fn.mod.cygport
cygport $fn.mod.cygport prep compile install
# Hack to fix packaging
tar -x -C $fn.mod.$CPU/inst/usr/share/doc/libexif -f $fn.mod.$CPU/src/*/doc/libexif-api.html.tar.gz
cygport $fn.mod.cygport package
rm $fn.mod.cygport
for pkg in $(find $fn.mod.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd
fi
if [ ! -f /lib/libogg.dll.a ]
then
install-source libogg-devel
read dir </tmp/dwn
pushd $dir
fn=$(basename $dir | sed -e 's/\.src$//')
cygport libogg.cygport all
for pkg in $(find $fn.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd
fi
if [ ! -f /lib/libvorbis.dll.a ]
then
install-source libvorbis-devel
read dir </tmp/dwn
pushd $dir
fn=$(basename $dir | sed -e 's/\.src$//')
echo "01-autoreconf.patch" > series
cygport libvorbis.cygport all
rm series
for pkg in $(find $fn.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd
fi
if [ ! -f /lib/libFLAC.dll.a ]
then
install-source flac-devel
read dir </tmp/dwn
pushd $dir
fn=$(basename $dir | sed -e 's/\.src$//')
sed -e 's/CYGCONF_ARGS="/CFLAGS="-ggdb -O2 -pipe -Wimplicit-function-declaration -D_O_BINARY=O_BINARY"\nCYGCONF_ARGS="\$CYGCONF_ARGS /' flac.cygport > flac.mod.cygport
echo "01-do_not_use__fileno.patch 02-no_win_utf8_io.patch 03-fix_O_BINARY.patch" > series
cygport flac.mod.cygport all
rm series
rm flac.mod.cygport
for pkg in $(find $fn.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd
fi
cd $cwd
# Build ffmpeg if needed
if [ ! -f /lib/libavutil.dll.a ]
then
unzip $FFMPEG.src.zip -d /usr/src/$FFMPEG.src
pushd /usr/src/$FFMPEG.src
echo "Building $FFMPEG..."
cygport ffmpeg_static.cygport fetch all
echo "Installing $FFMPEG..."
for pkg in $(find $FFMPEG.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd
fi
# Build minidlna
unzip $MINIDLNA.src.zip -d /usr/src/$MINIDLNA.src
pushd /usr/src/$MINIDLNA.src
echo "Building $MINIDLNA..."
cygport minidlna_static.cygport fetch prep compile install package
echo "Installing $MINIDLNA..."
for pkg in $(find $MINIDLNA.$CPU/dist/ -iname "*.tar.xz" ! -iname "*-src.tar.xz" ! -iname "*-debuginfo*")
do
local-install $pkg
done
popd