forked from yedino/galaxy42
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-gitian
executable file
·695 lines (591 loc) · 24.5 KB
/
build-gitian
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
#!/bin/bash -e
echo -e "\nThis script can run the Gitian-Build of this project, to produce deterministic builds\n"
[ -r "toplevel" ] || { echo "Run this while being in the top-level directory; Can't find 'toplevel' in PWD=$PWD"; exit 1; }
dir_base_of_source=$(pwd) # need absolute path when we change dirs later
source gettext.sh || { echo "Gettext is not installed, please install it." ; exit 1 ; }
export TEXTDOMAIN="galaxy42_scripts"
export TEXTDOMAINDIR="${dir_base_of_source}share/locale/"
lib='abdialog.sh'; source "${dir_base_of_source}/share/script/lib/${lib}" || {\
printf "\n%s\n" "$(eval_gettext 'Can not find script library $lib (dir_base_of_source=$dir_base_of_source).')" ; exit 1; }
lib='utils.sh'; source "${dir_base_of_source}/share/script/lib/${lib}" || {\
printf "\n%s\n" "$(eval_gettext 'Can not find script library $lib (dir_base_of_source=$dir_base_of_source).')" ; exit 1; }
lib='g42-middle-utils.sh' ; source "${dir_base_of_source}/share/script/lib/${lib}" || {\
printf "\n%s\n" "$(eval_gettext "Can not find script library \$lib (dir_base_of_source=\$dir_base_of_source).")" ; exit 1; }
lib='gitian-utils.sh'; source "${dir_base_of_source}/share/script/lib/${lib}" || {\
printf "\n%s\n" "$(eval_gettext 'Can not find script library $lib (dir_base_of_source=$dir_base_of_source).')" ; exit 1; }
init_platforminfo || { printf "%s\n" "$(gettext "error_init_platforminfo")" ; exit 1; }
target_name="galaxy42" # will be asserted when detecting git repo url. this also becomes name of the directory in ~/
# target_repo_user , target_url will be auto detected
function fail() {
echo "ERROR occured (in $0) will exit now."
echo "ERROR is: " "$@"
exit 1
}
function usage() {
cat <<EOF
Usage: call this program like:
$0 -W image
$0 -W fast
$0 -M image
$0 -L fast
$0 [-W -L -M] [options] build_type
-W is windows build
-L is linux build
-M is mac osx build
build_type is:
install - installs everything, this will do a sudo and as root will setup it all - run it once
image - also recreates the System Image (e.g. LXC) - run it once (as user) and then from time to time
fast - faster gbuild, no re-creationg of System Image (e.g. LXC) - run it often
show - just show the results (as they are now)
on-target (or "o-t") - opens a bash console inside the System Image (e.g. LXC) so you can debug it here
on-target-root (or "o-t-r") - same, but you are the root user (inside System Image e.g. LXC)
fix1 - special function: re-run configuration on-target
Options:
-s single dir - use the same main directory for all Gitian temporary data,
and images (around 3 GB size)
-m multi dir - use and save a separate directory for each platform,
for the Gitian temporary data and images, e.g. one dir for -L linux, other for -W windows,
etc (each dir is around 3 GB size) - this can help to speedup builds if you often here
for example build linux then windows then again linux
Configuration options, set env variables:
export buildgitian_dbs_skip_template_fix=1 to skip the automatic debootstrap template fix
export buildgitian_dbs_sys="/some/dir" to force the debootstrap template fix to search there for it's files
EOF
}
# --- parse options ---
option_platform_windows=0
option_platform_linux=0
option_platform_osx=0
option_basedir_multi=0
function parse_options() {
echo "Parsing options"
used_sm=0 # did we already given one of this excluding options (to detect conflict in options): -s , -m for option_basedir_multi
while getopts ":hWLMsm" opt; do
case $opt in
h)
usage
exit 0
;;
W)
option_platform_windows=1
;;
L)
option_platform_linux=1
;;
M)
option_platform_osx=1
;;
s)
if [[ "$used_sm" == "true" ]] ; then fail "Do not use both Single and Multi option together" ; fi
echo "-s option"
option_basedir_multi=0
used_sm=1
;;
m)
if [[ "$used_sm" == "true" ]] ; then fail "Do not use both Single and Multi option together" ; fi
echo "-m option"
option_basedir_multi=1
used_sm=1
;;
esac
done
shift $((OPTIND-1)) # eat all the options paresed above
printf "Program is running with options:\n"
printf "%s\n" "option_platform_windows=$option_platform_windows"
printf "%s\n" "option_platform_linux=$option_platform_linux"
printf "%s\n" "option_platform_osx=$option_platform_osx"
## can not pass options via Gitian to inside Gitian -> yml -> script...
## printf "\n%s\n" "options to be passed to the Gitian would be:"
## printf "%s\n" "$@"
runmode="$1" ;
shift || fail "Run program with some runmode in command line arguments; Run with -h to see usage help".
printf "runmode=%s\n" "runmode"
}
base_dir=""
function set_base_dir() {
image_name=""
if (( option_basedir_multi )) ; then
echo "Using multi basedir"
if (( option_platform_osx )) ; then
image_name="macosx"
elif (( option_platform_windows )) ; then
image_name="windows"
elif (( option_platform_linux )) ; then
image_name="linux"
else
fail "Unknown (or none) platform used (when choosing image_name)"
fi
else
echo "Using single basedir"
fi
base_dir="$HOME/var-gitian${image_name:+-$image_name}/"
echo "Using base_dir=\"$base_dir\" , for image_name=\"$image_name\""
}
# --- execute main program ---
function main_run_action() {
# --- test can we run fast for this base_dir e.g. as multidir ---
printf "\n\n%s\n\n" "Testing data in base_dir=[$base_dir]"
if [[ "$runmode" == "fast" ]] ; then
filename="$base_dir/gitian-builder/$gitian_filename_of_target" # e.g. ~/var-gitian/gitian-builder/target-xenial-amd64
if [[ -r "$filename" ]] ; then
echo "OK, we can run FAST build - Image of Target seems to exist ($filename). $runmode"
else
echo "Note: we can NOT run FAST build - Image of Target is not readable by us (probably not existing) ($filename). $runmode"
runmode="image"
echo "CHANGING RUNMODE:"
echo "runmode=$runmode"
fi
fi
printf "\n\n\n"
anything=0
if [[ "$runmode" == "install" ]] ; then anything=1 ; setup_host_for_lxc ; fi
if [[ "$runmode" == "image" ]] ; then anything=1 ; all_including_new_lxc "$@" ; fi
if [[ "$runmode" == "fast" ]] ; then anything=1 ; all_excluding_new_lxc "$@" ; fi
if [[ "$runmode" == "show" ]] ; then anything=1 ; run_onlyresult ; fi
if [[ "$runmode" == "on-target" || "$runmode" == "ont" || "$runmode" == "o-t" ]] ; then anything=1 ; special_command_on_target "$@" ; fi
if [[ "$runmode" == "on-target-root" || "$runmode" == "ontr" || "$runmode" == "o-t-r" ]] ; then anything=1 ; special_command_on_target "-u" "root" "$@" ; fi
if [[ "$runmode" == "fix1" ]] ; then anything=1 ; gitian_my_cfg_on_target ; fi
if (( ! anything )) ; then
printf "\n%s\n" "No action was selected. Run with -h for usage."
fi
}
# --- tmp dir ---
my_dir="$PWD"
my_tmp="$my_dir/vartmp/build-gitian/" ; rm -rf "$my_tmp" || exit 1
function script_cleanup() {
rm --one-file-system -rf "$my_tmp"
}
trap script_cleanup EXIT
mkdir -p "$my_tmp" || exit
# --- config ---
# Where from get the Gitian tool itself:
gitiansoftware_url="https://github.com/devrandom/gitian-builder.git"
#"https://github.com/devrandom/gitian-builder.git"
gitiansoftware_checkout="a918531859ecc7d391ce37a7d7435a222c6b9af3" # can be tag etc
gitiansoftware_checkout_hash="a918531859ecc7d391ce37a7d7435a222c6b9af3" # must be a hash to confirm
# "ee1b69d6949810069453d5540af7a0b3ca63ea8d"
gitian_suite=xenial
gitian_filename_of_target="target-${gitian_suite}-amd64"
# ---
parse_options "$@"
set_base_dir
target_dbs="${base_dir}debootstrap/"
echo "Using target_dbs=$target_dbs for debootstrap dir"
# get our own version
info_thisscript="$( git describe --dirty="-DIRTY-NOT-COMMITED" )"
echo -e "Building using the build script from: $info_thisscript\n"
# cd
echo "Working in base_dir=${base_dir}"
mkdir -p "$base_dir" || fail "Can not create the base dir ($base_dir)"
cd "$base_dir" || fail "Can not enter the base dir ($base_dir)"
function fix_template_script() {
# fix Debian Jessie (and any other distro) that lacks Xenial script/template in it's debootstrap.
# gbuild calls ---> make-base-vm (it's own script) ---> that calls debootstrap from system.
# debootstrap uses dir DEBOOTSTRAP_DIR=/usr/share/debootstrap to load templates.
# that dir contains:
# devices.tar.gz functions/ scripts/
# and the subdir scripts/ needs to have script e.g. "xenial" (when we use xenial ubuntu in our Gitian process)
if [[ ! -z "$buildgitian_dbs_skip_template_fix" ]] ; then printf "Skipping debootstrap template fix (due to options)\n"; return ; fi
if [[ ! -z "$buildgitian_dbs_sys" ]] ; then
dbs_sys="$buildgitian_dbs_sys"
else
dbs_sys="/usr/share/debootstrap" # system's location of debootstrap
[[ -r "$dbs_sys" ]] || {
printf "Warning: Can not read debootstrap data dir [$dbs_sys]\n"
dbs_sys="/usr/local/share/debootstrap" # other location
[[ -r "$dbs_sys" ]] || {
printf "Warning: Can not read debootstrap data dir [$dbs_sys]\n"
printf "Error: Debootstrap seems not installed\n" ; exit 1; # exit
}
}
fi
printf "\nAssuming debootstrap system's version data dir is dbs_sys=$dbs_sys\n"
suite="$gitian_suite"
rm -rf "${target_dbs}"
mkdir -p "${target_dbs}"
if [[ ! -r "$dbs_sys/scripts/$suite" ]] ; then
echo "Your system seems to lack te debootstrap template for suite '$suite', we will work around this now."
for item_full in "${dbs_sys}"/* ; do # link top level things, e.g. "functions/" except for scripts/
[[ -e "$item_full" ]] || { echo "Can not read item_full (step1) $item_full" ; exit 1 ; }
item="${item_full##*/}"
echo "(step1) item_full=$item_full item=$item"
if [[ "$item" != "scripts" ]] ; then
ln -s "$item_full" "${target_dbs}" # link whole subdir
fi
done
mkdir "${target_dbs}/scripts"
for item_full in "${dbs_sys}/scripts"/* ; do # link all scripts
echo "(step2) item_full=$item_full"
ln -s "$item_full" "${target_dbs}scripts" # link a script
done
# add our script file:
cp "${my_dir}/contrib/gitian-debootstrap/scripts/${suite}" "$target_dbs/scripts/"
export DEBOOTSTRAP_DIR="$target_dbs"
export GITIAN_SUDO_USE_DEBOOTSTRAP_DIR="yes"
echo "Exporting DEBOOTSTRAP_DIR=$DEBOOTSTRAP_DIR GITIAN_SUDO_USE_DEBOOTSTRAP_DIR=$GITIAN_SUDO_USE_DEBOOTSTRAP_DIR"
else
echo "Your system's debootstrap seems ready to support suite '$suite' - no need to fix anything there."
fi
}
function set_env() {
export USE_LXC=1
export PATH="$PATH:$base_dir/gitian-builder/libexec"
export LXC_ARCH=amd64
export LXC_SUITE="$gitian_suite"
# export VERSION=""
export GITIAN_HOST_IP=10.0.3.2
export LXC_GUEST_IP=10.0.3.5
}
function setup_host_for_lxc() {
cat <<EOF
To configure your system for Gitian, please use ./install script,
or see doc/*gitian*
EOF
echo "Press any key - after reading above" ; read _
}
function my_banner {
printf "\n\n"
has_figlet=$(platforminfo_check_program 'figlet')
if (( $has_figlet )) ; then
figlet "$@"
else
printf "\n"
echo "$@"
printf "\n"
fi
printf "\n"
}
function gitian_builder_download() {
my_banner "Builder download"
if false ; then
printf "\n\nSKIPPING download of Gitian\n\n" # e.g. for debug of ${base_dir}/gitian-builder that you now edit there
else
echo "Downloading gitian-builder itself"
sudo rm -rf "${base_dir}/gitian-builder" || fail "remove gitian"
cd "${base_dir}" || fail "cd base dir"
git clone "$gitiansoftware_url" || fail "while downloading gitian" # confirm gitrev hash below!
cd gitian-builder || fail
git reset --hard "$gitiansoftware_checkout" || fail "Choosing gitian version (step 1)"
git clean -xdf || fail "Doing git-clean"
confirm_git_ver=$(git log --format='%H' -1)
[[ "$confirm_git_ver" == "$gitiansoftware_checkout_hash" ]] || {
fail "Git verification of hash: hash is $confirm_git_ver instead of expected $gitiansoftware_checkout_hash"
}
fi
}
function gitian_builder_make_lxc_image() {
my_banner "Make image (slow)"
echo "(from $0) Making the LXC image (with DEBOOTSTRAP_DIR=$DEBOOTSTRAP_DIR)"
cd "${base_dir}/gitian-builder/" || fail
bin/make-base-vm --lxc --arch amd64 --suite xenial || {
cat <<EOF
Can not create base VM image:
Possible problems to check:
- did you configured network for LXC? (installer should do it)
- is apt-cacher-ng running (or apt-cacher, for some system)
- if network seems to not work in LXC, then make sure you given proper access to Gitian lxc-net to allow it to use your PROPER network card. Maybe run install.sh again and give access to all network cards for lxc-net.
- More of common problems and their solutions are described in FAQ (see README.md and doc/build-gitian.md)
EOF
fail "Creating base VM failed (see above)"
}
}
function gitian_detect_source_repository() {
printf "\n%s\n" "Detecting git repository here - and URL to use in Gitian"
pushd "$my_dir" || fail "Can not cd my_dir=[$my_dir]"
gitinfo=$(git remote -v | egrep '^origin' | awk '{print$2}' | head -n 1)
echo "You have here git origin: [$gitinfo]"
[[ -z "$gitinfo" ]] && fail "Can not detect url of git here. Please get the source via git-clone and then run this script here."
ex='^http[s]*://.*$'
if [[ "$gitinfo" =~ $ex ]] ; then
echo "(origin is in https format)"
giturl="$gitinfo"
target_url="$giturl"
else
echo "(origin is in other format...)"
ex='^.*@.*$'
if [[ "$gitinfo" =~ $ex ]] ; then
echo "(origin is ssh format)"
gitinfo=$(echo "$gitinfo" | sed 's/\.git$//; s/.*://; s|/|;|') ; IFS=';' read -r -a gitpart <<< "$gitinfo" ;
# TODO take out server address instead github.com
giturl="https://github.com/${gitpart[0]}/${gitpart[1]}.git"
echo "giturl=[$giturl]"
target_url="$giturl"
gitproj="${gitpart[1]}"
if [[ "$target_name" != "$gitproj" ]] ; then
fail "Unexpected project name (from git origin) [$gitproj] instead of expected [$target_name]."
fi
else
fail "Origin is in unknown format. Do not know how to parse it. gitinfo=[$gitinfo]"
fi
fi
popd
printf "%s\n" "Detected target_url=[$target_url]"
}
function gitian_detect_source_version() {
echo "Checking git-rev of the source from which you call this script."
pushd "$my_dir" || fail "Can not cd my_dir=[$my_dir]"
printf "%s\n" "Detecting git version (revision) from PWD=$PWD."
gr=$(git log --format='%H' -1) || fail "Can not detect git version (revision) form PWD=$PWD"
target_checkout_gitrev="$gr"
printf "%s\n" "Detected and will use: target_checkout_gitrev=$target_checkout_gitrev"
popd
}
function target_download() {
my_banner "Target download"
gitian_detect_source_repository
gitian_detect_source_version
printf "\n%s\n" "Will download target to [${base_dir}] (${target_name})"
cd "${base_dir}" || fail
rm -rf "${base_dir}/${target_name}/" || fail
git clone "$target_url" || fail "Download target, target_url=[$target_url]" # confirm gitrev hash below!
cd "${base_dir}/${target_name}" || fail
printf "%s\n" "On host we start with download of (${target_name}) in version:"
PAGER=cat git log -1
git clean -xdf || fail
git checkout "$target_checkout_gitrev" || {
printf "\nYou probably should push your local version on server. Use: git branch (it shows you your actual branch)."
printf " Then use e.g.\ngit push origin Your_Actual_Branch \n"
fail "Download target in given version (step 1)"
}
confirm_git_ver=$(git log --format='%H' -1)
[[ "$confirm_git_ver" == "$target_checkout_gitrev" ]] || {
fail "Git verification of hash: hash is $confirm_git_ver instead of expected $target_checkout_gitrev"
}
git clean -xdf || fail "Doing git-clean"
PAGER=cat git log -1 || fail "Show git-version"
printf "\n\n\n"
}
function string_limitlen() {
thestr="$1" ; elipsis="-" ;
l1=3 ; l2=1 ; l3=${#elipsis} ;
if (( ${#thestr} > (l1+l2+l3) )) ; then echo "${thestr:0:l1}${elipsis}${thestr:(-l2):l2}" ; else echo "$thestr" ; fi
}
function get_host_info() {
user_s=$(string_limitlen "$USER")
hostname_s=$(string_limitlen "$HOSTNAME")
echo "$user_s@$hostname_s"
}
# IN: set $var_platform_name to eg 'windows', 'linux' or 'osx'
function gitian_show_result() {
my_banner "Results"
printf "\n\n\n%s\n" "Will show results now (base_dir=$base_dir)"
printf "%s\n" "For var_platform_name=${var_platform_name}"
cd "${base_dir}/gitian-builder" || fail "cd dir of gitian-builder" # need it to call on-target
info_gitian=$(cd "${base_dir}/gitian-builder/" ; git log -1 | head -n 1 | cut -d' ' -f2 | head -c 8) || fail "Info git gitian-builder"
info_target=$(cd "${base_dir}/${target_name}/" ; git log -1 | head -n 1 | cut -d' ' -f2 | head -c 999) || fail "Info target"
info_binary=$(on-target /home/ubuntu/build/galaxy42/contrib/tools/results-of-build-${var_platform_name}.sh) || fail "Info binary results platform=$var_platform_name"
info_binary_first=$( printf "$info_binary" | head -n 1 )
info_host="$(get_host_info)" || fail "Info host"
# info_target_yml=$( python3 ${my_dir}/contrib/gitian-tools/get_version_from_yaml.py "$gitian_yml_file_full" | cut -d' ' -f1 | head -c 8 )
target_in_gitian_gitrev=$( on-target /home/ubuntu/build/galaxy42/contrib/tools/my-gitian-gitrev.sh ) || fail "Info on-target gitian rev"
info_target_commit="${target_in_gitian_gitrev}"
info_target_commit_name="${info_target_commit}"
if [[ "$info_target_commit_name" == "$info_target" ]] ; then info_target_commit_name="same-hash" ; fi
echo "Script ${info_thisscript} using Gitian ($info_gitian) of $target_name $info_target ($info_target_commit_name) for $var_platform_name gives $info_binary_first on $info_host"
echo "Report (received from inside Gitian):"
echo "$info_binary"
}
# IN: set $var_platform_name to eg 'windows', 'linux' or 'osx'
function gitian_run_build_once() {
my_banner "Building ($var_platform_name)"
[[ -z "${var_platform_name}" ]] && fail "Internal error: set platform name for gitian_run_build_once"
gitian_yml_file="main-build/galaxy-${var_platform_name}.yml" # must be under contrib/gitian-descriptors/
gitian_yml_file_full="$my_dir/contrib/gitian-descriptors/${gitian_yml_file}"
printf "\n\n\n\n\n\n"
printf "The Gitian build, for platform=$var_platform_name, for YML file: $gitian_yml_file_full"
printf "\n\n\n\n\n\n"
gitian_detect_source_repository
gitian_detect_source_version
cd "$base_dir/gitian-builder/" || fail
# MAC OSX - sdk check
if (( option_platform_osx )) ; then
if [[ -r "$dir_base_of_source/contrib/macdeploy/MacOSX10.11.sdk.tar.gz" ]] ; then
mkdir -p inputs
cp "$dir_base_of_source/contrib/macdeploy/MacOSX10.11.sdk.tar.gz" inputs || fail "Fail to copy MacOSX10.11.sdk.tar.gz to gitian-builder/inputs dir"
else
fail "Cannot build for OSX, SDK does not exist. $dir_base_of_source/contrib/macdeploy should contain 'MacOSX10.11.sdk.tar.gz'.\n" \
"Read instruction in $dir_base_of_source/contrib/macdeploy/README_osx.md"
fi
fi
printf "\nWill use YML Gitian file: $gitian_yml_file_full\n\n"
cat "$gitian_yml_file_full" | egrep -H -n -i "commit|url|dir"
printf "\n\n"
printf "%s\n" "Gitian for commit ${target_checkout_gitrev}, from url ${target_url}"
set -x
./bin/gbuild \
--commit galaxy42="${target_checkout_gitrev}" \
--url galaxy42="${target_url}" \
--allow-sudo \
"$gitian_yml_file_full" \
|| {
set +x
fail "Build with gbuild. See file [$base_dir/gitian-builder/var/build.log] for details of the error inside Gitian."
}
set +x
printf "\n\nBuild with gbuild - done - for platform=$var_platform_name\n\n"
gitian_show_result
printf "\n\n\n"
}
function print_no_platform() {
printf "\nNo known platform was selected (run program with -h to see options, e.g. -W -L).\n"
}
function gitian_run_build_all_platforms() {
my_banner "Building selected platforms"
any=0
# this would allow to run -W, -L and -M in one program call. Not sure if that is 100% supported,
if (( option_platform_windows )) ; then
any=1
var_platform_name='windows'
gitian_run_build_once
fi
if (( option_platform_linux )) ; then
any=1
var_platform_name='linux'
gitian_run_build_once
fi
if (( option_platform_osx )) ; then
any=1
var_platform_name='osx'
gitian_run_build_once
fi
if (( ! any )) ; then print_no_platform ; fi
}
info_host=$(get_host_info)
echo "Running on host (shortcut name): $info_host"
function gitian_config_specific_platforms() {
# setting devices for ubuntu <= 14
if [[ "${platforminfo[distro]}" == "ubuntu" ]]; then
# get ubuntu main version e.g. "14" from "ubuntu_14.04"
ubuntu_ver=$( echo "${platforminfo[only_verid]}" | cut -d'.' -f1)
# if ubuntu main version is older/equal than 14
if (( $ubuntu_ver <= 14 )); then
echo "In order to avoid connetion issues inside lxc machine on ubuntu <= 14"
echo "It seems reswitch lxcbr0 device is needed:"
run_with_root_privilages ifconfig lxcbr0 down
run_with_root_privilages ifconfig lxcbr0 up
fi
fi
}
function check_options_platform() {
if (( ! ( option_platform_windows || option_platform_linux || option_platform_osx ) )) ; then
print_no_platform
exit 1
fi
}
function special_command_on_target() {
set_env
gitian_config_specific_platforms
printf "Starting a console on the Image of for-Gitian system. PATH=$PATH\n"
cd "${base_dir}/gitian-builder" || fail "cd dir of gitian-builde"
echo "PWD=$PWD"
set -x
on-target "$@"
set +x
printf "Exited from Image\n"
}
function run_script_on_target() {
user_or_root="$1"
script_file_main_name="$2"
script_file="${my_dir}/${script_file_main_name}"
printf "\nWill execute on-target a script [${script_file}] (user/root: $user_or_root)\n\n"
if [[ "$user_or_root" == 'root' ]] ; then
special_command_on_target -u root < ${script_file} || {
fail "Execute on-target script=[$script_file] (user/root: $user_or_root)"
}
else
special_command_on_target < ${script_file} || {
fail "Execute on-target script=[$script_file] (user/root: $user_or_root)"
}
fi
printf "Script on-target done.\n\n"
}
function gitian_my_cfg_on_target() {
my_banner "Gitian on-target config"
printf "\nApplying my gitian config on target\n\n"
run_script_on_target 'user' 'contrib/gitian-tools/on-target-cfg-settings.sh'
run_script_on_target 'root' 'contrib/gitian-tools/on-target-cfg-settings.sh'
run_script_on_target 'root' 'contrib/gitian-tools/on-target-cfg-root.sh'
}
function prepare_build_sdk() {
if (( option_platform_osx )) ; then
sdkfile="${dir_base_of_source}/contrib/macdeploy/MacOSX10.11.sdk.tar.gz"
[ -r "$sdkfile" ] || fail "You need to provide file $sdkfile (PWD=$PWD). Read instruction in $dir_base_of_source/contrib/macdeploy/README_osx.md"
fi
}
function all_including_new_lxc() {
check_options_platform
prepare_build_sdk
set_env
fix_template_script
gitian_builder_download
gitian_check_net_devices "loud"
gitian_config_specific_platforms
gitian_builder_make_lxc_image
gitian_my_cfg_on_target
target_download
gitian_run_build_all_platforms "$@"
}
function all_excluding_new_lxc() {
check_options_platform
prepare_build_sdk
set_env
fix_template_script
gitian_check_net_devices "loud"
gitian_config_specific_platforms
# gitian_my_cfg_on_target
target_download
gitian_run_build_all_platforms "$@"
}
function run_onlyresult() {
check_options_platform
set_env
gitian_check_net_devices "loud"
# this would allow to run -W, -L and -M in one program call. Not sure if that is 100% supported,
if (( option_platform_windows )) ; then
any=1
var_platform_name='windows'
printf "\n\n%s\n" "v---- only showing previous results!!!"
gitian_show_result
printf "\n%s\n" "Above is ONLY the result (we did NOT run here the build process, just showing results of previous builds)"
fi
if (( option_platform_linux )) ; then
any=1
var_platform_name='linux'
printf "\n\n%s\n" "v---- only showing previous results!!!"
gitian_show_result
printf "\n%s\n" "Above is ONLY the result (we did NOT run here the build process, just showing results of previous builds)"
fi
if (( option_platform_osx )) ; then
any=1
var_platform_name='osx'
printf "\n\n%s\n" "v---- only showing previous results!!!"
gitian_show_result
printf "\n%s\n" "Above is ONLY the result (we did NOT run here the build process, just showing results of previous builds)"
fi
}
function run_with_root_privilages_fix() {
# TODO ask user to confirm?
info="$1" ; shift
run_with_root_privilages "$@" || fail "Can not run the fix for problem."
}
function my_set_mountflags() {
dir="$1"
good="$2"
bad="$3"
platforminfo_set_mountflags verbose "$dir" fix "$good" "$bad" || {
mount_check_result=$?
if (( $mount_check_result == 1 )) ; then
printf "%s\n" "Mount needs to be adjusted: ${g42utils_resulting_mount_args[*]}."
run_with_root_privilages_fix "$(gettext 'L_fix_mount_flags')" 'mount' "${g42utils_resulting_mount_args[@]}"
else
fail "Problems when checking mount flags."
fi
}
}
my_set_mountflags "${base_dir}" "" "nodev,noexec"
midutils_detect_correct_apt_cacher_version
printf "\n\n%s\n\n" "Apt-cacher that should be used is detected as: ${midutils_apt_cacher_version_name_service}."
run_with_root_privilages "service" "$midutils_apt_cacher_version_name_service" "restart" || \
fail "Restarting apt-cacher (version: ${midutils_apt_cacher_version_name_service}."
# start main:
main_run_action