Upstream builds a single static binary (main.go at repo root, no cmd/... subpackage) that go:embeds templates/ and assets/ at compile time, and uses a relative ./db directory (jsondb) instead of SQLite - so WorkingDirectory in the systemd unit now matters for the DB path, not for template/static serving like before. Frontend assets (admin-lte, jquery plugins) need yarn + prepare_assets.sh before go build, so all installers now also install nodejs/npm/yarn and run prepare_assets.sh when assets/dist is missing or package.json changed. Binary is now literally named "wireguard-ui" (matches upstream), listens on 0.0.0.0:5000 by default. systemd unit rewritten accordingly with WorkingDirectory=/var/lib/wireguard-ui-multi. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
73 lines
2.3 KiB
Bash
Executable File
73 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Idempotent installer for wireguard-ui (upstream ngoduykhanh/wireguard-ui
|
|
# fork). Expects to run from a checkout of this repo. Builds the frontend
|
|
# assets + Go binary if not already built, then installs everything.
|
|
set -euo pipefail
|
|
|
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
BIN_NAME="wireguard-ui"
|
|
BIN_DST="/usr/local/bin/wireguard-ui"
|
|
INSTALL_DIR="/var/lib/wireguard-ui-multi"
|
|
SERVICE_SRC="$REPO_ROOT/systemd/wireguard-ui-multi.service"
|
|
SERVICE_DST="/etc/systemd/system/wireguard-ui-multi.service"
|
|
|
|
if [[ "$(id -u)" -ne 0 ]]; then
|
|
echo "This installer must be run as root (it writes to /usr/local/bin, /etc, /var/lib)." >&2
|
|
exit 1
|
|
fi
|
|
|
|
export PATH="/usr/local/go/bin:/usr/local/bin:$PATH"
|
|
|
|
cd "$REPO_ROOT"
|
|
|
|
if [[ ! -d assets/dist ]]; then
|
|
echo "Frontend assets not built yet, running prepare_assets.sh..."
|
|
if ! command -v yarn >/dev/null 2>&1; then
|
|
echo "yarn not found. Install Node.js + yarn first, e.g.:" >&2
|
|
echo " apt-get install -y nodejs npm && npm install -g yarn" >&2
|
|
exit 1
|
|
fi
|
|
bash prepare_assets.sh
|
|
fi
|
|
|
|
if [[ ! -f "$BIN_NAME" ]]; then
|
|
if ! command -v go >/dev/null 2>&1; then
|
|
echo "go not found. Install Go first (see bootstrap.sh) or build manually:" >&2
|
|
echo " go build -o $BIN_NAME ." >&2
|
|
exit 1
|
|
fi
|
|
echo "Building $BIN_NAME..."
|
|
go mod tidy
|
|
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o "$BIN_NAME" .
|
|
fi
|
|
|
|
echo "Creating directories..."
|
|
mkdir -p /usr/local/bin
|
|
mkdir -p "$INSTALL_DIR/db"
|
|
|
|
echo "Installing binary to $BIN_DST..."
|
|
cp "$BIN_NAME" "${BIN_DST}.new"
|
|
chmod 0755 "${BIN_DST}.new"
|
|
mv -f "${BIN_DST}.new" "$BIN_DST"
|
|
|
|
echo "Installing systemd unit to $SERVICE_DST..."
|
|
cp "$SERVICE_SRC" "$SERVICE_DST"
|
|
systemctl daemon-reload
|
|
|
|
# The jsondb store holds session secrets and password hashes; keep it private.
|
|
echo "Restricting permissions on $INSTALL_DIR (0700)..."
|
|
chmod 0700 "$INSTALL_DIR"
|
|
|
|
echo
|
|
echo "Installation complete."
|
|
echo "This script does NOT start the service automatically. To enable and start it, run:"
|
|
echo
|
|
echo " systemctl enable --now wireguard-ui-multi.service"
|
|
echo
|
|
echo "Then check status with:"
|
|
echo
|
|
echo " systemctl status wireguard-ui-multi.service"
|
|
echo " journalctl -u wireguard-ui-multi.service -f"
|
|
echo
|
|
echo "Default UI: http://<host>:5000 (see WGUI_BIND_ADDRESS in the systemd unit to change)"
|