The web UI 404'd in production because templates/static were loaded
via relative paths ("internal/ui/templates", "internal/ui/static"),
which only resolved when running from the repo checkout. systemd sets
WorkingDirectory=/var/lib/wireguard-ui-multi, so those paths never
existed there.
Add a -ui-root flag (default /usr/local/share/wireguard-ui-multi/ui),
have install.sh copy internal/ui there, and resolve templates/static
paths through it instead of hardcoded relative strings.
Also add release-binary fast path to bootstrap.sh (falls back to
source build with CGO_ENABLED=0/-trimpath if no release exists yet),
and document real hardware/build-RAM requirements in the README.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
74 lines
2.4 KiB
Bash
Executable File
74 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Idempotent installer for wireguard-ui-multi. Expects the binary to already be
|
|
# built at ./wireguard-ui-multi (run `go build ./cmd/wireguard-ui-multi` first).
|
|
set -euo pipefail
|
|
|
|
export PATH="/usr/local/go/bin:/usr/local/bin:$PATH"
|
|
|
|
BIN_SRC="./wireguard-ui-multi"
|
|
BIN_DST="/usr/local/bin/wireguard-ui-multi"
|
|
CONFIG_DIR="/etc/wireguard-ui-multi"
|
|
DATA_DIR="/var/lib/wireguard-ui-multi"
|
|
HOOKS_DIR="/etc/wireguard-manager/hooks"
|
|
UI_SRC="internal/ui"
|
|
UI_DST="/usr/local/share/wireguard-ui-multi/ui"
|
|
SERVICE_SRC="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
|
|
|
|
if [[ ! -f "$BIN_SRC" ]]; then
|
|
if [[ -d "./cmd/wireguard-ui-multi" ]] && command -v go >/dev/null 2>&1; then
|
|
echo "Binary not found, building from source with 'go build'..."
|
|
go mod tidy
|
|
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o "$BIN_SRC" ./cmd/wireguard-ui-multi
|
|
else
|
|
echo "Binary not found at $BIN_SRC and cannot build (need Go toolchain + source). Build it first, e.g.:" >&2
|
|
echo " go build -o wireguard-ui-multi ./cmd/wireguard-ui-multi" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if [[ -d /usr/local/go/bin ]] && [[ ! -f /etc/profile.d/go-path.sh ]]; then
|
|
echo "Persisting Go on PATH for future shells (/etc/profile.d/go-path.sh)..."
|
|
echo 'export PATH="/usr/local/go/bin:$PATH"' > /etc/profile.d/go-path.sh
|
|
chmod 0644 /etc/profile.d/go-path.sh
|
|
fi
|
|
|
|
echo "Creating directories..."
|
|
mkdir -p /usr/local/bin
|
|
mkdir -p "$CONFIG_DIR"
|
|
mkdir -p "$DATA_DIR"
|
|
mkdir -p "$HOOKS_DIR"
|
|
|
|
echo "Installing binary to $BIN_DST..."
|
|
cp "$BIN_SRC" "$BIN_DST"
|
|
chmod 0755 "$BIN_DST"
|
|
|
|
echo "Installing UI assets to $UI_DST..."
|
|
mkdir -p "$(dirname "$UI_DST")"
|
|
rm -rf "$UI_DST"
|
|
cp -r "$UI_SRC" "$UI_DST"
|
|
|
|
echo "Installing systemd unit to $SERVICE_DST..."
|
|
cp "$SERVICE_SRC" "$SERVICE_DST"
|
|
systemctl daemon-reload
|
|
|
|
# The database holds bcrypt password hashes; keep the directory private.
|
|
echo "Restricting permissions on $DATA_DIR (0700)..."
|
|
chmod 0700 "$DATA_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"
|