Adapt installers to upstream wireguard-ui build (Go+embed, yarn assets)
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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
94f0e69676
commit
e5c0a5888f
+34
-36
@@ -1,18 +1,14 @@
|
||||
#!/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).
|
||||
# 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
|
||||
|
||||
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"
|
||||
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
|
||||
@@ -20,47 +16,47 @@ if [[ "$(id -u)" -ne 0 ]]; then
|
||||
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
|
||||
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 [[ -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
|
||||
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 "$CONFIG_DIR"
|
||||
mkdir -p "$DATA_DIR"
|
||||
mkdir -p "$HOOKS_DIR"
|
||||
mkdir -p "$INSTALL_DIR/db"
|
||||
|
||||
echo "Installing binary to $BIN_DST..."
|
||||
cp "$BIN_SRC" "${BIN_DST}.new"
|
||||
cp "$BIN_NAME" "${BIN_DST}.new"
|
||||
chmod 0755 "${BIN_DST}.new"
|
||||
mv -f "${BIN_DST}.new" "$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"
|
||||
# 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."
|
||||
@@ -72,3 +68,5 @@ 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)"
|
||||
|
||||
@@ -130,11 +130,14 @@ echo "Starting container..."
|
||||
pct start "$VMID"
|
||||
sleep 5
|
||||
|
||||
echo "Installing base dependencies inside container (Go, git, wireguard-tools, nftables)..."
|
||||
echo "Installing base dependencies inside container (Go, Node/yarn, git, wireguard-tools, nftables)..."
|
||||
pct exec "$VMID" -- bash -c "
|
||||
set -e
|
||||
apt-get update
|
||||
apt-get install -y wireguard-tools nftables curl ca-certificates git
|
||||
apt-get install -y wireguard-tools nftables curl ca-certificates git nodejs npm
|
||||
if ! command -v yarn >/dev/null 2>&1; then
|
||||
npm install -g yarn
|
||||
fi
|
||||
if ! command -v go >/dev/null 2>&1; then
|
||||
ARCH=\$(dpkg --print-architecture)
|
||||
curl -fsSL https://go.dev/dl/go1.22.5.linux-\${ARCH}.tar.gz -o /tmp/go.tar.gz
|
||||
@@ -160,9 +163,8 @@ pct exec "$VMID" -- bash -c "
|
||||
echo "Running native installer inside container..."
|
||||
pct exec "$VMID" -- bash -c "
|
||||
set -e
|
||||
export PATH=/usr/local/go/bin:/usr/local/bin:\$PATH
|
||||
cd /opt/wireguard-ui-multi-src
|
||||
go mod tidy
|
||||
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o wireguard-ui-multi ./cmd/wireguard-ui-multi
|
||||
bash scripts/install.sh
|
||||
"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user