port LXC side to Alpine/OpenRC, add Proxmox host-side creator

- Replace systemd units with OpenRC init scripts (supervise-daemon)
- Add wirecon-watchdog-loop.sh since OpenRC has no timers
- Switch install.sh to apk + rc-update
- Update bootstrap.sh to install git/bash via apk
- New proxmox/create-lxc.sh: picks next VMID, downloads Alpine template,
  creates unprivileged LXC with tun passthrough, chains bootstrap
- Rewrite README around the Proxmox one-liner flow
This commit is contained in:
d4nn13 committed 2026-04-19 18:40:55 +02:00
1 parent 390e10b06d
commit 5b9abdae08
13 files changed
+290 -128

No files matched your search

+128
View File
@@ -0,0 +1,128 @@
#!/bin/bash
# Provision the wirecon Alpine LXC on the Proxmox host.
# Run as root on the Proxmox host (NOT inside an LXC).
#
# Defaults:
# hostname=concad 1 core 256 MiB RAM 2 GiB disk DHCP on vmbr0
# VMID is auto-picked via `pvesh get /cluster/nextid`.
# Override any default by exporting it, e.g.:
# HOSTNAME=tunbox MEMORY=512 STORAGE=fast-nvme ./create-lxc.sh
#
# What it does:
# 1. picks next free VMID
# 2. downloads the latest alpine template if missing
# 3. creates an unprivileged LXC with nesting+keyctl
# 4. appends the /dev/net/tun passthrough to the container config
# 5. starts the container, waits for DHCP
# 6. chains into lxc/bootstrap.sh inside the LXC (which clones + installs)
set -euo pipefail
if [[ $EUID -ne 0 ]]; then
echo "must run as root on the Proxmox host" >&2
exit 1
fi
if ! command -v pct >/dev/null; then
echo "pct not found — run this on the Proxmox host" >&2
exit 1
fi
: "${HOSTNAME:=concad}"
: "${CORES:=1}"
: "${MEMORY:=256}"
: "${DISK:=2}"
: "${BRIDGE:=vmbr0}"
: "${STORAGE:=local-lvm}"
: "${TEMPLATE_STORAGE:=local}"
: "${WIRECON_REPO:=https://git.d4nn13.de/d4nn13/wirecon.git}"
: "${WIRECON_REF:=main}"
: "${BOOTSTRAP_URL:=https://git.d4nn13.de/d4nn13/wirecon/raw/branch/${WIRECON_REF}/lxc/bootstrap.sh}"
log() { printf '[create-lxc] %s\n' "$*"; }
# --- pick VMID --------------------------------------------------------------
VMID=$(pvesh get /cluster/nextid)
log "VMID=$VMID hostname=$HOSTNAME cores=$CORES mem=${MEMORY}MiB disk=${DISK}GiB"
# --- find + download template ----------------------------------------------
log "refreshing template index"
pveam update >/dev/null
tmpl=$(pveam available --section system \
| awk '{print $2}' \
| grep -E '^alpine-[0-9]+\.[0-9]+-default_' \
| sort -V | tail -n1 || true)
if [[ -z "$tmpl" ]]; then
echo "no alpine-*-default template found in pveam available" >&2
exit 1
fi
log "template: $tmpl"
if ! pveam list "$TEMPLATE_STORAGE" | awk '{print $1}' | grep -q "/$tmpl$"; then
log "downloading $tmpl to $TEMPLATE_STORAGE"
pveam download "$TEMPLATE_STORAGE" "$tmpl"
else
log "template already present in $TEMPLATE_STORAGE"
fi
# --- create container -------------------------------------------------------
log "pct create $VMID"
pct create "$VMID" "$TEMPLATE_STORAGE:vztmpl/$tmpl" \
--ostype alpine \
--hostname "$HOSTNAME" \
--cores "$CORES" \
--memory "$MEMORY" \
--swap 0 \
--rootfs "${STORAGE}:${DISK}" \
--net0 "name=eth0,bridge=${BRIDGE},firewall=1,ip=dhcp" \
--unprivileged 1 \
--features nesting=1,keyctl=1 \
--onboot 1 \
--start 0
# --- tun passthrough --------------------------------------------------------
CONF="/etc/pve/lxc/${VMID}.conf"
if ! grep -q 'lxc.mount.entry: /dev/net/tun' "$CONF"; then
log "appending /dev/net/tun passthrough to $CONF"
cat >> "$CONF" <<'EOF'
# wirecon: kernel WireGuard in unprivileged LXC
lxc.cgroup2.devices.allow: c 10:200 rwm
lxc.mount.entry: /dev/net/tun dev/net/tun none bind,create=file 0 0
EOF
fi
# --- start + wait for DHCP --------------------------------------------------
log "starting container"
pct start "$VMID"
log "waiting for eth0 to get an IPv4"
for _ in $(seq 1 45); do
if pct exec "$VMID" -- sh -c 'ip -4 addr show eth0 | grep -q "inet "' 2>/dev/null; then
break
fi
sleep 1
done
ip=$(pct exec "$VMID" -- sh -c "ip -4 -o addr show eth0 | awk '{print \$4}' | cut -d/ -f1" 2>/dev/null || echo "")
log "container IPv4: ${ip:-<not ready>}"
# --- chain into bootstrap ---------------------------------------------------
log "installing bootstrap prereqs inside LXC"
pct exec "$VMID" -- sh -c 'apk add --no-cache bash curl ca-certificates >/dev/null'
log "running bootstrap from $BOOTSTRAP_URL"
pct exec "$VMID" -- sh -c "curl -fsSL '$BOOTSTRAP_URL' | WIRECON_REPO='$WIRECON_REPO' WIRECON_REF='$WIRECON_REF' bash"
cat <<EOF
[create-lxc] container $VMID ($HOSTNAME) provisioned.
[create-lxc] finish configuration inside the LXC:
pct enter $VMID
vi /etc/wireguard/wg0.conf # keys, endpoint, LAN iface
vi /etc/wirecon/wirecon.conf # thresholds (optional)
rc-update add wg-quick.wg0 default && rc-service wg-quick.wg0 start
rc-update add wirecon-watchdog default && rc-service wirecon-watchdog start
rc-update add wirecon-monitor default && rc-service wirecon-monitor start
tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
EOF