auto-start services, prompt for WG + LAN nets, fix busybox httpd applet
- create-lxc.sh prompts for WIRECON_NET / PEER_IP / CLIENT_IP / LAN_CIDR (defaults 10.13.13.0/24, .1, .2, 192.168.1.0/24) and passes them through to the in-container bootstrap - install.sh generates a placeholder /etc/wireguard/wg0.conf from those env vars instead of copying the static example, and updates PEER_IP in wirecon.conf on first install - install.sh always enables + starts wg-quick, watchdog, monitor and (if WIRECON_WEB_AUTOSTART=yes, default yes) the web UI, even before keys are filled in — wg-quick will fail until then, and the web UI is the way to finish configuration - apk installs busybox-extras and wirecon-web now runs /usr/sbin/httpd (fixes "httpd: applet not found" on base busybox) - create-lxc.sh drops its own web-UI start block (install.sh owns it) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
14fad9a49e
commit
78c3a790be
3 files changed
+112
-57
No files matched your search
@@ -14,8 +14,8 @@ description="wirecon web UI (busybox httpd)"
|
|||||||
: "${WEB_ROOT:=/var/www/wirecon}"
|
: "${WEB_ROOT:=/var/www/wirecon}"
|
||||||
|
|
||||||
supervisor="supervise-daemon"
|
supervisor="supervise-daemon"
|
||||||
command="/bin/busybox"
|
command="/usr/sbin/httpd"
|
||||||
command_args="httpd -f -v -p ${WEB_BIND}:${WEB_PORT} -h ${WEB_ROOT} -c /etc/wirecon/httpd.conf"
|
command_args="-f -v -p ${WEB_BIND}:${WEB_PORT} -h ${WEB_ROOT} -c /etc/wirecon/httpd.conf"
|
||||||
respawn_delay=5
|
respawn_delay=5
|
||||||
respawn_max=0
|
respawn_max=0
|
||||||
output_log="/var/log/wirecon-web.log"
|
output_log="/var/log/wirecon-web.log"
|
||||||
|
|||||||
+65
-35
@@ -27,6 +27,7 @@ log "installing packages"
|
|||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
bash \
|
bash \
|
||||||
nano \
|
nano \
|
||||||
|
busybox-extras \
|
||||||
wireguard-tools \
|
wireguard-tools \
|
||||||
wireguard-tools-openrc \
|
wireguard-tools-openrc \
|
||||||
iptables \
|
iptables \
|
||||||
@@ -85,52 +86,81 @@ if [[ ! -L /etc/init.d/wg-quick.wg0 ]]; then
|
|||||||
ln -s wg-quick /etc/init.d/wg-quick.wg0
|
ln -s wg-quick /etc/init.d/wg-quick.wg0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# --- env-driven defaults (propagated from create-lxc.sh / bootstrap.sh) -----
|
||||||
|
: "${WIRECON_NET:=10.13.13.0/24}"
|
||||||
|
: "${WIRECON_PEER_IP:=10.13.13.1}"
|
||||||
|
: "${WIRECON_CLIENT_IP:=10.13.13.2}"
|
||||||
|
: "${WIRECON_LAN_CIDR:=192.168.1.0/24}"
|
||||||
|
: "${WIRECON_WEB_AUTOSTART:=yes}"
|
||||||
|
|
||||||
|
# CIDR prefix (e.g. 24) — carry onto the client Address line.
|
||||||
|
WIRECON_NET_PREFIX="${WIRECON_NET##*/}"
|
||||||
|
[[ "$WIRECON_NET_PREFIX" == "$WIRECON_NET" ]] && WIRECON_NET_PREFIX=24
|
||||||
|
|
||||||
if [[ ! -e /etc/wirecon/wirecon.conf ]]; then
|
if [[ ! -e /etc/wirecon/wirecon.conf ]]; then
|
||||||
log "installing default /etc/wirecon/wirecon.conf"
|
log "installing default /etc/wirecon/wirecon.conf (PEER_IP=$WIRECON_PEER_IP)"
|
||||||
install -m 0644 "$SRC/etc/wirecon/wirecon.conf" /etc/wirecon/wirecon.conf
|
install -m 0644 "$SRC/etc/wirecon/wirecon.conf" /etc/wirecon/wirecon.conf
|
||||||
|
sed -i "s|^PEER_IP=.*|PEER_IP=${WIRECON_PEER_IP}|" /etc/wirecon/wirecon.conf
|
||||||
else
|
else
|
||||||
log "keeping existing /etc/wirecon/wirecon.conf"
|
log "keeping existing /etc/wirecon/wirecon.conf"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -e /etc/wireguard/wg0.conf ]]; then
|
if [[ ! -e /etc/wireguard/wg0.conf ]]; then
|
||||||
log "seeding /etc/wireguard/wg0.conf from example (EDIT BEFORE STARTING)"
|
log "generating placeholder /etc/wireguard/wg0.conf (edit keys via web UI or nano)"
|
||||||
install -m 0600 "$SRC/etc/wireguard/wg0.conf.example" /etc/wireguard/wg0.conf
|
umask 077
|
||||||
EDIT_REQUIRED=1
|
cat > /etc/wireguard/wg0.conf <<EOF
|
||||||
|
# /etc/wireguard/wg0.conf — generated by wirecon install.sh
|
||||||
|
# Fill in PrivateKey, PublicKey, Endpoint. Until then wg-quick will fail to
|
||||||
|
# dial; the watchdog keeps retrying and the web UI lets you edit this file.
|
||||||
|
|
||||||
|
[Interface]
|
||||||
|
Address = ${WIRECON_CLIENT_IP}/${WIRECON_NET_PREFIX}
|
||||||
|
PrivateKey = REPLACE_WITH_CLIENT_PRIVATE_KEY
|
||||||
|
|
||||||
|
# Default 1280 for Telekom DSL/LTE Hybrid (GRE overlay eats headroom).
|
||||||
|
# Run wirecon-mtu-probe.sh to find a better value.
|
||||||
|
MTU = 1280
|
||||||
|
|
||||||
|
# MASQ traffic from the WG tunnel onto the LAN. Replace eth0 with the LXC's
|
||||||
|
# LAN interface name if it differs.
|
||||||
|
PostUp = sysctl -w net.ipv4.ip_forward=1
|
||||||
|
# LAN subnet: ${WIRECON_LAN_CIDR}
|
||||||
|
PostUp = iptables -t nat -A POSTROUTING -s ${WIRECON_NET} -o eth0 -j MASQUERADE
|
||||||
|
PostUp = iptables -A FORWARD -i %i -o eth0 -j ACCEPT
|
||||||
|
PostUp = iptables -A FORWARD -i eth0 -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||||
|
PostDown = iptables -t nat -D POSTROUTING -s ${WIRECON_NET} -o eth0 -j MASQUERADE
|
||||||
|
PostDown = iptables -D FORWARD -i %i -o eth0 -j ACCEPT
|
||||||
|
PostDown = iptables -D FORWARD -i eth0 -o %i -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||||
|
|
||||||
|
[Peer]
|
||||||
|
PublicKey = REPLACE_WITH_SERVER_PUBLIC_KEY
|
||||||
|
Endpoint = REPLACE_WITH_SERVER_PUBLIC_HOST:51820
|
||||||
|
AllowedIPs = ${WIRECON_PEER_IP}/32
|
||||||
|
PersistentKeepalive = 25
|
||||||
|
EOF
|
||||||
|
chmod 0600 /etc/wireguard/wg0.conf
|
||||||
else
|
else
|
||||||
log "keeping existing /etc/wireguard/wg0.conf"
|
log "keeping existing /etc/wireguard/wg0.conf"
|
||||||
EDIT_REQUIRED=0
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- enable services --------------------------------------------------------
|
# --- enable + start services (always, even with placeholder keys) -----------
|
||||||
if [[ "$EDIT_REQUIRED" == "1" ]]; then
|
# wg-quick will fail until keys are filled in — that's fine. The watchdog
|
||||||
cat <<'EOF'
|
# will keep retrying, and the web UI is how you finish configuration.
|
||||||
|
log "enabling + starting services"
|
||||||
|
rc-update add wg-quick.wg0 default 2>/dev/null || true
|
||||||
|
rc-update add wirecon-watchdog default 2>/dev/null || true
|
||||||
|
rc-update add wirecon-monitor default 2>/dev/null || true
|
||||||
|
|
||||||
NEXT STEPS:
|
rc-service wg-quick.wg0 start 2>/dev/null || log "wg-quick.wg0 failed to start (expected until keys are set in /etc/wireguard/wg0.conf)"
|
||||||
1. Generate keys and edit /etc/wireguard/wg0.conf:
|
rc-service wirecon-watchdog start 2>/dev/null || true
|
||||||
- [Interface] PrivateKey + MTU + PostUp LAN iface name
|
rc-service wirecon-monitor start 2>/dev/null || true
|
||||||
- [Peer] Server PublicKey + Endpoint
|
|
||||||
2. Review /etc/wirecon/wirecon.conf (PEER_IP, thresholds).
|
if [[ "$WIRECON_WEB_AUTOSTART" == "yes" ]]; then
|
||||||
3. Start everything:
|
|
||||||
rc-update add wg-quick.wg0 default
|
|
||||||
rc-update add wirecon-watchdog default
|
|
||||||
rc-update add wirecon-monitor default
|
|
||||||
rc-update add wirecon-web default # optional, http://<lxc>:8080
|
|
||||||
rc-service wg-quick.wg0 start
|
|
||||||
rc-service wirecon-watchdog start
|
|
||||||
rc-service wirecon-monitor start
|
|
||||||
rc-service wirecon-web start
|
|
||||||
4. Watch the logs:
|
|
||||||
tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
|
||||||
EOF
|
|
||||||
else
|
|
||||||
log "enabling + (re)starting services"
|
|
||||||
rc-update add wg-quick.wg0 default 2>/dev/null || true
|
|
||||||
rc-update add wirecon-watchdog default 2>/dev/null || true
|
|
||||||
rc-update add wirecon-monitor default 2>/dev/null || true
|
|
||||||
rc-update add wirecon-web default 2>/dev/null || true
|
rc-update add wirecon-web default 2>/dev/null || true
|
||||||
rc-service wg-quick.wg0 restart
|
rc-service wirecon-web start 2>/dev/null || true
|
||||||
rc-service wirecon-watchdog restart
|
log "web UI enabled on http://<lxc-ip>:${WEB_PORT:-8080}/"
|
||||||
rc-service wirecon-monitor restart
|
else
|
||||||
rc-service wirecon-web restart
|
log "web UI disabled (enable: rc-update add wirecon-web default && rc-service wirecon-web start)"
|
||||||
log "done. UI: http://<lxc-ip>:${WEB_PORT:-8080}/ | logs: tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
log "done. logs: tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log"
|
||||||
+45
-20
@@ -40,22 +40,39 @@ fi
|
|||||||
|
|
||||||
log() { printf '[create-lxc] %s\n' "$*"; }
|
log() { printf '[create-lxc] %s\n' "$*"; }
|
||||||
|
|
||||||
# --- web UI autostart -------------------------------------------------------
|
# --- interactive prompts (web UI + WG network) ------------------------------
|
||||||
# WIRECON_WEB_AUTOSTART=yes|no overrides the prompt. Default: yes (the UI is
|
# All settings can be preset via env vars; the prompt is skipped when set.
|
||||||
# how you'll edit wg0.conf / wirecon.conf without drop-to-shell).
|
# WIRECON_WEB_AUTOSTART=yes|no, WIRECON_NET=CIDR, WIRECON_PEER_IP=ip,
|
||||||
|
# WIRECON_CLIENT_IP=ip.
|
||||||
|
_ask() { # _ask <varname> <prompt> <default>
|
||||||
|
local var="$1" prompt="$2" default="$3" ans=""
|
||||||
|
if [[ -n "${!var:-}" ]]; then return; fi
|
||||||
|
if [[ -r /dev/tty && -w /dev/tty ]]; then
|
||||||
|
printf '%s [%s]: ' "$prompt" "$default" >/dev/tty
|
||||||
|
IFS= read -r ans </dev/tty || ans=""
|
||||||
|
printf -v "$var" '%s' "${ans:-$default}"
|
||||||
|
else
|
||||||
|
printf -v "$var" '%s' "$default"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if [[ -z "${WIRECON_WEB_AUTOSTART:-}" ]]; then
|
if [[ -z "${WIRECON_WEB_AUTOSTART:-}" ]]; then
|
||||||
if [[ -r /dev/tty && -w /dev/tty ]]; then
|
if [[ -r /dev/tty && -w /dev/tty ]]; then
|
||||||
printf 'start web UI automatically on boot? [Y/n] ' >/dev/tty
|
printf 'start web UI automatically on boot? [Y/n] ' >/dev/tty
|
||||||
IFS= read -r _ans </dev/tty || _ans=""
|
IFS= read -r _ans </dev/tty || _ans=""
|
||||||
case "$_ans" in
|
case "$_ans" in n|N|no|NO) WIRECON_WEB_AUTOSTART=no ;; *) WIRECON_WEB_AUTOSTART=yes ;; esac
|
||||||
n|N|no|NO) WIRECON_WEB_AUTOSTART=no ;;
|
|
||||||
*) WIRECON_WEB_AUTOSTART=yes ;;
|
|
||||||
esac
|
|
||||||
else
|
else
|
||||||
WIRECON_WEB_AUTOSTART=yes
|
WIRECON_WEB_AUTOSTART=yes
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_ask WIRECON_NET "wireguard tunnel network (CIDR)" "10.13.13.0/24"
|
||||||
|
_ask WIRECON_PEER_IP "wireguard server (peer) IP" "10.13.13.1"
|
||||||
|
_ask WIRECON_CLIENT_IP "wireguard client (this LXC) IP" "10.13.13.2"
|
||||||
|
_ask WIRECON_LAN_CIDR "local LAN subnet (CIDR)" "192.168.1.0/24"
|
||||||
|
|
||||||
|
log "wg net=$WIRECON_NET peer=$WIRECON_PEER_IP client=$WIRECON_CLIENT_IP lan=$WIRECON_LAN_CIDR web_autostart=$WIRECON_WEB_AUTOSTART"
|
||||||
|
|
||||||
# --- pick VMID --------------------------------------------------------------
|
# --- pick VMID --------------------------------------------------------------
|
||||||
VMID=$(pvesh get /cluster/nextid)
|
VMID=$(pvesh get /cluster/nextid)
|
||||||
log "VMID=$VMID hostname=$HOSTNAME cores=$CORES mem=${MEMORY}MiB disk=${DISK}GiB"
|
log "VMID=$VMID hostname=$HOSTNAME cores=$CORES mem=${MEMORY}MiB disk=${DISK}GiB"
|
||||||
@@ -128,7 +145,15 @@ log "installing bootstrap prereqs inside LXC"
|
|||||||
pct exec "$VMID" -- sh -c 'apk add --no-cache bash curl ca-certificates >/dev/null'
|
pct exec "$VMID" -- sh -c 'apk add --no-cache bash curl ca-certificates >/dev/null'
|
||||||
|
|
||||||
log "running bootstrap from $BOOTSTRAP_URL"
|
log "running bootstrap from $BOOTSTRAP_URL"
|
||||||
pct exec "$VMID" -- sh -c "curl -fsSL '$BOOTSTRAP_URL' | WIRECON_REPO='$WIRECON_REPO' WIRECON_REF='$WIRECON_REF' bash"
|
pct exec "$VMID" -- sh -c "curl -fsSL '$BOOTSTRAP_URL' \
|
||||||
|
| WIRECON_REPO='$WIRECON_REPO' \
|
||||||
|
WIRECON_REF='$WIRECON_REF' \
|
||||||
|
WIRECON_NET='$WIRECON_NET' \
|
||||||
|
WIRECON_PEER_IP='$WIRECON_PEER_IP' \
|
||||||
|
WIRECON_CLIENT_IP='$WIRECON_CLIENT_IP' \
|
||||||
|
WIRECON_LAN_CIDR='$WIRECON_LAN_CIDR' \
|
||||||
|
WIRECON_WEB_AUTOSTART='$WIRECON_WEB_AUTOSTART' \
|
||||||
|
bash"
|
||||||
|
|
||||||
# --- tty1 auto-login (for Proxmox web Console) ------------------------------
|
# --- tty1 auto-login (for Proxmox web Console) ------------------------------
|
||||||
# Drop a /usr/local/sbin/autologin-root wrapper and point getty at it so the
|
# Drop a /usr/local/sbin/autologin-root wrapper and point getty at it so the
|
||||||
@@ -152,13 +177,14 @@ pct exec "$VMID" -- sh -c '
|
|||||||
pkill -KILL getty 2>/dev/null || true
|
pkill -KILL getty 2>/dev/null || true
|
||||||
'
|
'
|
||||||
|
|
||||||
# --- optional: start web UI -------------------------------------------------
|
# --- final summary ----------------------------------------------------------
|
||||||
|
# install.sh (run by bootstrap) has already enabled + started wg-quick,
|
||||||
|
# watchdog, monitor, and (if WIRECON_WEB_AUTOSTART=yes) the web UI. Keys
|
||||||
|
# aren't filled in yet — wg-quick will be failing until you edit wg0.conf
|
||||||
|
# in the web UI (or via the Proxmox Console).
|
||||||
if [[ "$WIRECON_WEB_AUTOSTART" == "yes" ]]; then
|
if [[ "$WIRECON_WEB_AUTOSTART" == "yes" ]]; then
|
||||||
log "enabling + starting wirecon-web"
|
|
||||||
pct exec "$VMID" -- sh -c 'rc-update add wirecon-web default && rc-service wirecon-web start'
|
|
||||||
WEB_URL="http://${ip:-<lxc-ip>}:8080/"
|
WEB_URL="http://${ip:-<lxc-ip>}:8080/"
|
||||||
else
|
else
|
||||||
log "wirecon-web left disabled (enable later: rc-update add wirecon-web default && rc-service wirecon-web start)"
|
|
||||||
WEB_URL=""
|
WEB_URL=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -168,12 +194,11 @@ cat <<EOF
|
|||||||
[create-lxc] shell: open Console in the Proxmox UI → root shell, no prompt
|
[create-lxc] shell: open Console in the Proxmox UI → root shell, no prompt
|
||||||
[create-lxc] (or from the host: pct enter $VMID)
|
[create-lxc] (or from the host: pct enter $VMID)
|
||||||
${WEB_URL:+[create-lxc] web UI: $WEB_URL}
|
${WEB_URL:+[create-lxc] web UI: $WEB_URL}
|
||||||
[create-lxc] finish configuration:
|
[create-lxc] all services are already enabled + running; wg-quick will
|
||||||
- edit /etc/wireguard/wg0.conf and /etc/wirecon/wirecon.conf
|
[create-lxc] fail until keys are configured. Finish setup by editing
|
||||||
(via the web UI above, or the Proxmox Console)
|
[create-lxc] /etc/wireguard/wg0.conf (PrivateKey, Peer PublicKey, Endpoint)
|
||||||
- then start the tunnel services:
|
[create-lxc] /etc/wirecon/wirecon.conf (thresholds — optional)
|
||||||
rc-update add wg-quick.wg0 default && rc-service wg-quick.wg0 start
|
[create-lxc] via the web UI above, then:
|
||||||
rc-update add wirecon-watchdog default && rc-service wirecon-watchdog start
|
[create-lxc] rc-service wg-quick.wg0 restart
|
||||||
rc-update add wirecon-monitor default && rc-service wirecon-monitor start
|
[create-lxc] tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
||||||
- tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log
|
|
||||||
EOF
|
EOF
|
||||||
Reference in new issue
Block a user