From 06cf72b2c9f082262e0145c1d1f217d0f701837f Mon Sep 17 00:00:00 2001 From: Benjamin Toby Date: Sun, 13 Sep 2026 11:53:52 +0100 Subject: [PATCH] Update wgui install script --- src/scripts/install-wg-ui.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/scripts/install-wg-ui.sh b/src/scripts/install-wg-ui.sh index 4b0b6c2..7420143 100755 --- a/src/scripts/install-wg-ui.sh +++ b/src/scripts/install-wg-ui.sh @@ -8,24 +8,27 @@ set -euo pipefail +log() { echo "==> $*"; } +fail() { echo "error: $*" >&2; exit 1; } + WGUI_LIB_DIR="/var/lib/wgui" -INSTALL_DIR="${INSTALL_DIR:-$WGUI_LIB_DIR/webapp}" +INSTALL_DIR="${INSTALL_DIR:-}" SERVICE_USER="${SERVICE_USER:-}" SERVICE_GROUP="${SERVICE_GROUP:-}" SERVICE_NAME="${SERVICE_NAME:-wgui}" REPO_URL="${REPO_URL:-}" BRANCH="${BRANCH:-main}" BUN_INSTALL_DIR="${BUN_INSTALL_DIR:-/opt/bun}" +BUN_VERSION="${BUN_VERSION:-1.3.14}" BUN_BIN="/usr/local/bin/bun" UPDATE=false DEV_MODE=false if [ "${NODE_ENV:-}" = "development" ]; then DEV_MODE=true - log "NODE_ENV=development — skipping system service installation (daemon is assumed to already be running)" fi -log() { echo "==> $*"; } -fail() { echo "error: $*" >&2; exit 1; } +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" require_root() { if [ "$(id -u)" -ne 0 ]; then @@ -51,9 +54,14 @@ SERVICE_USER="${SERVICE_USER:-$(resolve_service_user)}" SERVICE_GROUP="${SERVICE_GROUP:-$(id -gn "$SERVICE_USER")}" log "running the wg-ui service as $SERVICE_USER (group: $SERVICE_GROUP)" -if [ -z "$REPO_URL" ]; then +if [ "$DEV_MODE" = true ]; then + INSTALL_DIR="${INSTALL_DIR:-$REPO_ROOT}" + log "NODE_ENV=development — using local repo at $INSTALL_DIR, skipping clone and system service installation (daemon is assumed to already be running)" +elif [ -z "$REPO_URL" ]; then fail "REPO_URL is not set — pass the git URL of the wg-ui repo, e.g. REPO_URL=https://git.example.com/org/wireguard-ui.git $0" +else + INSTALL_DIR="${INSTALL_DIR:-$WGUI_LIB_DIR/webapp}" fi detect_distro() { @@ -103,14 +111,15 @@ install_deps() { } install_bun() { + local bun_binary="$BUN_INSTALL_DIR/bin/bun" if [ ! -x "$BUN_BIN" ]; then - log "installing bun to $BUN_INSTALL_DIR ..." + log "installing bun $BUN_VERSION to $BUN_INSTALL_DIR ..." mkdir -p "$BUN_INSTALL_DIR" - curl -fsSL https://bun.sh/install | BUN_INSTALL="$BUN_INSTALL_DIR" bash - if [ ! -x "$BUN_INSTALL_DIR/bun" ]; then - fail "bun binary not found at $BUN_INSTALL_DIR/bun after install" + curl -fsSL https://bun.sh/install | BUN_INSTALL="$BUN_INSTALL_DIR" bash -s "bun-v$BUN_VERSION" + if [ ! -x "$bun_binary" ]; then + fail "bun binary not found at $bun_binary after install" fi - ln -sf "$BUN_INSTALL_DIR/bun" "$BUN_BIN" + ln -sf "$bun_binary" "$BUN_BIN" fi log "bun: $($BUN_BIN --version)" } @@ -259,7 +268,9 @@ grab_port() { install_deps install_bun setup_service_user -clone_or_update +if [ "$DEV_MODE" = false ]; then + clone_or_update +fi install_dependencies ensure_env_file setup_wireguard