Add update.sh, persist Go on PATH via profile.d
update.sh pulls the latest main, rebuilds, reinstalls, and restarts the service in one step. install.sh/bootstrap.sh now also drop /etc/profile.d/go-path.sh so Go stays on PATH in future shells, not just within the running install script. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
f333623035
commit
b2b6b82f58
@@ -62,6 +62,16 @@ sudo systemctl enable --now wireguard-ui-multi.service
|
|||||||
Der Quellcode bleibt unter `/opt/wireguard-ui-multi-src` liegen; erneutes
|
Der Quellcode bleibt unter `/opt/wireguard-ui-multi-src` liegen; erneutes
|
||||||
Ausführen des Einzeilers aktualisiert die Installation.
|
Ausführen des Einzeilers aktualisiert die Installation.
|
||||||
|
|
||||||
|
### Update
|
||||||
|
|
||||||
|
Für ein gezieltes Update (holt neuesten Code, baut neu, installiert neu und
|
||||||
|
startet den Dienst neu):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd /opt/wireguard-ui-multi-src
|
||||||
|
sudo ./update.sh
|
||||||
|
```
|
||||||
|
|
||||||
### Manuelle Installation
|
### Manuelle Installation
|
||||||
|
|
||||||
#### 1. Aus dem Quellcode bauen
|
#### 1. Aus dem Quellcode bauen
|
||||||
|
|||||||
@@ -49,6 +49,11 @@ if ! command -v go >/dev/null 2>&1; then
|
|||||||
rm -f /tmp/go.tar.gz
|
rm -f /tmp/go.tar.gz
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f /etc/profile.d/go-path.sh ]]; then
|
||||||
|
echo 'export PATH="/usr/local/go/bin:$PATH"' > /etc/profile.d/go-path.sh
|
||||||
|
chmod 0644 /etc/profile.d/go-path.sh
|
||||||
|
fi
|
||||||
|
|
||||||
if ! command -v go >/dev/null 2>&1; then
|
if ! command -v go >/dev/null 2>&1; then
|
||||||
echo "go still not found on PATH after install attempt (/usr/local/go/bin)." >&2
|
echo "go still not found on PATH after install attempt (/usr/local/go/bin)." >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
# built at ./wireguard-ui-multi (run `go build ./cmd/wireguard-ui-multi` first).
|
# built at ./wireguard-ui-multi (run `go build ./cmd/wireguard-ui-multi` first).
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
|
export PATH="/usr/local/go/bin:/usr/local/bin:$PATH"
|
||||||
|
|
||||||
BIN_SRC="./wireguard-ui-multi"
|
BIN_SRC="./wireguard-ui-multi"
|
||||||
BIN_DST="/usr/local/bin/wireguard-ui-multi"
|
BIN_DST="/usr/local/bin/wireguard-ui-multi"
|
||||||
CONFIG_DIR="/etc/wireguard-ui-multi"
|
CONFIG_DIR="/etc/wireguard-ui-multi"
|
||||||
@@ -28,6 +30,12 @@ if [[ ! -f "$BIN_SRC" ]]; then
|
|||||||
fi
|
fi
|
||||||
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..."
|
echo "Creating directories..."
|
||||||
mkdir -p /usr/local/bin
|
mkdir -p /usr/local/bin
|
||||||
mkdir -p "$CONFIG_DIR"
|
mkdir -p "$CONFIG_DIR"
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Updates an existing wireguard-ui-multi installation: pulls the latest
|
||||||
|
# source, rebuilds, reinstalls the binary/unit, and restarts the service.
|
||||||
|
#
|
||||||
|
# Usage (as root):
|
||||||
|
# cd /opt/wireguard-ui-multi-src && ./update.sh
|
||||||
|
# or from anywhere:
|
||||||
|
# /opt/wireguard-ui-multi-src/update.sh --src-dir /opt/wireguard-ui-multi-src
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
REF="main"
|
||||||
|
RESTART=1
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
--src-dir) SRC_DIR="$2"; shift 2 ;;
|
||||||
|
--ref) REF="$2"; shift 2 ;;
|
||||||
|
--no-restart) RESTART=0; shift ;;
|
||||||
|
-h|--help)
|
||||||
|
echo "Usage: $0 [--src-dir <path>] [--ref <branch>] [--no-restart]" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*) echo "Unknown option: $1" >&2; exit 1 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$(id -u)" -ne 0 ]]; then
|
||||||
|
echo "Must run as root (rebuilds and reinstalls the service)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PATH="/usr/local/go/bin:/usr/local/bin:$PATH"
|
||||||
|
|
||||||
|
if [[ ! -d "$SRC_DIR/.git" ]]; then
|
||||||
|
echo "No git checkout found at $SRC_DIR. Run bootstrap.sh first." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Fetching latest $REF..."
|
||||||
|
git -C "$SRC_DIR" fetch --depth 1 origin "$REF"
|
||||||
|
BEFORE="$(git -C "$SRC_DIR" rev-parse HEAD)"
|
||||||
|
git -C "$SRC_DIR" checkout "$REF"
|
||||||
|
git -C "$SRC_DIR" reset --hard "origin/$REF"
|
||||||
|
AFTER="$(git -C "$SRC_DIR" rev-parse HEAD)"
|
||||||
|
|
||||||
|
if [[ "$BEFORE" == "$AFTER" ]]; then
|
||||||
|
echo "Already up to date ($AFTER)."
|
||||||
|
else
|
||||||
|
echo "Updated $BEFORE -> $AFTER"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Rebuilding..."
|
||||||
|
cd "$SRC_DIR"
|
||||||
|
go mod tidy
|
||||||
|
go build -o wireguard-ui-multi ./cmd/wireguard-ui-multi
|
||||||
|
|
||||||
|
echo "Reinstalling..."
|
||||||
|
bash scripts/install.sh
|
||||||
|
|
||||||
|
if [[ "$RESTART" -eq 1 ]]; then
|
||||||
|
if systemctl is-enabled --quiet wireguard-ui-multi.service 2>/dev/null || systemctl is-active --quiet wireguard-ui-multi.service 2>/dev/null; then
|
||||||
|
echo "Restarting wireguard-ui-multi.service to pick up the new binary..."
|
||||||
|
systemctl restart wireguard-ui-multi.service
|
||||||
|
systemctl status --no-pager wireguard-ui-multi.service
|
||||||
|
else
|
||||||
|
echo "Service not enabled/active yet, skipping restart. Start it with:"
|
||||||
|
echo " systemctl enable --now wireguard-ui-multi.service"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Skipping restart (--no-restart). Restart manually with:"
|
||||||
|
echo " systemctl restart wireguard-ui-multi.service"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Update complete."
|
||||||
Reference in New Issue
Block a user