-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgeniso
executable file
·78 lines (68 loc) · 1.65 KB
/
geniso
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
#!/usr/bin/env bash
message() {
echo -e "\n######################################################################"
echo "# $1"
echo "######################################################################"
}
need() {
which "$1" &>/dev/null || die "Binary '$1' is missing but required."
}
usage() {
cat << EOF
usage: geniso COMMAND [NODE]
Commands:
generate Generate an ISO by providing a node
list List available nodes to be built
Examples:
geniso GENERATE node-1
geniso list
EOF
}
list() {
echo -e "The following node files are detected:\n"
ls -1 nodes | grep -v network-config
}
generate() {
NODE="$1"
if [ -f "nodes/$NODE" ]
then
echo "Node $NODE found."
else
echo "Node not found, available nodes below."
list
exit 1
fi
export REPO_ROOT=$(git rev-parse --show-toplevel)
. "$REPO_ROOT"/.env
message "Creating k3s-seed ISO for $NODE."
echo "Touching meta-data file."
touch meta-data
echo "Populating variables to temporary user-data file."
envsubst < "nodes/${NODE}" > "user-data"
echo "Running cloud-localds for your node."
if [ -f "nodes/$NODE.network-config" ]; then
envsubst < "nodes/${NODE}.network-config" > "network-config"
cloud-localds k3s-seed-$NODE.iso --network-config=network-config user-data meta-data
else
cloud-localds k3s-seed-$NODE.iso user-data meta-data
fi
rm user-data
rm meta-data
rm network-config
echo "Copying seed ISO to Proxmox"
scp k3s-seed-$NODE.iso root@${PROXMOX_SERVER}:/var/lib/vz/template/iso/
}
case "$1" in
generate)
need "scp"
need "envsubst"
need "cloud-localds"
generate $2
;;
list)
list
;;
*)
usage
;;
esac