-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm-build-helper
executable file
·113 lines (101 loc) · 4.33 KB
/
vm-build-helper
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
#!/usr/bin/env bash
#
# Template VM Image Builder
# Copyright (C) 2017-2025 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Contact: [email protected]
set -e
. ./directories.config
# ###### Handle command-line parameters #####################################
if [ ! -e "${OUTPUT_DIRECTORY}" ] ; then
echo >&2 "ERROR: Output directory ${OUTPUT_DIRECTORY} does not exist!"
exit 1
fi
mkdir -p "${CACHE_DIRECTORY}" || true
if [ ! -e "${CACHE_DIRECTORY}" ] ; then
echo >&2 "ERROR: Cache directory ${CACHE_DIRECTORY} does not exist!"
exit 1
fi
# ###### Build VMs ##########################################################
build-defined-vms ()
{
local delay="$1"
if [[ ! "${delay}" =~ ^[0-9]+$ ]] ; then
delay=0
fi
isFirst=1
for project in ${PROJECTS} ; do
for system in ${SYSTEMS} ; do
# shellcheck disable=SC2001
distribution=$(echo "${system}" | sed -e "s/-.*$//g")
# shellcheck disable=SC2001
release=$(echo "${system}" | sed -e "s/^[^\-]*-//g")
# ====== Filter out unsupported combinations =======================
if [ "${project}" == "NorNet" ] && [ "${distribution}" == "Debian" ] ||
[ "${project}" == "NorNet-Desktop" ] && [ "${distribution}" == "Debian" ] ; then
echo "${project}/${distribution}-${release} is not supported (yet)"
continue
fi
# ====== Build VM ==================================================
name="${HYPERVISOR}-${project}-${distribution}-${release}"
logfile="${OUTPUT_DIRECTORY}/${name}/${name}.log"
if [ ! -e "${OUTPUT_DIRECTORY}/${name}/successfully-built.txt" ] ; then
if [ "${isFirst}" -eq 0 ] ; then
if [ "${delay}" -gt 0 ] ; then
echo -e "\x1b[37mWaiting for ${delay} s ...\x1b[0m"
sleep ${delay}
fi
fi
isFirst=0
startTime=$(date)
echo -e "\x1b[33m${startTime}: Starting to build ${name}, logfile is ${logfile} ...\x1b[0m"
mkdir -p "${OUTPUT_DIRECTORY}/${name}"
(
# shellcheck disable=SC2086
if ./make-vm -H "${HYPERVISOR}" \
--project "${project}" --distribution "${distribution}" --release "${release}" \
--hostname "${HOSTNAME}" \
--username "${USER_NAME}" --realname "${USER_REALNAME}" --password "${USER_PASSWORD}" \
--chipset "${CHIPSET}" \
--firmware "${FIRMWARE}" \
--cores "${CORES}" --memory "${MEMORY}" --balloon "${BALLOON}" \
--root "${DISK_ROOT}" --home "${DISK_HOME}" --swap "${DISK_SWAP}" \
--video "${VIDEO}" \
--bootsplash "${BOOTSPLASH}" \
--background-sddm "${BACKGROUND_SDDM}" \
--background-lockscreen "${BACKGROUND_LOCKSCREEN}" \
--background-desktop "${BACKGROUND_DESKTOP}" \
--cache-directory "${CACHE_DIRECTORY}" \
--output-directory "${OUTPUT_DIRECTORY}" \
${OPTIONS} >"${logfile}" 2>&1 ; then
result="OK"
resultColor="32"
else
result="FAILED!"
resultColor="37;41;97"
fi
finishTime=$(date)
echo -e "\x1b[${resultColor}m${finishTime}: Finished to build ${name} - ${result} -> ${logfile}\x1b[0m"
) &
else
echo -e "\x1b[34m${name} is already there -> ${logfile}\x1b[0m"
fi
done
done
# ====== Wait for completion of all parallel builds ======================
wait
reset -I
}