-
Notifications
You must be signed in to change notification settings - Fork 7
/
build_iso.sh
executable file
·184 lines (156 loc) · 6.5 KB
/
build_iso.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
#!/bin/bash
wd=$(dirname "$0")
output_dir=.
# test if "docker compose" works
docker compose >/dev/null 2>&1
returncode=$?
if [ $returncode -eq 0 ]; then
COMPOSECMD="docker compose"
else
COMPOSECMD="docker-compose"
fi
echo "We are going to use $COMPOSECMD"
rm -f $output_dir/seapath.iso
# removing the volume in case it exists from a precedent build operation
docker rm -f fai-setup 2>/dev/null
docker volume rm build_debian_iso_ext 2>/dev/null
set -ex
if [ ! -f "$wd"/etc_fai/grub.cfg ]; then
cp "$wd"/etc_fai/grub_base.cfg "$wd"/etc_fai/grub.cfg
fi
find "$wd"/build_tmp/ ! -name .gitkeep -type f -exec rm -f {} +
cp -r "$wd/srv_fai_config/"* "$wd/build_tmp"
cp -r "$wd/usercustomization/"* "$wd/build_tmp"
finalClasses="SEAPATH_CLUSTER,SEAPATH_DBG,SEAPATH_KERBEROS,SEAPATH_COCKPIT,"
if [ "$1" == "--custom" ]; then
cp "$wd"/etc_fai/grub_base.cfg "$wd"/etc_fai/grub.cfg
# add index to an array, for each value
function addIndexToArray1 {
local -n myarray=$1
for idx in $(seq 1 ${#myarray[@]}); do
arrVar+=("$idx"")")
arrVar+=("${myarray[$((idx-1))]}")
done
}
# add index to an array, every 2 values
function addIndexToArray2 {
local -n myarray=$1
for idx in $(seq 1 $((${#myarray[@]}/2))); do
arrVar+=("$idx"")")
arrVar+=("${myarray[$((idx*2-2))]}")
arrVar+=("${myarray[$((idx*2-1))]}")
done
}
listClasses=("SEAPATH_CLUSTER" "ON" "SEAPATH_DBG" "ON" "SEAPATH_COCKPIT" "ON" "SEAPATH_KERBEROS" "ON")
arrVar=()
addIndexToArray2 listClasses
CHOICES=$(whiptail --separate-output --checklist "Choose package classes to add to iso" 18 60 7 \
"${arrVar[@]}" 3>&1 1>&2 2>&3)
finalClasses=""
for CHOICE in $CHOICES; do
c=${CHOICE//)/}
c=$(((c-1)*2))
finalClasses="$finalClasses""${listClasses[$c]}"","
done
addFlagCombination() {
listFlags=("french" "FRENCH keyboard rather than english" "OFF" "german" "GERMAN keyboard rather than english" "OFF" "dbg" "DEBUG packages" "OFF" "raid" "lvm RAID" "ON" "cockpit" "COCKPIT packages" "OFF" "kerberos" "KERBEROS packages" "OFF" "cluster" "CLUSTER rather than standalone" "ON")
arrVar=()
if CHOICES=$(whiptail --separate-output --checklist "Choose flags combination to add to grub" 18 60 7 "${listFlags[@]}" 3>&1 1>&2 2>&3); then
# code 0
finalFlags=""
if [ -z "$CHOICES" ]; then
finalFlags="noflag"
else
for CHOICE in $CHOICES; do
finalFlags="$finalFlags""${CHOICE}"","
done
finalFlags=${finalFlags::-1}
fi
menuItems+=("$finalFlags")
fi
}
menuItems=()
while true
do
menuItemsStr=""
for menuItem in "${menuItems[@]}"; do
menuItemsStr="$menuItemsStr\n""$menuItem"
done
whiptail --msgbox "this is the list of grub menu entries:\n$menuItemsStr\n" 20 100
CHOICE=$(
whiptail --title "grub menu" --cancel-button "exit" --menu "Make your choice:" 22 100 14 \
"1)" "add grub entry (flag combinaison)" \
"2)" "continue" \
3>&2 2>&1 1>&3
)
[[ "$?" = 1 ]] && break
case $CHOICE in
"1)") addFlagCombination
;;
"2)") break
;;
esac
done
if [ ${#menuItems[@]} -gt 0 ]; then
# if user has defined grub items, make him choose a default one
CHOICE=$(
addIndexToArray1 menuItems
whiptail --title "choose default grub item" --cancel-button "exit" --menu "choose default grub entry:" 22 100 14 \
"${arrVar[@]}" \
3>&2 2>&1 1>&3
)
[[ "$?" = 1 ]] && exit
c=${CHOICE//)/}
echo "set default=\" SEAPATH installation - ${menuItems[$((c-1))]}\"" > /tmp/seapathlistfai.txt
echo "set timeout=5" >> /tmp/seapathlistfai.txt
for menuItem in "${menuItems[@]}"; do
entry="menuentry \" SEAPATH installation - $menuItem\" {
search --set=root --file /FAI-CD
linux /boot/vmlinuz FAI_FLAGS=\"$menuItem,verbose,sshd,createvt,reboot\" FAI_ACTION=install FAI_CONFIG_SRC=file:///var/lib/fai/config rd.live.image root=live:CDLABEL=FAI_CD ipv6.disable=1
initrd /boot/initrd.img
}"
echo "$entry" >> /tmp/seapathlistfai.txt
done
sed -i -ne '/## BEGIN CUSTOM MENU ITEMS/ {p; r /tmp/seapathlistfai.txt' -e ':a; n; /## END CUSTOM MENU ITEMS/ {p; b}; ba}; p' "$wd"/etc_fai/grub.cfg
rm -f /tmp/seapathlistfai.txt
fi
fi
# Creating the NFSROOT
# Removing *.profile since we don't use them
# Removing 50-host-classes to prevent DEMO and FAIBASE to be added to the list of classes
# Adding the Bookworm basefiles to that we deploy a Debian v12 distro
# Patches /sbin/install_packages (bug in the process of being corrected upstream)
$COMPOSECMD -f "$wd"/docker-compose.yml run --rm fai-setup bash -c "\
echo \"fai-setup -v -e -f \" && \
fai-setup -v -e -f && \
echo \"rm -f /ext/srv/fai/config/class/50-host-classes\" && \
rm -f /ext/srv/fai/config/class/50-host-classes && \
echo \"rm -f /ext/srv/fai/config/class/*.profile\" && \
rm -f /ext/srv/fai/config/class/*.profile && \
echo \"SED\" && \
sed -i -e \"s|-f \\\"\\\$FAI_ROOT/usr/sbin/apt-cache|-f \\\"\\\$FAI_ROOT/usr/bin/apt-cache|\" /ext/nfsroot/sbin/install_packages && \
sed -i -e \"s/ --allow-change-held-packages//\" /ext/nfsroot/sbin/install_packages && \
echo \"wget -O /ext/srv/fai/config/basefiles/BOOKWORM64.tar.xz https://fai-project.org/download/basefiles/BOOKWORM64.tar.xz\" && \
wget -O /ext/srv/fai/config/basefiles/BOOKWORM64.tar.xz https://fai-project.org/download/basefiles/BOOKWORM64.tar.xz"
# Starting the container to add stuff in it
$COMPOSECMD -f "$wd"/docker-compose.yml up --no-start fai-setup
# Adding the SEAPATH workspace
docker cp "$wd"/build_tmp/. fai-setup:/ext/srv/fai/config/
# Stopping the container after having added stuff in it
$COMPOSECMD -f "$wd"/docker-compose.yml down
# List user defined Classes
userClasses=$(grep -Ev "^#|^$" "$wd"/user_classes.conf | tr '\n' ',' | sed -e "s/,$//")
# Creating the mirror
CLASSES="FAIBASE,DEBIAN,GRUB_EFI,SEAPATH_COMMON,SEAPATH_HOST,${finalClasses}USERCUSTOMIZATION,${userClasses},LAST"
$COMPOSECMD -f "$wd"/docker-compose.yml run --rm fai-setup bash -c "\
cp /etc/fai/apt/keys/* /etc/apt/trusted.gpg.d/ &&\
fai-mirror -c $CLASSES /ext/mirror"
# Creating the ISO
$COMPOSECMD -f "$wd"/docker-compose.yml run --rm fai-cd fai-cd -f -m /ext/mirror /ext/seapath.iso
# Retrieving the ISO from the volume
$COMPOSECMD -f "$wd"/docker-compose.yml up --no-start fai-setup
docker cp fai-setup:/ext/seapath.iso $output_dir/
$COMPOSECMD -f "$wd"/docker-compose.yml down --remove-orphans
# Removing the volume
docker volume rm build_debian_iso_ext
rm -rf "$wd"/build_tmp/*