Update wgui install script
This commit is contained in:
@@ -8,24 +8,27 @@
|
|||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
log() { echo "==> $*"; }
|
||||||
|
fail() { echo "error: $*" >&2; exit 1; }
|
||||||
|
|
||||||
WGUI_LIB_DIR="/var/lib/wgui"
|
WGUI_LIB_DIR="/var/lib/wgui"
|
||||||
INSTALL_DIR="${INSTALL_DIR:-$WGUI_LIB_DIR/webapp}"
|
INSTALL_DIR="${INSTALL_DIR:-}"
|
||||||
SERVICE_USER="${SERVICE_USER:-}"
|
SERVICE_USER="${SERVICE_USER:-}"
|
||||||
SERVICE_GROUP="${SERVICE_GROUP:-}"
|
SERVICE_GROUP="${SERVICE_GROUP:-}"
|
||||||
SERVICE_NAME="${SERVICE_NAME:-wgui}"
|
SERVICE_NAME="${SERVICE_NAME:-wgui}"
|
||||||
REPO_URL="${REPO_URL:-}"
|
REPO_URL="${REPO_URL:-}"
|
||||||
BRANCH="${BRANCH:-main}"
|
BRANCH="${BRANCH:-main}"
|
||||||
BUN_INSTALL_DIR="${BUN_INSTALL_DIR:-/opt/bun}"
|
BUN_INSTALL_DIR="${BUN_INSTALL_DIR:-/opt/bun}"
|
||||||
|
BUN_VERSION="${BUN_VERSION:-1.3.14}"
|
||||||
BUN_BIN="/usr/local/bin/bun"
|
BUN_BIN="/usr/local/bin/bun"
|
||||||
UPDATE=false
|
UPDATE=false
|
||||||
DEV_MODE=false
|
DEV_MODE=false
|
||||||
if [ "${NODE_ENV:-}" = "development" ]; then
|
if [ "${NODE_ENV:-}" = "development" ]; then
|
||||||
DEV_MODE=true
|
DEV_MODE=true
|
||||||
log "NODE_ENV=development — skipping system service installation (daemon is assumed to already be running)"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log() { echo "==> $*"; }
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
fail() { echo "error: $*" >&2; exit 1; }
|
REPO_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||||
|
|
||||||
require_root() {
|
require_root() {
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
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")}"
|
SERVICE_GROUP="${SERVICE_GROUP:-$(id -gn "$SERVICE_USER")}"
|
||||||
log "running the wg-ui service as $SERVICE_USER (group: $SERVICE_GROUP)"
|
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.
|
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"
|
REPO_URL=https://git.example.com/org/wireguard-ui.git $0"
|
||||||
|
else
|
||||||
|
INSTALL_DIR="${INSTALL_DIR:-$WGUI_LIB_DIR/webapp}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
detect_distro() {
|
detect_distro() {
|
||||||
@@ -103,14 +111,15 @@ install_deps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
install_bun() {
|
install_bun() {
|
||||||
|
local bun_binary="$BUN_INSTALL_DIR/bin/bun"
|
||||||
if [ ! -x "$BUN_BIN" ]; then
|
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"
|
mkdir -p "$BUN_INSTALL_DIR"
|
||||||
curl -fsSL https://bun.sh/install | BUN_INSTALL="$BUN_INSTALL_DIR" bash
|
curl -fsSL https://bun.sh/install | BUN_INSTALL="$BUN_INSTALL_DIR" bash -s "bun-v$BUN_VERSION"
|
||||||
if [ ! -x "$BUN_INSTALL_DIR/bun" ]; then
|
if [ ! -x "$bun_binary" ]; then
|
||||||
fail "bun binary not found at $BUN_INSTALL_DIR/bun after install"
|
fail "bun binary not found at $bun_binary after install"
|
||||||
fi
|
fi
|
||||||
ln -sf "$BUN_INSTALL_DIR/bun" "$BUN_BIN"
|
ln -sf "$bun_binary" "$BUN_BIN"
|
||||||
fi
|
fi
|
||||||
log "bun: $($BUN_BIN --version)"
|
log "bun: $($BUN_BIN --version)"
|
||||||
}
|
}
|
||||||
@@ -259,7 +268,9 @@ grab_port() {
|
|||||||
install_deps
|
install_deps
|
||||||
install_bun
|
install_bun
|
||||||
setup_service_user
|
setup_service_user
|
||||||
clone_or_update
|
if [ "$DEV_MODE" = false ]; then
|
||||||
|
clone_or_update
|
||||||
|
fi
|
||||||
install_dependencies
|
install_dependencies
|
||||||
ensure_env_file
|
ensure_env_file
|
||||||
setup_wireguard
|
setup_wireguard
|
||||||
|
|||||||
Reference in New Issue
Block a user