-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmolior-deploy
executable file
·1717 lines (1530 loc) · 46.5 KB
/
molior-deploy
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
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
. /usr/lib/molior-tools/molior.sh.inc
APTLY_OVERRIDE=0
LIST_ONLY=0
ask_cleanup=1
user_abort=0
deploy_all=0
keep_log=0
no_color=0
unstable_sources=0
dist=stable
lvm_rename_existing=0
DEPLOYMENT_SHA256=0
OVERLAY_VERSION=""
OVERLAY_AUTO=0
VARIANT=""
MOLIOR_PROJECTINFO_FILE=""
src_pkg_only=0
output_build_vars=0
omit_local_suffix=0
debug_mode=0
docker_login_registries=""
deploy_conf_level=0
MOLIOR_TOOLS_VERSION=`cat /usr/lib/molior-tools/version`
usage()
{
echo "molior-tools $MOLIOR_TOOLS_VERSION"
echo
echo "Usage: $0 [OPTIONS] PROJECT VERSION"
echo "Options:"
echo " -l List deployment variants"
echo " -n PACKAGE_NAME Package name (Default: PROJECT)"
echo " -s SOURCE_DIR Use local source tree (Default: download source package)"
echo " -v VARIANT Deployment variant to generate (Default: ask)"
echo " -p PRJSRC_FILE Do not download project source from molior sever, use file contents"
echo " -m MOLIOR_SERVER Molior server to use (Default in ~/.moliorrc)"
echo " -a APTLY_SERVER Aptly server to use (Default in ~/.moliorrc)"
echo " -A Override project apt sources with APTLY_SERVER"
echo " -V PKG_VERSION Pin pkg version to install. Dangerous, use with care!"
echo " -O Automatically find top level package in the available projectversions"
echo " -o OVERLAY_BASE Specify overlay base and fetch top level package from there"
echo " -c Cleanup on error (Default: ask)"
echo " -f Build all variants (Default: ask)"
echo " -F OUTPUT_FILE Custom deployment output's filename"
echo " -d Debug APT package resolver. Print debug output to stdout instead of file"
echo " -t Text output only, do not print colored output"
echo " -r Keep rootfs of final deployment (to be used for -i)"
echo " -i ROOTFS_TAR Use existing rootfs (tar) as base for post install (tar created with -r)"
echo " -L Keep log file"
echo " -U Use unstable APT sources (CI Builds)"
echo " -u Use unstable top level package (INSTALL_PACKAGE in deploy file)"
echo " -S Only download source package"
echo " -D Output build variables"
echo " -C Omit +local suffix for local builds"
echo " -T TMPDIR Use TMPDIR (Default: \$MOLIOR_TMPDIR env variable or /tmp)"
echo
if [ -n "$1" ]; then
echo $1
fi
echo
exit 1
}
origopts=$@
while getopts "n:s:v:p:m:a:V:o:F:b:i:rtAlcfdOLUuSDCT:" opt; do
case $opt in
n)
PACKAGE_NAME=$OPTARG
shift 2
;;
s)
SOURCE_DIR=$OPTARG
shift 2
;;
v)
VARIANT=$OPTARG
shift 2
;;
p)
MOLIOR_PROJECTSOURCES_FILE=$OPTARG
shift 2
;;
m)
MOLIOR_SERVER=$OPTARG
shift 2
;;
a)
APTLY_SERVER=$OPTARG
shift 2
;;
V)
PACKAGE_VERSION=$OPTARG
shift 2
;;
o)
OVERLAY_VERSION=$OPTARG
shift 2
;;
F)
DEPLOYMENT_OUTPUT_FILE=$OPTARG
shift 2
;;
O)
OVERLAY_AUTO=1
shift 1
;;
A)
APTLY_OVERRIDE=1
shift 1
;;
l)
LIST_ONLY=1
shift 1
;;
c)
ask_cleanup=0
shift 1
;;
f)
deploy_all=1
shift 1
;;
d)
debug_mode=1
APT_DEBUG_OPTIONS="-o Debug::pkgProblemResolver=yes"
shift 1
;;
L)
keep_log=1
shift 1
;;
U)
unstable_sources=1
shift 1
;;
u)
dist=unstable
shift 1
;;
t)
no_color=1
shift 1
;;
r)
KEEP_ROOTFS=1
shift 1
;;
i)
BASE_ROOTFS=$OPTARG
shift 2
;;
S)
src_pkg_only=1
shift 1
;;
D)
output_build_vars=1
shift 1
;;
C)
omit_local_suffix=1
shift 1
;;
T)
MOLIOR_TMPDIR=$OPTARG
shift 2
;;
\?)
exit 1
;;
:)
usage "Option -$OPTARG requires an argument." >&2
;;
esac
done
if [ $LIST_ONLY -eq 0 -a `id -u` -ne 0 ]; then
usage "Please run $0 as root" >&2
fi
PROJECT=$1
VERSION=$2
if [ -z "$PROJECT" ]; then
usage
fi
if [ -z "$VERSION" ]; then
usage
fi
if [ $LIST_ONLY -eq 0 -a "$deploy_all" -eq 1 ]; then
opts=`echo $origopts | sed -e "s/$PROJECT//" -e "s/$VERSION//" -e 's/-f//'`
for variant in `eval molior-deploy $opts -l $PROJECT $VERSION`
do
echo
echo "### running molior-deploy $opts -c -v $variant $PROJECT $VERSION"
echo
eval molior-deploy $opts -c -v $variant $PROJECT $VERSION
done
exit 0
fi
if [ -z "$PACKAGE_NAME" ]; then
PACKAGE_NAME=`echo $PROJECT | tr '[:upper:]' '[:lower:]'`
fi
if [ -z "$MOLIOR_SERVER" ]; then
MOLIOR_SERVER=$MOLIOR_URL
fi
if [ -z "$APTLY_SERVER" ]; then
APTLY_SERVER=$MOLIOR_REPO_URL
fi
if [ -z "$MOLIOR_TMPDIR" ]; then
MOLIOR_TMPDIR=/tmp
fi
# clean env
unset LANGUAGE
unset LC_ALL
unset LC_PAPER
unset LC_NUMERIC
unset LC_IDENTIFICATION
unset LC_MEASUREMENT
unset LC_NAME
unset LC_TELEPHONE
unset LC_ADDRESS
unset LC_MONETARY
unset LC_TIME
unset LANG
export HOME=/root
# default settings
DEPLOYMENT_TYPE=image
INSTALL_PACKAGE=""
PRESEED_FILE=""
REQUIRED_MOLIORTOOLS_VERSION=""
if [ "$KEEP_ROOTFS" != "1" ]; then
KEEP_ROOTFS=0
fi
# logging
if [ $no_color -ne 1 ]; then
color_info="\e[36m\e[1m"
color_notice="\e[34m\e[1m"
color_warn="\e[35m\e[1m"
color_error="\e[31m\e[1m"
color_ask="\e[33m\e[1m"
color_reset="\e[0m"
else
color_info=""
color_notice=""
color_warn=""
color_error=""
color_ask=""
color_reset=""
fi
log()
{
if [ "$LIST_ONLY" -eq 0 ]; then
echo " * $@"
fi
}
log_info()
{
if [ "$LIST_ONLY" -eq 0 ]; then
/bin/echo -e "${color_info}I: $@ $color_reset"
fi
}
log_notice()
{
if [ "$LIST_ONLY" -eq 0 ]; then
/bin/echo -e "${color_notice}N: $@ $color_reset"
fi
}
log_warn()
{
if [ "$LIST_ONLY" -eq 0 ]; then
/bin/echo -e "${color_warn}W: $@ $color_reset"
fi
}
log_error()
{
/bin/echo -e "${color_error}E: $@ $color_reset"
set +x
if [ -n "$target" -a "$user_abort" -eq 0 -a "$ask_cleanup" -eq 1 ]; then
log_info "examine situation: sudo chroot $target"
fi
# if RET is set to non zero, use it as exit code
if [ -n "$RET" ]; then
if [ "$RET" = "0" ]; then
RET=1
fi
else
RET=1
fi
exit $RET
}
# include helper functions
. /usr/lib/molior-deploy/molior-deploy.sh.inc
if ls /usr/lib/molior-deploy/molior-deploy.d/*.inc > /dev/null 2>&1; then
. /usr/lib/molior-deploy/molior-deploy.d/*.inc
fi
# init
success=0
CUR_DIR=`pwd`
WORK_DIR=`mktemp -p $MOLIOR_TMPDIR -d molior-XXXXXXXX`
exit_on_error "Error creating temporary directory in '$MOLIOR_TMPDIR'"
chmod 755 $WORK_DIR
errlog=$WORK_DIR/output.log
do_fstab=1
do_compress=1
do_installation=1
do_software_installation=1
starttime="0"
endtime="0"
target=""
# binftms to be disabled
BADFMTS="cli jar jarwrapper python2.7 python3.5"
if [ "$debug_mode" -ne 1 -a "$LIST_ONLY" -ne 1 ]; then
exec 3>&2
exec 2>$errlog
fi
echo >&2
echo " _ _ _ _ " >&2
echo " _ __ ___ ___ | (_) ___ _ __ __| | ___ _ __ | | ___ _ _ " >&2
echo "| '_ \` _ \ / _ \| | |/ _ \| '__|____ / _\` |/ _ \\ '_ \| |/ _ \| | | |" >&2
echo "| | | | | | (_) | | | (_) | | |_____| (_| | __/ |_) | | (_) | |_| |" >&2
echo "|_| |_| |_|\___/|_|_|\___/|_| \__,_|\___| .__/|_|\___/ \__, |" >&2
echo " |_| |___/ " >&2
echo >&2
echo $0 $@ >&2
echo "molior-tools version: $MOLIOR_TOOLS_VERSION" >&2
echo >&2
if [ "$LIST_ONLY" -eq 1 ]; then
ask_cleanup=0
else
set -x
fi
# functions
apt_get_chroot_with_retry ()
{
for i in seq 1 3; do
if chroot $target apt-get --download-only "$@"; then
break
fi
done
DEBIAN_FRONTEND=noninteractive chroot $target apt-get "$@"
}
finish ()
{
set +x
endtime=$(date +"%s")
if [ "$ask_cleanup" -eq 1 ]; then
if [ "$success" -ne 1 ]; then
ask "Cleanup $WORK_DIR ?" Y
if [ $? -ne 0 ]; then
echo "Please rm -rf $WORK_DIR later ..."
return 1
fi
fi
fi
if [ "$LIST_ONLY" -ne 1 ]; then
log "cleanup"
fi
umount_bootstrap
umount_fs
if type deinit_deployment_$DEPLOYMENT_TYPE >/dev/null; then
deinit_deployment_$DEPLOYMENT_TYPE
fi
if [ -n "$LVM_VG" ]; then
vgremove -f ${LVM_VG} >&2
if vgs ${LVM_VG}_molior_renamed >/dev/null 2>&1; then
log_warn "Warning: restoring local LVM VG $LVM_VG"
vgrename -A y ${LVM_VG}_molior_renamed $LVM_VG >&2
if [ $? -ne 0 ]; then
# no errors in trap handler
log_warn "Error restoring LVM VG $LVM_VG"
fi
fi
LVM_VG=""
fi
if [ -n "$disk" ]; then
# FIXME: only for loop disks, not /dev/nbd0
losetup -d $disk
disk=""
fi
if [ "$success" -eq 1 -a "$output_build_vars" -eq 1 ]; then
get_deploy_config > $CUR_DIR/deployment.vars
if [ -n "$SUDO_UID" -a -n "$SUDO_GID" ]; then
chown $SUDO_UID:$SUDO_GID $CUR_DIR/deployment.vars
fi
log "saving deploy configuration to deployment.vars"
fi
set +x
exec 2>&3 3>&-
if which update-binfmts >/dev/null 2>&1; then
for b in $BADFMTS
do
update-binfmts --enable $b >/dev/null 2>&1
done
fi
if [ "$user_abort" -eq 0 ]; then
if [ "$success" -ne 1 -o "$keep_log" -eq 1 ]; then
if [ -z "$VARIANT" ]; then
VARIANT="undefined"
fi
logfile=`date "+${PROJECT}_${VERSION}_${VARIANT}_%Y%m%d%H%M%S.log"`
cp $errlog $CUR_DIR/$logfile
test "$success" -ne 1 && log_info "full log: $logfile"
fi
fi
if grep -q $WORK_DIR /proc/mounts; then
umount `grep $WORK_DIR /proc/mounts | cut -d' ' -f2 | sort -r`
fi
if ! grep -q $WORK_DIR /proc/mounts; then
rm -rf $WORK_DIR
else
log_warn "not removing $WORK_DIR, still mounted:"
grep $WORK_DIR /proc/mounts
fi
diff=$((endtime-starttime))
if [ "$success" -ne 1 ]; then
if [ "$user_abort" -eq 0 ]; then
log_warn "failed within $((diff / 60)) minutes and $((diff % 60)) seconds"
fi
return 1
fi
if [ -n "$deployment" ]; then
size=`ls -lh $CUR_DIR/$deployment | cut -d ' ' -f5`
log_notice "Deployment created in $((diff / 60))m$((diff % 60))s: $deployment ($size)"
if type notify_deployment >/dev/null; then
echo
notify_deployment
echo
fi
fi
if [ $src_pkg_only -eq 1 ]; then
log_notice "Source package downloaded: `basename $FILENAME`"
fi
}
abort()
{
ask_cleanup=0
user_abort=1
echo
finish
}
trap finish EXIT
trap abort INT
ask()
{
y="y"
n="n"
default=1
if [ "$2" = "Y" ]; then
default=0
y="Y"
fi
if [ "$2" = "N" ]; then
n="N"
fi
/bin/echo -n -e "${color_ask}Q: $1 [$y/$n] $color_reset"
read x
case "$x" in
Y|y)
return 0
;;
"")
return $default
;;
*)
return 1
;;
esac
}
mountbind()
{
mount -o bind "$1" "$2"
if [ -n "$3" ]; then
mount -o remount,bind,$3 $2
fi
}
mount_bootstrap()
{
if [ -z "$target" ]; then
log_error "Error: \$target not set"
fi
CHROOTIGNORE=/usr/lib/molior-deploy/chroot-ignore
for ignore in $CHROOTIGNORE/*
do
cp $ignore $target/usr/local/bin
done
exit_on_error "Error mounting $target/usr/local/bin"
# Disable daemons in chroot:
cat >> $target/usr/sbin/policy-rc.d <<EOM
#!/bin/sh
while true; do
case "\$1" in
-*) shift ;;
makedev|x11-common) exit 0;;
EOM
if [ -n "$CHROOT_DAEMONS_ENABLED" ]; then
cat >> $target/usr/sbin/policy-rc.d <<EOM
$CHROOT_DAEMONS_ENABLED) exit 0;;
EOM
fi
cat >> $target/usr/sbin/policy-rc.d <<EOM
*) exit 101;;
esac
done
EOM
chmod +x $target/usr/sbin/policy-rc.d
mount udev -t devtmpfs $target/dev
exit_on_error "Error mounting $target/dev"
mount devpts -t devpts $target/dev/pts
exit_on_error "Error mounting $target/dev/pts"
mount proc -t proc $target/proc
exit_on_error "Error mounting $target/proc"
mount sysfs -t sysfs $target/sys
exit_on_error "Error mounting $target/sys"
mkdir -p $WORK_DIR/chroottmp
# set permissions on tmp including the sticky bit
chmod 1777 $WORK_DIR/chroottmp
mountbind $WORK_DIR/chroottmp $target/tmp
exit_on_error "Error mounting $target/tmp"
if [ -d $target/usr/tmp ]; then
mkdir -p $WORK_DIR/chrootvartmp
mountbind $WORK_DIR/chrootvartmp $target/var/tmp
exit_on_error "Error mounting $target/var/tmp"
fi
}
umount_bootstrap()
{
if [ -z "$target" ]; then
return
fi
sync
if [ -n "$BIND_MOUNTS" ]; then
for m in $BIND_MOUNTS
do
to=`echo $m | cut -d: -f2`
unmount $target/$to
done
fi
if [ -d "$target" ]; then
CHROOTIGNORE=/usr/lib/molior-deploy/chroot-ignore
for ignore in $CHROOTIGNORE/*
do
rm -f $target/usr/local/bin/$(basename "$ignore")
done
rm -f $target/usr/sbin/policy-rc.d
for m in `grep $target/proc /proc/mounts | cut -d' ' -f2 | tac`
do
umount $m
done
umount $target/proc
umount $target/sys
umount $target/dev/pts
umount $target/dev
umount $target/tmp
if [ -e $target/etc/apt/auth.conf ]; then
umount $target/etc/apt/auth.conf
fi
mountpoint -q $target/var/tmp && umount $target/var/tmp
fi
}
include_deploy_conf()
{
deploy_conf=$1
# allow recursive calls
deploy_conf_level=$((deploy_conf_level + 1))
if echo $deploy_conf | grep -q ":"; then
source_file=`echo $deploy_conf | cut -d: -f2`
deploy_conf=`echo $deploy_conf | cut -d: -f1`
else
source_file=deploy/common.inc
fi
log "downloading deploy conf package: $deploy_conf"
baseurls=`echo "$APT_SOURCES" | grep $SOURCEMIRROR/repos/ | awk '{print $2}'`
for baseurl in $baseurls
do
SOURCES_VERSION=`basename $baseurl`
curl -n -f -s --retry 10 -o $WORK_DIR/Sources.func $baseurl/dists/$dist/main/source/Sources
lines=`wc -l $WORK_DIR/Sources 2>/dev/null | cut -d' ' -f1`
if [ -n "$lines" ] && [ "$lines" -eq 0 ]; then
# try next baseurl
continue
fi
srcinfo=`/usr/lib/molior-tools/find-latest-version.pl $deploy_conf < $WORK_DIR/Sources.func`
if [ $? -ne 0 ]; then
# try next baseurl
continue
fi
CONFPKG_NAME=`echo $srcinfo | cut -d ' ' -f 1`/`echo $srcinfo | cut -d ' ' -f 2`
CONFPKG_REV=`echo $srcinfo | cut -d ' ' -f 3`
if [ -n "$CONFPKG_NAME" ]; then
FUNC_SOURCEMIRROR=$baseurl
# found package
break
fi
done
rm -f $WORK_DIR/Sources.func
if [ -z "$CONFPKG_NAME" ]; then
log_error "Error finding '$deploy_conf' source package in apt sources"
fi
confdir=`mktemp -d $WORK_DIR/conf-XXXXX`
old_dir=$PWD
cd $confdir
curl -n -f -s --retry 10 -O -J $FUNC_SOURCEMIRROR/$CONFPKG_NAME
exit_on_error "Error downloading $FUNC_SOURCEMIRROR/$CONFPKG_NAME"
tar xf `basename $CONFPKG_NAME`
exit_on_error "Error extracting `basename $CONFPKG_NAME`"
rm -f `basename $CONFPKG_NAME`
log "sourcing from $deploy_conf ($CONFPKG_REV): $source_file"
# provide new SOURCE_DIR for conf pkg includes to work (recursively)
eval orig_SOURCE_DIR_$deploy_conf_level=$SOURCE_DIR
SOURCE_DIR=$confdir/$deploy_conf
cd `dirname $deploy_conf/$source_file`
. $SOURCE_DIR/$source_file
cd - >/dev/null
eval SOURCE_DIR=\$orig_SOURCE_DIR_$deploy_conf_level
cd $old_dir
rm -rf $confdir
deploy_conf_level=$((deploy_conf_level - 1))
}
setup_deployment()
{
DEPLOYMENT_TIMESTAMP=`date -R`
starttime=$(date +"%s")
log_info "Creating deployment for $PROJECT/$VERSION"
log "molior-tools $MOLIOR_TOOLS_VERSION"
log "started: `date -R`"
log "logfile: $WORK_DIR/output.log"
if [ -z "$MOLIOR_PROJECTSOURCES_FILE" ]; then
param=""
if [ $unstable_sources -eq 1 ]; then
param="?unstable=true"
fi
log_info "Getting deployment information ..."
SOURCESURL=$MOLIOR_SERVER/api2/project/$PROJECT/$VERSION/aptsources
APT_SOURCES_ORIG=`curl -n -f -s --retry 10 $SOURCESURL$param`
if [ -z "$APT_SOURCES_ORIG" ]; then
SOURCESURL=$MOLIOR_SERVER/api/projectsources/$PROJECT/$VERSION
APT_SOURCES_ORIG=`curl -n -f -s --retry 10 $SOURCESURL`
if [ -z "$APT_SOURCES_ORIG" ]; then
log_error "Error downloading $SOURCESURL"
fi
fi
else
log_info "Reading deployment information from $MOLIOR_PROJECTSOURCES_FILE ..."
APT_SOURCES_ORIG=`cat $MOLIOR_PROJECTSOURCES_FILE`
if [ -z "$APT_SOURCES_ORIG" ]; then
log_error "Error reading $MOLIOR_PROJECTSOURCES_FILE"
fi
fi
if [ "$APTLY_OVERRIDE" -eq 1 ]; then
APT_SOURCES_ORIG=`echo "$APT_SOURCES_ORIG" | sed "s=deb \([^:]\)\+://\([^/]\)\+=deb $APTLY_SERVER="`
fi
APT_SOURCES=`echo "$APT_SOURCES_ORIG" | sed -e '/^#/d' -e '/^$/d'`
MIRROR=`echo "$APT_SOURCES" | head -n 1 | cut -d' ' -f 2`
if [ -z "$MIRROR" ]; then
log_error "No base mirror repo found"
fi
SUITE=`echo "$APT_SOURCES" | head -n 1 | cut -d' ' -f 3`
if [ -z "$SUITE" ]; then
log_error "No SUITE in APT repo found"
fi
tmp=`dirname $MIRROR`
REPOURL=`dirname $tmp`
BASEMIRROR=`basename $tmp`
BASEVERSION=`basename $MIRROR`
log "mirror: $MIRROR"
SOURCEMIRROR=`echo "$APT_SOURCES" | head -n 2 | tail -n 1 | cut -d' ' -f 2`
SOURCEMIRROR=`dirname $SOURCEMIRROR` # cut projectversion
SOURCEMIRROR=`dirname $SOURCEMIRROR` # cut project
SOURCEMIRROR=`dirname $SOURCEMIRROR` # cut /repos
log_info "Getting source package ..."
if [ -n "$SOURCE_DIR" ]; then
SOURCE_DIR=`readlink -f $SOURCE_DIR`
log "using local package source: $SOURCE_DIR"
cd $SOURCE_DIR
if [ $omit_local_suffix -eq 0 ]; then
REVISION=`dpkg-parsechangelog -S Version`+local
else
REVISION=`dpkg-parsechangelog -S Version`
fi
log "found source package: $PACKAGE_NAME $REVISION"
cd - >/dev/null
else
SOURCES_VERSION=$VERSION
if [ -n "$OVERLAY_VERSION" ]; then
SOURCES_VERSION=$OVERLAY_VERSION
log "using overlay source: $SOURCES_VERSION"
fi
if [ "$OVERLAY_AUTO" -eq 1 ]; then
baseurls=`echo "$APT_SOURCES" | grep $SOURCEMIRROR/repos/$PROJECT | awk '{print $2}'`
for baseurl in $baseurls
do
SOURCES_VERSION=`basename $baseurl`
log "trying to download package source from $SOURCES_VERSION"
curl -n -f -s --retry 10 -o $WORK_DIR/Sources $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/dists/$dist/main/source/Sources
if [ `wc -l $WORK_DIR/Sources 2>/dev/null | cut -d' ' -f1` -eq 0 ]; then
# try next baseurl
continue
fi
srcinfo=`/usr/lib/molior-tools/find-latest-version.pl $PACKAGE_NAME $PACKAGE_VERSION < $WORK_DIR/Sources`
if [ $? -ne 0 ]; then
# try next baseurl
continue
fi
FILENAME=`echo $srcinfo | cut -d ' ' -f 1`/`echo $srcinfo | cut -d ' ' -f 2`
REVISION=`echo $srcinfo | cut -d ' ' -f 3`
if [ -n "$FILENAME" ]; then
# found package
break
fi
done
if [ -z "$FILENAME" ]; then
log_error "No filename found for $PACKAGE_NAME in $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/dists/$dist/main/source/Sources"
fi
log "using package source: $SOURCES_VERSION"
else
curl -n -f -s --retry 10 -o $WORK_DIR/Sources $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/dists/$dist/main/source/Sources
# FIXME: check if exists...
if [ `wc -l $WORK_DIR/Sources 2>/dev/null | cut -d' ' -f1` -eq 0 ]; then
log_error "Could not download $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/dists/$dist/main/source/Sources"
fi
srcinfo=`/usr/lib/molior-tools/find-latest-version.pl $PACKAGE_NAME $PACKAGE_VERSION < $WORK_DIR/Sources`
exit_on_error "Error: package $PACKAGE_NAME not found in $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/dists/$dist/main/source/Sources"
FILENAME=`echo $srcinfo | cut -d ' ' -f 1`/`echo $srcinfo | cut -d ' ' -f 2`
REVISION=`echo $srcinfo | cut -d ' ' -f 3`
if [ -z "$FILENAME" ]; then
log_error "No filename found for $PACKAGE_NAME in $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/dists/$dist/main/source/Sources"
fi
fi
log "downloading source: $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/$FILENAME"
cd $WORK_DIR
curl -n -f -s --retry 10 -O -J $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/$FILENAME
exit_on_error "Error downloading $SOURCEMIRROR/repos/$PROJECT/$SOURCES_VERSION/$FILENAME"
if [ $src_pkg_only -eq 1 ]; then
mv `basename $FILENAME` $CUR_DIR
if [ -n "$SUDO_UID" -a -n "$SUDO_GID" ]; then
chown $SUDO_UID:$SUDO_GID $CUR_DIR/`basename $FILENAME`
fi
success=1
exit
fi
tar xf `basename $FILENAME`
rm -f `basename $FILENAME`
cd - >/dev/null
SOURCE_DIR=$WORK_DIR/$PACKAGE_NAME
fi
if [ ! -d $SOURCE_DIR/deploy ]; then
log_error "No deploy/ directory found in $SOURCE_DIR"
fi
if [ -z "`ls -1 $SOURCE_DIR/deploy/*.conf 2>/dev/null`" ]; then
log_error "No deploy/*.conf files found in $SOURCE_DIR"
fi
VARIANT=`echo $VARIANT | sed s/\.conf$//`
variants=""
count=0
found_variant=0
for t in $SOURCE_DIR/deploy/*.conf
do
if [ ! -z "$variants" ]; then
variants="$variants "
fi
t=`basename $t | sed s/\.conf$//`
variants="$variants$t"
if [ -n "$VARIANT" ]; then
if [ "$t" = "$VARIANT" ]; then
found_variant=1
break
fi
fi
count=$((count + 1))
done
if [ -n "$VARIANT" -a "$found_variant" -ne 1 ]; then
ask_cleanup=0
user_abort=1
log_error "Specified deployment variant '$VARIANT' not found (missing deploy/$VARIANT.conf)"
fi
if [ "$count" -eq 1 -a "$found_variant" -ne 1 ]; then
found_variant=1
VARIANT=$variants
fi
if [ "$LIST_ONLY" -eq 1 ]; then
for v in `echo $variants`
do
echo $v
done
success=1
exit 0
fi
if [ "$found_variant" -ne 1 ]; then
while true
do
# Read deployment variant. Use tab-completion if available.
if type rlwrap > /dev/null; then
rlwrap_comp=$WORK_DIR/molior-deployments.list
echo $variants > $rlwrap_comp
VARIANT=$(rlwrap -S "Q: Please choose a deployment variant: " -pYellow -e '' -i --break-chars ' ' -f $rlwrap_comp -o cat)
rm -f $rlwrap_comp
else
/bin/echo -n -e "${color_ask}Q: Please choose a deployment variant:\n`echo $variants | tr ' ' '\n' | sed 's/^/ > /'`\nEnter variant: $color_reset"
read VARIANT
fi
if [ -z "$VARIANT" ]; then
log_warn "No deployment variant choosen, aborting ..."
ask_cleanup=0
user_abort=1
VARIANT="undefined"
exit 1
fi
if [ -f $SOURCE_DIR/deploy/$VARIANT.conf ]; then
starttime=$(date +"%s")
break
fi
done
fi
log_notice "Selected deployment variant/type: $VARIANT/$DEPLOYMENT_TYPE"
cd `dirname $SOURCE_DIR/deploy/$VARIANT.conf`
. $SOURCE_DIR/deploy/$VARIANT.conf
cd - >/dev/null
check_required_version
# load plugin
if [ ! -e /usr/lib/molior-deploy/plugins/$DEPLOYMENT_TYPE.plugin ]; then
log "using custom plugin for '$DEPLOYMENT_TYPE'"
else
. /usr/lib/molior-deploy/plugins/$DEPLOYMENT_TYPE.plugin
fi
if [ -n "$ROOTPART" ]; then
log_warn "Warning: ROOTPART is deprecated, please use PART${ROOTPART}_MNT=/"
eval PART${ROOTPART}_MNT=/
fi
if [ -z "$ARCH" ]; then
log_warn "The deployment does not specify an architecture, assuming ARCH=amd64"
ARCH=amd64
fi
if echo $ARCH | grep -q arm; then
if ! which /usr/bin/qemu-arm-static >/dev/null || ! which /usr/sbin/update-binfmts >/dev/null; then
log_error "Error: qemu arm support is missing, run apt-get install binfmt-support qemu-user-static"
fi
fi
if [ -z "$DEPLOYMENT_COMPRESSION" ]; then
DEPLOYMENT_COMPRESSION=xz
fi
case $DEPLOYMENT_COMPRESSION in
none)
DEPLOYMENT_COMPRESSION_EXT=""
;;
xz)
DEPLOYMENT_COMPRESSION_EXT=".xz"
;;
gz|gzip)
DEPLOYMENT_COMPRESSION_EXT=".gz"
;;
*)
log_error "Unsupported deployment compression: '$DEPLOYMENT_COMPRESSION' (use: none, gz, xz)"
;;
esac
if [ -n "$RAID_NAME" -a -z "$RAID_DEVICES" ]; then
log_error "Error: RAID devices not definded, please set \$RAID_DEVICES"
fi
if [ -z "$DEPLOYMENT_OUTPUT_FILE" ]; then
DEPLOYMENT_OUTPUT_FILE="${PROJECT}_${VERSION}_${REVISION}_$VARIANT"
fi
target=$WORK_DIR/root
mkdir $target
}
bootstrap_deployment()
{
KEY_URL=$REPOURL/$PUBKEY_FILE
log "importing gpg key from $KEY_URL"
include="gnupg"
eval t=\$DEBOOTSTRAP_INCLUDE_`echo $SUITE | tr '-' '_'`
if [ -n "$t" ]; then
include="$include,$t"
fi
i=0
for url in $KEY_URL $APT_KEYS_EXTRA
do
if [ -z "$url" ]; then
continue
fi
if [ $i -ne 0 ]; then
postfix=".$i"
else
postfix=""
fi
i=$((i + 1))
curl -L -n -f -s --retry 10 -o $WORK_DIR/repo.asc$postfix $url
exit_on_error "Error downloading $url"
done
gpg -q --import --no-default-keyring --keyring=trustedkeys.gpg $WORK_DIR/repo.asc
log "downloading debootstrap for $SUITE $BASEMIRROR/$BASEVERSION $ARCH"
curl -n -f -s --retry 10 -o $WORK_DIR/root.tar.xz $MOLIOR_SERVER/debootstrap/${BASEMIRROR}_${BASEVERSION}_$ARCH.tar.xz
if [ $? -eq 0 ]; then
log "extracting debootstrap"
mkdir -p $target
cd $target
tar $TAR_PXZ -xf $WORK_DIR/root.tar.xz
cd - >/dev/null
rm -f $WORK_DIR/root.tar.xz
cp -fL /etc/resolv.conf $target/etc/resolv.conf
else
log "error downloading debootstrap archive..."
log "running debootstrap for $SUITE $BASEMIRROR/$BASEVERSION $ARCH"
if echo $ARCH | grep -q arm; then
debootstrap --foreign --arch $ARCH --keyring=/root/.gnupg/trustedkeys.gpg --variant=minbase --include=$include $SUITE $target $MIRROR >&2
exit_on_error "debootstrap failed"
if [ "$ARCH" = "armhf" ]; then
cp /usr/bin/qemu-arm-static $target/usr/bin/