- 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>
167 lines
6.5 KiB
Bash
Executable File
167 lines
6.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Installer for the wirecon LXC side on Alpine Linux (OpenRC).
|
|
# Run as root inside the unprivileged LXC:
|
|
# sudo ./install.sh
|
|
#
|
|
# Idempotent. Does NOT overwrite an existing /etc/wireguard/wg0.conf so
|
|
# real keys survive re-runs.
|
|
|
|
set -euo pipefail
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "must run as root" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v apk >/dev/null; then
|
|
echo "this installer targets Alpine (apk). for Debian/RHEL use an earlier ref." >&2
|
|
exit 1
|
|
fi
|
|
|
|
SRC="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
log() { printf '[install] %s\n' "$*"; }
|
|
|
|
# --- packages ---------------------------------------------------------------
|
|
log "installing packages"
|
|
apk add --no-cache \
|
|
bash \
|
|
nano \
|
|
busybox-extras \
|
|
wireguard-tools \
|
|
wireguard-tools-openrc \
|
|
iptables \
|
|
ip6tables \
|
|
iproute2 \
|
|
iputils \
|
|
conntrack-tools \
|
|
openrc
|
|
|
|
# Default editor → nano (for visudo, crontab -e, etc.)
|
|
if ! grep -q '^export EDITOR=nano' /etc/profile 2>/dev/null; then
|
|
echo 'export EDITOR=nano' >> /etc/profile
|
|
echo 'export VISUAL=nano' >> /etc/profile
|
|
fi
|
|
|
|
# --- /dev/net/tun sanity ----------------------------------------------------
|
|
if [[ ! -e /dev/net/tun ]]; then
|
|
cat >&2 <<'EOF'
|
|
ERROR: /dev/net/tun is not present in this unprivileged LXC.
|
|
On the Proxmox host, append proxmox/lxc.conf.snippet to
|
|
/etc/pve/lxc/<VMID>.conf
|
|
and restart the container. (proxmox/create-lxc.sh does this automatically.)
|
|
EOF
|
|
exit 1
|
|
fi
|
|
|
|
# --- files ------------------------------------------------------------------
|
|
install -d -m 0755 /etc/wirecon /etc/wireguard /etc/conf.d \
|
|
/etc/init.d /usr/local/bin /var/log
|
|
|
|
log "deploying scripts"
|
|
install -m 0755 "$SRC/usr/local/bin/wirecon-watchdog.sh" /usr/local/bin/
|
|
install -m 0755 "$SRC/usr/local/bin/wirecon-watchdog-loop.sh" /usr/local/bin/
|
|
install -m 0755 "$SRC/usr/local/bin/wirecon-monitor.sh" /usr/local/bin/
|
|
install -m 0755 "$SRC/usr/local/bin/wirecon-mtu-probe.sh" /usr/local/bin/
|
|
|
|
log "deploying OpenRC init scripts"
|
|
install -m 0755 "$SRC/etc/init.d/wirecon-watchdog" /etc/init.d/
|
|
install -m 0755 "$SRC/etc/init.d/wirecon-monitor" /etc/init.d/
|
|
install -m 0755 "$SRC/etc/init.d/wirecon-web" /etc/init.d/
|
|
install -m 0644 "$SRC/etc/conf.d/wg-quick" /etc/conf.d/wg-quick
|
|
|
|
log "deploying web UI"
|
|
install -d -m 0755 /var/www/wirecon /var/www/wirecon/cgi-bin
|
|
install -m 0644 "$SRC/var/www/wirecon/index.html" /var/www/wirecon/
|
|
install -m 0644 "$SRC/var/www/wirecon/style.css" /var/www/wirecon/
|
|
install -m 0644 "$SRC/var/www/wirecon/app.js" /var/www/wirecon/
|
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/status.sh" /var/www/wirecon/cgi-bin/
|
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/config-get.sh" /var/www/wirecon/cgi-bin/
|
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/config-save.sh" /var/www/wirecon/cgi-bin/
|
|
install -m 0755 "$SRC/var/www/wirecon/cgi-bin/logs.sh" /var/www/wirecon/cgi-bin/
|
|
install -m 0644 "$SRC/etc/wirecon/httpd.conf" /etc/wirecon/httpd.conf
|
|
|
|
# Per-interface wg-quick symlink so the init script knows which iface to bring up.
|
|
if [[ ! -L /etc/init.d/wg-quick.wg0 ]]; then
|
|
ln -s wg-quick /etc/init.d/wg-quick.wg0
|
|
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
|
|
log "installing default /etc/wirecon/wirecon.conf (PEER_IP=$WIRECON_PEER_IP)"
|
|
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
|
|
log "keeping existing /etc/wirecon/wirecon.conf"
|
|
fi
|
|
|
|
if [[ ! -e /etc/wireguard/wg0.conf ]]; then
|
|
log "generating placeholder /etc/wireguard/wg0.conf (edit keys via web UI or nano)"
|
|
umask 077
|
|
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
|
|
log "keeping existing /etc/wireguard/wg0.conf"
|
|
fi
|
|
|
|
# --- enable + start services (always, even with placeholder keys) -----------
|
|
# wg-quick will fail until keys are filled in — that's fine. The watchdog
|
|
# 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
|
|
|
|
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)"
|
|
rc-service wirecon-watchdog start 2>/dev/null || true
|
|
rc-service wirecon-monitor start 2>/dev/null || true
|
|
|
|
if [[ "$WIRECON_WEB_AUTOSTART" == "yes" ]]; then
|
|
rc-update add wirecon-web default 2>/dev/null || true
|
|
rc-service wirecon-web start 2>/dev/null || true
|
|
log "web UI enabled on http://<lxc-ip>:${WEB_PORT:-8080}/"
|
|
else
|
|
log "web UI disabled (enable: rc-update add wirecon-web default && rc-service wirecon-web start)"
|
|
fi
|
|
|
|
log "done. logs: tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log"
|