Update wgui install script

This commit is contained in:
2026-09-13 11:53:52 +01:00
parent ad94385bcb
commit 06cf72b2c9
+21 -10
View File
@@ -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
if [ "$DEV_MODE" = false ]; then
clone_or_update
fi
install_dependencies
ensure_env_file
setup_wireguard