platforms/qemu and platforms/proxmox each have their own lab.sh and lab.conf; content/ holds everything shared (roles, seed, site, helpers). The dispatcher, preflight and command implementations are common and take platform differences from the backend. Proxmox backend: qm create with q35/SATA/e1000, ISOs and seed ISOs in an ISO storage, provisioning over qm guest exec (no Python packages needed on the host), template + clone for reset, and peers/ to emit WireGuard configs. The role scripts now ride on the seed ISO, so provisioning transfers nothing. build-bundle.sh produces a self-contained tarball per platform, for hosts that cannot reach the git server. Both configs are generic: no absolute path from this machine remains.
76 lines
2.6 KiB
Bash
76 lines
2.6 KiB
Bash
# shellcheck shell=bash
|
|
# cmd_seeds — render one unattend + payload per VM and pack a seed ISO.
|
|
# Nothing here needs root or a downloaded ISO; it is pure file assembly.
|
|
|
|
cmd_seeds() {
|
|
local tmpl="$CONTENT_DIR/seed/Autounattend.xml.tmpl"
|
|
local payload="$CONTENT_DIR/seed/payload"
|
|
|
|
[[ -r $tmpl ]] || die "missing template: $tmpl"
|
|
[[ -d $payload ]] || die "missing payload dir: $payload"
|
|
have_cmd genisoimage || have_cmd xorriso || die "genisoimage or xorriso is required"
|
|
: "${LAB_ADMIN_PASSWORD:?LAB_ADMIN_PASSWORD is not set in lab.conf}"
|
|
|
|
mkdir -p "$SEED_DIR"
|
|
|
|
local i name ip role work iso volid dns
|
|
for i in "${!VM_NAMES[@]}"; do
|
|
name=${VM_NAMES[$i]}
|
|
ip=${VM_IPS[$i]}
|
|
role=${VM_ROLES[$i]}
|
|
dns=$LAB_DC_IP # every lab VM resolves through the DC
|
|
|
|
work="$SEED_DIR/$name"
|
|
rm -rf "$work"
|
|
mkdir -p "$work/norbourg/roles"
|
|
|
|
sed -e "s|@@HOSTNAME@@|${name}|g" \
|
|
-e "s|@@ADMIN_PASSWORD@@|${LAB_ADMIN_PASSWORD}|g" \
|
|
-e "s|@@IMAGE_INDEX@@|${WINDOWS_IMAGE_INDEX:-2}|g" \
|
|
"$tmpl" > "$work/Autounattend.xml"
|
|
|
|
cp "$payload/bootstrap.cmd" "$work/norbourg/"
|
|
cp "$payload/bootstrap.ps1" "$work/norbourg/"
|
|
|
|
# Ship the role scripts on the ISO so the guest never needs a file
|
|
# transfer: bootstrap copies this tree to C:\norbourg and runs from there.
|
|
mkdir -p "$work/norbourg/lib" "$work/norbourg/roles"
|
|
cp "$CONTENT_DIR/windows/lib/common.ps1" "$work/norbourg/lib/"
|
|
render_role "$CONTENT_DIR/windows/roles/${role}.ps1" "$work/norbourg/roles/${role}.ps1"
|
|
if [[ -f $CONTENT_DIR/windows/roles/${role}-post.ps1 ]]; then
|
|
render_role "$CONTENT_DIR/windows/roles/${role}-post.ps1" "$work/norbourg/roles/${role}-post.ps1"
|
|
fi
|
|
|
|
cat > "$work/norbourg/config.ps1" <<EOF
|
|
\$Config = @{
|
|
Hostname = '${name}'
|
|
IP = '${ip}'
|
|
Prefix = ${LAB_NETMASK}
|
|
Gateway = '${LAB_GATEWAY}'
|
|
DNS = '${dns}'
|
|
Role = '${role}'
|
|
Domain = '${DOMAIN}'
|
|
}
|
|
EOF
|
|
|
|
# A malformed answer file means a 20-minute silent install failure; catch it here.
|
|
python3 - "$work/Autounattend.xml" <<'PY' || die "rendered answer file is not valid XML for ${name}"
|
|
import sys, xml.etree.ElementTree as ET
|
|
ET.parse(sys.argv[1])
|
|
PY
|
|
|
|
iso="$SEED_DIR/${name}-seed.iso"
|
|
volid="NRBG_${name^^}"
|
|
if have_cmd genisoimage; then
|
|
genisoimage -quiet -volid "$volid" -J -R -o "$iso" "$work"
|
|
else
|
|
xorriso -as mkisofs -quiet -V "$volid" -J -R -o "$iso" "$work"
|
|
fi
|
|
|
|
ok "$(printf '%-6s %-14s %-4s %s' "$name" "$ip" "$role" "$iso")"
|
|
done
|
|
|
|
printf '\n'
|
|
ok "${#VM_NAMES[@]} seed ISO(s) in ${SEED_DIR}"
|
|
}
|