forked from fsfw-dresden/usb-live-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-live-iso
executable file
·110 lines (86 loc) · 3.81 KB
/
build-live-iso
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
#!/bin/bash
. "$(dirname $(realpath "${0}"))/functions.sh"
. "$(dirname $(realpath "${0}"))/functions.bash"
cd_repo_root
# let failures in pipe fail the whole pipe
set -o pipefail
# turn on extended globbing for !(pattern-list)
shopt -s extglob
case "${1}" in
# debug mode
"-D")
;&
"--debug")
shift; set -x; trap "set +x" EXIT SIGHUP SIGQUIT SIGTERM
;;
# give some rudimentary help if requested
"-h")
;&
"--help")
print_info "usage is [--debug] ${0} [BUILD_VARIANT]"
print_info "If given, BUILD_VARIANT must match a sub-folder or symlink in variants.build/"
exit
;;
esac
select_build_variant() {
OPTIONS=()
for VARIANT in $(command ls -Ltd variants.build/!(active|base_*|shared)/)
do
NUMFILES=$(find "${VARIANT}" -type f -printf x | wc -c)
# THANKS https://stackoverflow.com/questions/4561895/how-to-recursively-find-the-latest-modified-file-in-a-directory
NEWESTFILE=$(find ${VARIANT} -type f -printf '%T@ %p\n'|sort -n|tail -n 1|cut -d" " -f2-)
[ -z "${NEWESTFILE}" ] && CHANGESTR="" || CHANGESTR=", last changed $(rel_fmt_low_precision $(stat --format='@%Y' "${NEWESTFILE}"))"
OPTIONS+=(${VARIANT#variants.build/} "(${NUMFILES} files${CHANGESTR})")
done
TEXT="Please choose the variant to build. (Build Variants named base_* or shared are not listed)"
TITLE="SELECT LIVE SYSTEM BUILD VARIANT"
display_menu "${TITLE}" "${TEXT}" "${OPTIONS[@]}"
}
print_time_used() {
print_info "this took $(format_timespan $(($(date +%s) - STARTTIME))) (+ the work of many)" 2> >(tee --append "${LOGFILE}")
}
build_main() {
# if a BUILD_VARIANT is given as parameter, prefer that
[ -n "${1}" ] && BUILD_VARIANT=${1}
# if not given, query user to visually select a variant
[ -n "${BUILD_VARIANT}" ] || BUILD_VARIANT=$(select_build_variant)
[ -z "${BUILD_VARIANT}" ] && die "no BUILD_VARIANT selected. #saaad.."
# chop off possible trailing slash and expose variable to sub processes
export BUILD_VARIANT=${BUILD_VARIANT%/}
# ensure the directory exists
[ -d "variants.build/${BUILD_VARIANT}" ] || die "given BUILD_VARIANT=${BUILD_VARIANT} does not exist"
print_info "Live-Stick Build Variant chosen: ${BUILD_VARIANT}\n"
print_info "Available live-build versions:"
apt policy live-build
[ -n "${LIVE_BUILD}" ] && print_warn "LIVE_BUILD variable is set\nlive-build scripts and functions will be invoked from ${LIVE_BUILD}"
print_info "Using live-build $(lb --version), lb command is $(type lb)"
# build in an appropriate sub-folder
cd build
# clean up live-build environment using auto/clean script
print_info "Triggering build area clean-up.."
lb clean --color
# generate live-build config/ from features of specified variant
print_info "Collecting build features for ${BUILD_VARIANT}.."
transmogrify_features ../variants.build/${BUILD_VARIANT}
# have live-build complete its config
print_info "Let live-build finalize its configuration"
lb config --color
# Trigger image build
print_info "Firing build process, fasten seatbelts.. it is $(date '+%F %H:%M') now."
lb build --color &&
{
print_success "Building ISO SUCCEEDED"
# Ensure artifacts dir exists
mkdir -p ../artifacts
# and move generated files there
LB_IMAGE_NAME=$(get_image_name)
mv -iv ${LB_IMAGE_NAME}*.* ../artifacts/
} || die "lb build FAILED for ${BUILD_VARIANT}, check ${LOGFILE}"
}
is_root_user_or_die
LOGFILE="build/build-live-iso.$(date '+%F.%H%Mh').log"
# Measure time and print when exiting
STARTTIME=$(date +%s)
trap "print_time_used" EXIT SIGHUP SIGQUIT SIGTERM
# Filter build log from apt's complaints about outdated packages in cache
build_main "${@}" |& tee >(sed '/^Del /d' > "${LOGFILE}")