fix(build): rename HOSTNAME -> CT_HOSTNAME (shadowed bash builtin), add VLAN_TAG prompt, fail fast on network timeout

HOSTNAME is a bash built-in always containing the host's name, so the
"-z HOSTNAME" check never fired and the prompt was silently skipped —
containers ended up named after the Proxmox host.

Also added an optional VLAN tag prompt (empty = no tag), and the network
wait loop now exits with an error if the network never comes up instead
of silently proceeding to a guaranteed-broken apt-get update.
This commit is contained in:
2026-05-21 23:32:12 +02:00
parent 7343501b25
commit b93ec8b553
+20 -8
View File
@@ -11,6 +11,9 @@
# and may override the DEFAULT_* values below.
#
# Caller may define print_app_summary() to customize the trailing summary.
#
# NB: We use CT_HOSTNAME (not HOSTNAME) because HOSTNAME is a bash built-in
# that always holds the current host's name, which would defeat any prompt.
# ── colors / logging ─────────────────────────────────────────────────────────
if [[ -z "${_COLORS_LOADED:-}" ]]; then
@@ -61,6 +64,8 @@ show_header() {
# ── prompts ──────────────────────────────────────────────────────────────────
# Each prompt is skipped if the corresponding variable is already set in env.
# VLAN_TAG uses ${VLAN_TAG+x} so that explicitly setting it to "" via env
# skips the prompt (= "no VLAN, don't ask").
prompt_lxc_config() {
if [[ -z "${CTID:-}" ]]; then
read -rp "Container ID [auto]: " CTID
@@ -68,9 +73,9 @@ prompt_lxc_config() {
fi
echo " → CTID: $CTID"
if [[ -z "${HOSTNAME:-}" ]]; then
read -rp "Hostname [$DEFAULT_HOSTNAME]: " HOSTNAME
HOSTNAME="${HOSTNAME:-$DEFAULT_HOSTNAME}"
if [[ -z "${CT_HOSTNAME:-}" ]]; then
read -rp "Hostname [$DEFAULT_HOSTNAME]: " CT_HOSTNAME
CT_HOSTNAME="${CT_HOSTNAME:-$DEFAULT_HOSTNAME}"
fi
if [[ -z "${DISK_SIZE:-}" ]]; then
read -rp "Disk size in GB [$DEFAULT_DISK]: " DISK_SIZE
@@ -88,6 +93,9 @@ prompt_lxc_config() {
read -rp "Bridge [$DEFAULT_BRIDGE]: " BRIDGE
BRIDGE="${BRIDGE:-$DEFAULT_BRIDGE}"
fi
if [[ -z "${VLAN_TAG+x}" ]]; then
read -rp "VLAN tag (empty for none): " VLAN_TAG
fi
if [[ -z "${TEMPLATE_STORAGE:-}" ]]; then
read -rp "Template storage [$DEFAULT_TEMPLATE_STORAGE]: " TEMPLATE_STORAGE
TEMPLATE_STORAGE="${TEMPLATE_STORAGE:-$DEFAULT_TEMPLATE_STORAGE}"
@@ -127,15 +135,17 @@ create_lxc() {
ROOT_PASSWORD=$(openssl rand -base64 18)
local net_opts="name=eth0,bridge=$BRIDGE"
[[ -n "${VLAN_TAG:-}" ]] && net_opts+=",tag=$VLAN_TAG"
if [[ "$IPCFG" == "dhcp" ]]; then
net_opts+=",ip=dhcp"
else
net_opts+=",ip=$IPCFG,gw=$GATEWAY"
fi
msg_info "Creating unprivileged LXC $CTID ($HOSTNAME)..."
msg_info "Creating unprivileged LXC $CTID ($CT_HOSTNAME)..."
msg_info " net0: $net_opts"
pct create "$CTID" "$TEMPLATE_STORAGE:vztmpl/$TEMPLATE" \
--hostname "$HOSTNAME" \
--hostname "$CT_HOSTNAME" \
--cores "$CORES" \
--memory "$RAM" \
--swap 512 \
@@ -156,11 +166,13 @@ create_lxc() {
local i
for i in {1..30}; do
if pct exec "$CTID" -- getent hosts deb.debian.org >/dev/null 2>&1; then
break
msg_ok "Network up"
return 0
fi
sleep 2
done
msg_ok "Network up"
msg_err "Network never came up. Check bridge/VLAN/gateway settings."
exit 1
}
# ── bootstrap installer inside the container ─────────────────────────────────
@@ -189,7 +201,7 @@ print_summary() {
msg_ok "Installation complete!"
echo
echo "─────────────────────────────────────────────────────────────"
echo " $APP LXC #$CTID — $HOSTNAME"
echo " $APP LXC #$CTID — $CT_HOSTNAME"
echo "─────────────────────────────────────────────────────────────"
print_app_summary
echo