59 lines
2.6 KiB
Bash
59 lines
2.6 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
#
|
||
|
|
# signage module update — a bare Debian VM (scaffold).
|
||
|
|
#
|
||
|
|
# The VM is created by the cluster:vm provider (Debian 13 cloud image) and
|
||
|
|
# OS-prepped by templates:debian. This module currently only confirms the VM is
|
||
|
|
# up and records a version marker — the signage software will be layered on in a
|
||
|
|
# later pass. install == update for this module.
|
||
|
|
#
|
||
|
|
# Runs on tappaas-cicd: resolves the VM's IP via the Proxmox guest agent, then
|
||
|
|
# drives the VM over SSH. Idempotent.
|
||
|
|
#
|
||
|
|
# Usage: update.sh <module-name>
|
||
|
|
#
|
||
|
|
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
. /home/tappaas/bin/common-install-routines.sh
|
||
|
|
|
||
|
|
MODULE="${1:-signage}"
|
||
|
|
readonly MGMT="mgmt"
|
||
|
|
readonly MARKER="/etc/tappaas-signage.version" # on the VM: module version we applied
|
||
|
|
|
||
|
|
VMNAME="$(get_config_value 'vmname' "${MODULE}")"
|
||
|
|
VMID="$(get_config_value 'vmid')"
|
||
|
|
VERSION="$(get_config_value 'version' '0.0.1')"
|
||
|
|
[[ -n "${VMID}" && "${VMID}" != "null" ]] || die "no vmid for ${MODULE}"
|
||
|
|
|
||
|
|
# ── Locate the node hosting the VM (HA-safe) and resolve its IP ───────
|
||
|
|
PRIMARY="$(get_primary_node_fqdn 2>/dev/null || echo "tappaas1.${MGMT}.internal")"
|
||
|
|
NODE="$(ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new "root@${PRIMARY}" \
|
||
|
|
"pvesh get /cluster/resources --type vm --output-format json 2>/dev/null" \
|
||
|
|
| jq -r --arg v "${VMID}" '.[] | select(.vmid==($v|tonumber)) | .node' 2>/dev/null | head -1)"
|
||
|
|
[[ -n "${NODE}" ]] || NODE="$(get_config_value 'node' "$(get_node_hostname 0)")"
|
||
|
|
[[ -n "${NODE}" ]] || die "could not locate the node hosting VM ${VMID}"
|
||
|
|
|
||
|
|
get_vm_ip() {
|
||
|
|
ssh -o BatchMode=yes "root@${NODE}.${MGMT}.internal" \
|
||
|
|
"qm guest cmd ${VMID} network-get-interfaces" 2>/dev/null \
|
||
|
|
| jq -r '.[] | select(.name | test("^lo$") | not) | ."ip-addresses"[]? | select(."ip-address-type"=="ipv4") | ."ip-address"' 2>/dev/null \
|
||
|
|
| grep -v '^127\.' | head -1
|
||
|
|
}
|
||
|
|
|
||
|
|
info "${BOLD}Updating signage${CL} on ${VMNAME} (VM ${VMID}, node ${NODE})"
|
||
|
|
|
||
|
|
IP=""
|
||
|
|
for _ in $(seq 1 18); do IP="$(get_vm_ip)"; [[ -n "${IP}" ]] && break; sleep 10; done
|
||
|
|
[[ -n "${IP}" ]] || die "could not resolve an IPv4 for VM ${VMID} via the guest agent"
|
||
|
|
info " VM IP: ${IP}"
|
||
|
|
|
||
|
|
vm() { ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o ConnectTimeout=10 "tappaas@${IP}" "$@"; }
|
||
|
|
|
||
|
|
# Confirm SSH is up and record the version marker. Nothing else to install yet —
|
||
|
|
# this is a bare Debian scaffold; the signage service comes in a later pass.
|
||
|
|
vm "true" || die "VM ${VMNAME} (${IP}) not reachable over SSH"
|
||
|
|
vm "echo '${VERSION}' | sudo tee ${MARKER} >/dev/null" || warn "could not write version marker"
|
||
|
|
|
||
|
|
info " ${GN}✓${CL} signage VM is up (bare Debian scaffold — no service installed yet)"
|