- 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
114 lines
3.8 KiB
Bash
Executable File
114 lines
3.8 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 \
|
|
wireguard-tools \
|
|
wireguard-tools-openrc \
|
|
iptables \
|
|
ip6tables \
|
|
iproute2 \
|
|
iputils \
|
|
conntrack-tools \
|
|
openrc
|
|
|
|
# --- /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 0644 "$SRC/etc/conf.d/wg-quick" /etc/conf.d/wg-quick
|
|
|
|
# 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
|
|
|
|
if [[ ! -e /etc/wirecon/wirecon.conf ]]; then
|
|
log "installing default /etc/wirecon/wirecon.conf"
|
|
install -m 0644 "$SRC/etc/wirecon/wirecon.conf" /etc/wirecon/wirecon.conf
|
|
else
|
|
log "keeping existing /etc/wirecon/wirecon.conf"
|
|
fi
|
|
|
|
if [[ ! -e /etc/wireguard/wg0.conf ]]; then
|
|
log "seeding /etc/wireguard/wg0.conf from example (EDIT BEFORE STARTING)"
|
|
install -m 0600 "$SRC/etc/wireguard/wg0.conf.example" /etc/wireguard/wg0.conf
|
|
EDIT_REQUIRED=1
|
|
else
|
|
log "keeping existing /etc/wireguard/wg0.conf"
|
|
EDIT_REQUIRED=0
|
|
fi
|
|
|
|
# --- enable services --------------------------------------------------------
|
|
if [[ "$EDIT_REQUIRED" == "1" ]]; then
|
|
cat <<'EOF'
|
|
|
|
NEXT STEPS:
|
|
1. Generate keys and edit /etc/wireguard/wg0.conf:
|
|
- [Interface] PrivateKey + MTU + PostUp LAN iface name
|
|
- [Peer] Server PublicKey + Endpoint
|
|
2. Review /etc/wirecon/wirecon.conf (PEER_IP, thresholds).
|
|
3. Start everything:
|
|
rc-update add wg-quick.wg0 default
|
|
rc-update add wirecon-watchdog default
|
|
rc-update add wirecon-monitor default
|
|
rc-service wg-quick.wg0 start
|
|
rc-service wirecon-watchdog start
|
|
rc-service wirecon-monitor 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-service wg-quick.wg0 restart
|
|
rc-service wirecon-watchdog restart
|
|
rc-service wirecon-monitor restart
|
|
log "done. tail logs: tail -F /var/log/wirecon-watchdog.log /var/log/wirecon-monitor.log"
|
|
fi
|