#!/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://:5000 (see WGUI_BIND_ADDRESS in the systemd unit to change)"