-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathutil.sh
executable file
·771 lines (676 loc) · 23.2 KB
/
util.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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
#!/bin/bash
##### -*- mode:shell-script; indent-tabs-mode:nil; sh-basic-offset:2 -*-
##### Author: Travis Cross <[email protected]>
set -e
ddir="."
[ -n "${0%/*}" ] && ddir="${0%/*}"
cd $ddir/../
#### lib
err () {
echo "$0 error: $1" >&2
exit 1
}
announce () {
cat >&2 <<EOF
########################################################################
## $1
########################################################################
EOF
}
xread () {
local xIFS="$IFS"
IFS=''
read $@
local ret=$?
IFS="$xIFS"
return $ret
}
mk_dver () { echo "$1" | sed -e 's/-/~/g'; }
mk_uver () { echo "$1" | sed -e 's/-.*$//' -e 's/~/-/'; }
dsc_source () { dpkg-parsechangelog | grep '^Source:' | awk '{print $2}'; }
dsc_ver () { dpkg-parsechangelog | grep '^Version:' | awk '{print $2}'; }
up_ver () { mk_uver "$(dsc_ver)"; }
dsc_base () { echo "$(dsc_source)_$(dsc_ver)"; }
up_base () { echo "$(dsc_source)-$(up_ver)"; }
find_distro () {
case "$1" in
experimental) echo "sid";;
unstable) echo "sid";;
experimental) echo "bookworm";;
testing) echo "bullseye";;
stable) echo "buster";;
oldstable) echo "stretch";;
*) echo "$1";;
esac
}
find_suite () {
case "$1" in
sid) echo "unstable";;
bookworm) echo "experimental";;
bullseye) echo "testing";;
buster) echo "stable";;
stretch) echo "oldstable";;
*) echo "$1";;
esac
}
#### debian/rules helpers
create_dbg_pkgs () {
for x in $ddir/*; do
test ! -d $x && continue
test "$x" = "tmp" -o "$x" = "source" && continue
test ! "$x" = "${x%-dbg}" && continue
test ! -d $x/usr/lib/debug && continue
mkdir -p $x-dbg/usr/lib
mv $x/usr/lib/debug $x-dbg/usr/lib/
done
}
cwget () {
local url="$1" f="${1##*/}"
echo "fetching: $url to $f" >&2
if [ -n "$FS_FILES_DIR" ]; then
if ! [ -s "$FS_FILES_DIR/$f" ]; then
(cd $FS_FILES_DIR && wget -N "$url")
fi
cp -a $FS_FILES_DIR/$f .
else
wget -N "$url"
fi
}
getlib () {
local url="$1" f="${1##*/}"
cwget "$url"
tar -xv --no-same-owner --no-same-permissions -f "$f"
rm -f "$f" && mkdir -p $f && touch $f/.download-stamp
}
getlibs () {
# get pinned libraries
getlib http://files.freeswitch.org/downloads/libs/sphinxbase-0.8.tar.gz
getlib http://files.freeswitch.org/downloads/libs/pocketsphinx-0.8.tar.gz
getlib http://files.freeswitch.org/downloads/libs/communicator_semi_6000_20080321.tar.gz
#getlib http://download.zeromq.org/zeromq-2.1.9.tar.gz \
# || getlib http://download.zeromq.org/historic/zeromq-2.1.9.tar.gz
#getlib http://files.freeswitch.org/downloads/libs/v8-3.24.14.tar.bz2
}
check_repo_clean () {
git diff-index --quiet --cached HEAD \
|| err "uncommitted changes present"
git diff-files --quiet \
|| err "unclean working tree"
git diff-index --quiet HEAD \
|| err "unclean repository"
! git ls-files --other --error-unmatch . >/dev/null 2>&1 \
|| err "untracked files or build products present"
}
get_last_release_ver () {
grep -m1 -e '^AC_INIT' configure.ac \
| cut -d, -f2 \
| sed -e 's/\[//' -e 's/\]//' -e 's/ //g'
}
get_nightly_version () {
local commit="$(git rev-list -n1 --abbrev=10 --abbrev-commit HEAD)"
echo "$(get_last_release_ver)+git~$(date -u '+%Y%m%dT%H%M%SZ')~$commit"
}
get_nightly_revision_human () {
echo "git $(git rev-list -n1 --abbrev=7 --abbrev-commit HEAD) $(date -u '+%Y-%m-%d %H:%M:%SZ')"
}
prep_create_orig () {
{
set -e
local OPTIND OPTARG
local uver="" hrev="" bundle_deps=true soft_reset=false
while getopts 'bm:nv:V:xz:' o "$@"; do
case "$o" in
b) ;;
m) ;;
n) uver="nightly";;
v) uver="$OPTARG";;
V) uver="$OPTARG";;
x) soft_reset=true;;
z) ;;
esac
done
shift $(($OPTIND-1))
if [ -z "$uver" ] || [ "$uver" = "nightly" ]; then
uver="$(get_nightly_version)"
hrev="$(get_nightly_revision_human)"
fi
local treeish="$1"
[ -n "$treeish" ] || treeish="HEAD"
if $soft_reset; then
git reset --soft "$treeish"
else
check_repo_clean
git reset --hard "$treeish"
fi
if $bundle_deps; then
(cd libs && getlibs)
fi
./build/set-fs-version.sh "$uver" "$hrev" # ToDo: Handle empty $hrev
echo "$uver" > .version
} 1>&2
echo "$uver"
}
create_orig () {
{
set -e
local OPTIND OPTARG
local bundle_deps=true modules_list="" soft_reset=false auto_orig=false zl=9e
local uver="$(prep_create_orig "$@")"
while getopts 'bm:nv:V:xz:' o "$@"; do
case "$o" in
b) ;;
m) modules_list="$OPTARG";;
n) ;;
v) ;;
V) auto_orig=true;;
x) soft_reset=true;;
z) zl="$OPTARG";;
esac
done
shift $(($OPTIND-1))
local commit_epoch=$(git log -1 --format=%ct)
local source_date=$(date -u -d @$commit_epoch +'%Y-%m-%d %H:%M:%S')
local orig git_archive_prefix
if $auto_orig; then
orig="../freeswitch_$(debian/version-omit_revision.pl).orig.tar.xz"
git_archive_prefix="freeswitch/"
else
orig="../freeswitch_$(mk_dver "$uver")~$(lsb_release -sc).orig.tar.xz"
git_archive_prefix="freeswitch-$uver/"
fi
mv .gitattributes .gitattributes.orig
local -a args=(-e '\bdebian-ignore\b')
test "$modules_list" = "non-dfsg" || args+=(-e '\bdfsg-nonfree\b')
grep .gitattributes.orig "${args[@]}" \
| while xread l; do
echo "$l export-ignore" >> .gitattributes
done
if $bundle_deps; then
git add -f libs
fi
git add -f configure.ac .version
git commit --allow-empty -m "nightly v$uver"
local tmpsrcdir="$(mktemp -d)"
git archive -v \
--worktree-attributes \
--format=tar \
--prefix=$git_archive_prefix \
HEAD | tar --extract --directory="$tmpsrcdir"
# https://www.gnu.org/software/tar/manual/html_section/Reproducibility.html
tar \
--sort=name \
--format=posix \
--pax-option='exthdr.name=%d/PaxHeaders/%f' \
--pax-option='delete=atime,delete=ctime' \
--clamp-mtime \
--mtime="$source_date" \
--numeric-owner \
--owner=0 \
--group=0 \
--mode='go+u,go-w' \
--create \
--directory="$tmpsrcdir" \
. | xz -v -c -${zl} > "$orig" && \
rm -rf "$tmpsrcdir"
echo "Source archive checksum:"
sha256sum $orig
mv .gitattributes.orig .gitattributes
if $soft_reset; then
git reset --soft HEAD^
else
git reset --hard HEAD^ && git clean -fdx
fi
} 1>&2
echo $orig
}
set_modules_quicktest () {
cat > debian/modules.conf <<EOF
applications/mod_commands
EOF
}
prep_create_dsc () {
{
set -e
local OPTIND OPTARG modules_conf="" modules_add="" modules_list="" speed="normal"
while getopts 'a:f:m:p:s:u:z:' o "$@"; do
case "$o" in
a) avoid_mods_arch="$OPTARG";;
f) modules_conf="$OPTARG";;
m) modules_list="$OPTARG";;
p) modules_add="$modules_add $OPTARG";;
s) speed="$OPTARG";;
u) ;;
z) ;;
esac
done
shift $(($OPTIND-1))
local distro="$(find_distro $1)"
if [ -n "$modules_conf" ]; then
cp $modules_conf debian/modules.conf
fi
local bootstrap_args=""
if [ -n "$modules_list" ]; then
if [ "$modules_list" = "non-dfsg" ]; then
bootstrap_args="-mnon-dfsg"
else
set_modules_${modules_list}
fi
fi
if test -n "$modules_add"; then
for x in $modules_add; do
bootstrap_args="$bootstrap_args -p${x}"
done
fi
(cd debian && ./bootstrap.sh -a "$avoid_mods_arch" -c $distro $bootstrap_args)
case "$speed" in
paranoid) sed -i ./debian/rules \
-e '/\.stamp-bootstrap:/{:l2 n; /\.\/bootstrap.sh -j/{s/ -j//; :l3 n; b l3}; b l2};' ;;
reckless) sed -i ./debian/rules \
-e '/\.stamp-build:/{:l2 n; /make/{s/$/ -j/; :l3 n; b l3}; b l2};' ;;
esac
} 1>&2
}
create_dsc () {
{
set -e
prep_create_dsc "$@"
local OPTIND OPTARG suite_postfix="" suite_postfix_p=false soft_reset=false zl=9
while getopts 'a:f:m:p:s:u:xz:' o "$@"; do
case "$o" in
a) ;;
f) ;;
m) ;;
p) ;;
s) ;;
u) suite_postfix="$OPTARG"; suite_postfix_p=true;;
x) soft_reset=true;;
z) zl="$OPTARG";;
esac
done
shift $(($OPTIND-1))
local distro="$(find_distro $1)" orig="$2"
local suite="$(find_suite $distro)"
local orig_ver="$(echo "$orig" | sed -e 's/^.*_//' -e 's/\.orig\.tar.*$//')"
local dver="${orig_ver}-1~${distro}+1"
$suite_postfix_p && { suite="${distro}${suite_postfix}"; }
[ -x "$(which dch)" ] \
|| err "package devscripts isn't installed"
[ "$zl" -ge "1" ] || zl=1
dch -b -m -v "$dver" --force-distribution -D "$suite" "Nightly build."
git add debian/rules debian/changelog && git commit -m "nightly v$orig_ver"
dpkg-source -i.* -Zxz -z${zl} -b .
dpkg-genchanges -S > ../$(dsc_base)_source.changes
local dsc="../$(dsc_base).dsc"
if $soft_reset; then
git reset --soft HEAD^
else
git reset --hard HEAD^ && git clean -fdx
fi
} 1>&2
echo $dsc
}
fmt_debug_hook () {
cat <<'EOF'
#!/bin/bash
export debian_chroot="cow"
cd /tmp/buildd/*/debian/..
/bin/bash < /dev/tty > /dev/tty 2> /dev/tty
EOF
}
get_sources () {
local tgt_distro="$1"
while read type args path distro components; do
test "$type" = deb || continue
if echo "$args" | grep -qv "\[" ; then components=$distro;distro=$path;path=$args;args=""; fi
prefix=`echo $distro | awk -F/ '{print $1}'`
suffix="`echo $distro | awk -F/ '{print $2}'`"
if test -n "$suffix" ; then full="$tgt_distro/$suffix" ; else full="$tgt_distro" ; fi
printf "$type $args $path $full $components\n"
done < "$2"
}
get_mirrors () {
file=${2-/etc/apt/sources.list}
announce "Using apt sources file: $file"
get_sources "$1" "$file" | tr '\n' '|' | head -c-1; echo
}
build_debs () {
{
set -e
local OPTIND OPTARG debug_hook=false hookdir="" cow_build_opts=""
local keep_pbuilder_config=false keyring="" custom_keyring="/tmp/fs.gpg"
local use_custom_sources=true
local custom_sources_file="/etc/apt/sources.list"
while getopts 'BbdK:kT:t' o "$@"; do
case "$o" in
B) cow_build_opts="--debbuildopts '-B'";;
b) cow_build_opts="--debbuildopts '-b'";;
d) debug_hook=true;;
k) keep_pbuilder_config=true;;
K) custom_keyring="$OPTARG";;
t) custom_sources_file="/etc/apt/sources.list";;
T) custom_sources_file="$OPTARG";;
esac
done
shift $(($OPTIND-1))
if [ "$custom_sources_file" == "/etc/apt/sources.list" ]; then
# If you are using the system sources, then it is reasonable that you expect to use all of the supplementary repos too
cat /etc/apt/sources.list > /tmp/fs.sources.list
if [ "$(ls -A /etc/apt/sources.list.d)" ]; then
for X in /etc/apt/sources.list.d/*; do cat $X >> /tmp/fs.sources.list; done
fi
custom_sources_file="/tmp/fs.sources.list"
apt-key exportall > "/tmp/fs.tmp.gpg"
gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --import /tmp/fs.tmp.gpg
gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --export > "/tmp/fs.gpg"
custom_keyring="/tmp/fs.gpg"
fi
if [ "$custom_sources_file" == "" ]; then
# Caller has explicitly set the custom sources file to empty string. They must intend to not use additional mirrors.
use_custom_sources=false
fi
if [[ "$custom_source_file" == "/tmp/fs.sources.list" && ! -e "/tmp/fs.sources.list" ]]; then
echo "deb [trusted=yes] http://files.freeswitch.org/repo/deb/freeswitch-1.8/ stretch main" >> "/tmp/fs.sources.list"
fi
if [[ "$custom_keyring" == "/tmp/fs.gpg" && ! -r "/tmp/fs.gpg" ]]; then
cat << EOF > "/tmp/fs.tmp.gpg"
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFlVeA4BEADg3MkzUvnbuqG7S6ppt0BJIYx2WIlDzsj2EBPBBo7VpppWPGa/
5IDuCgSTVeNPffo6jlHk6HFK4g3r+oVJIDoSGE8bKHAeva/iQRUx5o56zXBVOu8q
3lkUQBjRD+14Ujz9pShNylNfIjgmUp/lg93JYHvIMVGp3AcQKr0dgkhw31NXV2D1
BOSXdx6SNcbIhjY1X4CQivrz+WfX6Lk6vfWTwF0qDC0f7TYSEKmR4Sxadx/3Pb+a
+Hiu3BrYtpf99ldwjb2OsfHnRvdf57z+9cA6IEbA+5ergHgrMOVj8oRRCjWM2qNg
5aaJa5WfQsPNNQ41hvjYkdOJjI5mOUFEhX0+y0Gab7S5KCvNn8f5oGvcaYLjFfM4
syl2CbNx4mKfx+zJ43eH6GsU2N0VCk2lNZt0TV6p3AjZ4ofjj9YusQ6FczlWUgFW
QlNQZsR5KXAhVu3ACKWsy2WSvfkSOMPpM4lAXJvHyqXh8kO+GsuedVgu8uOiAmkS
acyPLohm0W87q2N/6xZ4OH7oMHQFos3hrknlESySN1iJz2qyuysL0yh77OWtdJH+
GIsnftEH33ggG69FHZRDouC60C2HwWxrOwngCSxFEdQppJZjI1H5wSIUOuywZ6a0
+mSe/ZnZKL/hYjy/ZQhGWdmliN8V0WF2MEesk1ouQg63bzxOYEo6Fpw6AwARAQAB
tD1GcmVlU1dJVENIIFBhY2thZ2luZyBLZXkgKERlYmlhbiA5KSA8cGFja2FnZXNA
ZnJlZXN3aXRjaC5vcmc+iQJUBBMBAgA+AhsDBQkSzAMAAh4BAheAFiEEXgmLPRhA
bo4ZVDcJvTGJ9aK1dpgFAluB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5nT2v/kqsgqUHUQLuwdjF1McJQpC0BK3cYXSMLe4vFE8B3/T
Y4o4oqgePeTYzkxVYj8=
=XPvO
-----END PGP PUBLIC KEY BLOCK-----
EOF
gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --import /tmp/fs.tmp.gpg
gpg --no-default-keyring --keyring /tmp/fs.tmp.keyring.gpg --export > "/tmp/fs.gpg"
fi
local distro="$(find_distro $1)" dsc="$2" arch="$3"
if [ -z "$distro" ] || [ "$distro" = "auto" ]; then
if ! (echo "$dsc" | grep -e '-[0-9]*~[a-z]*+[0-9]*'); then
err "no distro specified or found"
fi
local x="$(echo $dsc | sed -e 's/^[^-]*-[0-9]*~//' -e 's/+[^+]*$//')"
distro="$(find_distro $x)"
fi
[ -n "$arch" ] || arch="$(dpkg-architecture | grep '^DEB_BUILD_ARCH=' | cut -d'=' -f2)"
[ -x "$(which cowbuilder)" ] \
|| err "package cowbuilder isn't installed"
local cow_img=/var/cache/pbuilder/base-$distro-$arch.cow
if [ -e "$custom_keyring" ]; then
keyring="$custom_keyring"
else
keyring="$(mktemp /tmp/keyringXXXXXXXX.asc)"
apt-key exportall > "$keyring"
fi
cow () {
if ! $use_custom_sources; then
echo "Using system sources $keyring $distro $custom_sources_file"
cowbuilder "$@" \
--distribution $distro \
--architecture $arch \
--basepath $cow_img
else
echo "Using custom sources $keyring $distro $custom_sources_file"
cowbuilder "$@" \
--distribution $distro \
--architecture $arch \
--basepath $cow_img \
--keyring "$keyring" \
--othermirror "$(get_mirrors $distro $custom_sources_file)"
fi
}
if ! [ -d $cow_img ]; then
announce "Creating base $distro-$arch image..."
local x=30
while ! cow --create; do
[ $x -lt 1 ] && break; sleep 120; x=$((x-1))
done
fi
announce "Updating base $distro-$arch image..."
local x=30
local opts="--override-config"
$keep_pbuilder_config && opts=""
while ! cow --update $opts; do
[ $x -lt 1 ] && break; sleep 120; x=$((x-1))
done
announce "Building $distro-$arch DEBs from $dsc..."
if $debug_hook; then
mkdir -p .hooks
fmt_debug_hook > .hooks/C10shell
chmod +x .hooks/C10shell
hookdir=$(pwd)/.hooks
fi
cow --build $dsc \
--hookdir "$hookdir" \
--buildresult ../ \
$cow_build_opts
if [ ! -e "$custom_keyring" ]; then
# Cleanup script created temporary file
rm -f $keyring
fi
} 1>&2
echo ${dsc%.dsc}_${arch}.changes
}
default_distros () {
local host_distro="Debian"
test -z "$(which lsb_release)" || host_distro="$(lsb_release -is)"
case "$host_distro" in
Debian) echo "sid stretch jessie" ;;
Ubuntu) echo "utopic trusty" ;;
*) err "Unknown host distribution \"$host_distro\"" ;;
esac
}
build_all () {
local OPTIND OPTARG
local orig_opts="" dsc_opts="" deb_opts="" modlist=""
local archs="" distros="" orig="" depinst=false par=false
while getopts 'a:bc:df:ijkK:l:m:no:p:s:tT:u:v:z:' o "$@"; do
case "$o" in
a) archs="$archs $OPTARG";;
b) orig_opts="$orig_opts -b";;
c) distros="$distros $OPTARG";;
d) deb_opts="$deb_opts -d";;
f) dsc_opts="$dsc_opts -f$OPTARG";;
i) depinst=true;;
j) par=true;;
k) deb_opts="$deb_opts -k";;
K) deb_opts="$deb_opts -K$OPTARG";;
l) modlist="$OPTARG";;
m) orig_opts="$orig_opts -m$OPTARG"; dsc_opts="$dsc_opts -m$OPTARG";;
n) orig_opts="$orig_opts -n";;
o) orig="$OPTARG";;
p) dsc_opts="$dsc_opts -p$OPTARG";;
s) dsc_opts="$dsc_opts -s$OPTARG";;
t) deb_opts="$deb_opts -t";;
T) deb_opts="$deb_opts -T$OPTARG";;
u) dsc_opts="$dsc_opts -u$OPTARG";;
v) orig_opts="$orig_opts -v$OPTARG";;
z) orig_opts="$orig_opts -z$OPTARG"; dsc_opts="$dsc_opts -z$OPTARG";;
esac
done
shift $(($OPTIND-1))
[ -n "$archs" ] || archs="amd64 i386"
[ -n "$distros" ] || distros="$(default_distros)"
! $depinst || aptitude install -y \
rsync git less cowbuilder ccache \
devscripts equivs build-essential yasm
[ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
if [ -n "$modlist" ]; then
local modtmp="$(mktemp /tmp/modules-XXXXXXXXXX.conf)"
> $modtmp
for m in "$modlist"; do printf '%s\n' "$m" >> $modtmp; done
dsc_opts="$dsc_opts -f${modtmp}"; fi
[ -n "$orig" ] || orig="$(create_orig $orig_opts HEAD | tail -n1)"
mkdir -p ../log
> ../log/changes.txt
echo; echo; echo; echo
trap 'echo "Killing children...">&2; for x in $(jobs -p); do kill $x; done' EXIT
if [ "${orig:0:2}" = ".." ]; then
echo "true" > ../log/builds-ok.txt
for distro in $distros; do
echo "Creating $distro dsc..." >&2
local dsc="$(create_dsc $dsc_opts $distro $orig 2>../log/$distro.txt | tail -n1)"
echo "Done creating $distro dsc." >&2
if [ "${dsc:0:2}" = ".." ]; then
local lopts="-b"
for arch in $archs; do
{
echo "Building $distro-$arch debs..." >&2
local changes="$(build_debs $lopts $deb_opts $distro $dsc $arch 2>../log/$distro-$arch.txt | tail -n1)"
echo "Done building $distro-$arch debs." >&2
if [ "${changes:0:2}" = ".." ]; then
echo "$changes" >> ../log/changes.txt
else
echo "false" > ../log/builds-ok.txt
fi
} &
$par || wait
lopts="-B"
done
fi
done
! $par || wait
fi
[ -z "$modlist" ] || rm -f $modtmp
trap - EXIT
cat ../log/changes.txt
test "$(cat ../log/builds-ok.txt)" = true || exit 1
}
usage () {
cat >&2 <<EOF
$0 [opts] [cmd] [cmd-opts]
options:
-d Enable debugging mode.
commands:
archive-orig
build-all
[ This must be run as root! ]
-a Specify architectures
-c Specify distributions
-d Enable cowbuilder debug hook
-f <modules.conf>
Build only modules listed in this file
-i Auto install build deps on host system
-j Build debs in parallel
-k Don't override pbuilder image configurations
-K [/path/to/keyring.asc]
Use custom keyring file for sources.list in build environment
in the format of: apt-key exportall > /path/to/file.asc
-l <modules>
-m [ quicktest | non-dfsg ]
Choose custom list of modules to build
-n Nightly build
-o <orig-file>
Specify existing .orig.tar.xz file
-p <module>
Include otherwise avoided module
-s [ paranoid | reckless ]
Set FS bootstrap/build -j flags
-t Use system /etc/apt/sources.list in build environment(does not include /etc/apt/sources.list.d/*.list)
-T [/path/to/sources.list]
Use custom /etc/apt/sources.list in build environment
-u <suite-postfix>
Specify a custom suite postfix
-v Set version
-z Set compression level
build-debs <distro> <dsc-file> <architecture>
[ This must be run as root! ]
-B Binary architecture-dependent build
-b Binary-only build
-d Enable cowbuilder debug hook
-k Don't override pbuilder image configurations
-K [/path/to/keyring.asc]
Use custom keyring file for sources.list in build environment
in the format of: apt-key exportall > /path/to/file.asc
-t Use system /etc/apt/sources.list in build environment
-T [/path/to/sources.list]
Use custom /etc/apt/sources.list in build environment
create-dbg-pkgs
create-dsc <distro> <orig-file> (same for 'prep-create-dsc')
-f <modules.conf>
Build only modules listed in this file
-m [ quicktest | non-dfsg ]
Choose custom list of modules to build
-p <module>
Include otherwise avoided module
-s [ paranoid | reckless ]
Set FS bootstrap/build -j flags
-u <suite-postfix>
Specify a custom suite postfix
-x Use git soft reset instead of hard reset
-z Set compression level
create-orig <treeish> (same for 'prep_create_orig')
-m [ quicktest | non-dfsg ]
Choose custom list of modules to build
-n Nightly build
-v Set version
-V Set version (without replacing every '-' to '~')
-x Use git soft reset instead of hard reset
-z Set compression level
EOF
exit 1
}
while getopts 'dh' o "$@"; do
case "$o" in
d) set -vx;;
h) usage;;
esac
done
shift $(($OPTIND-1))
cmd="$1"; [ -n "$cmd" ] || usage
shift
case "$cmd" in
archive-orig) archive_orig "$@" ;;
build-all) build_all "$@" ;;
build-debs) build_debs "$@" ;;
create-dbg-pkgs) create_dbg_pkgs ;;
prep-create-dsc) prep_create_dsc "$@" ;;
create-dsc) create_dsc "$@" ;;
prep-create-orig) prep_create_orig "$@" ;;
create-orig) create_orig "$@" ;;
*) usage ;;
esac