fix(update): only wipe DB with --wipe-db flag, preserve data by default
This commit is contained in:
parent
8eca6d0ed4
commit
ecb3cbe442
1 changed files with 16 additions and 6 deletions
22
update.sh
22
update.sh
|
|
@ -3,22 +3,28 @@
|
||||||
# NextWks — Production Update Script
|
# NextWks — Production Update Script
|
||||||
# Pulls latest code, rebuilds, restarts NextWks only.
|
# Pulls latest code, rebuilds, restarts NextWks only.
|
||||||
# Users & auth are managed by Authelia (untouched).
|
# Users & auth are managed by Authelia (untouched).
|
||||||
|
#
|
||||||
# Run: cd /opt/nextwks && sudo bash update.sh
|
# Run: cd /opt/nextwks && sudo bash update.sh
|
||||||
|
# cd /opt/nextwks && sudo bash update.sh --wipe-db
|
||||||
# ============================================================
|
# ============================================================
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[1;33m'; NC='\033[0m'
|
GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; NC='\033[0m'
|
||||||
info() { echo -e "${BLUE}$1${NC}"; }
|
info() { echo -e "${BLUE}$1${NC}"; }
|
||||||
ok() { echo -e "${GREEN}$1${NC}"; }
|
ok() { echo -e "${GREEN}$1${NC}"; }
|
||||||
warn() { echo -e "${YELLOW}$1${NC}"; }
|
warn() { echo -e "${YELLOW}$1${NC}"; }
|
||||||
|
error() { echo -e "${RED}$1${NC}"; }
|
||||||
|
|
||||||
REPO_URL="https://git.lohmar.co.uk/lexton-it/NextWks.git"
|
REPO_URL="https://git.lohmar.co.uk/lexton-it/NextWks.git"
|
||||||
REPO_DIR="/tmp/nextwks-update"
|
REPO_DIR="/tmp/nextwks-update"
|
||||||
INSTALL_DIR="/opt/nextwks"
|
INSTALL_DIR="/opt/nextwks"
|
||||||
BIN_DIR="${INSTALL_DIR}/bin"
|
BIN_DIR="${INSTALL_DIR}/bin"
|
||||||
DATA_DIR="${INSTALL_DIR}/data"
|
DATA_DIR="${INSTALL_DIR}/data"
|
||||||
|
WIPE_DB=false
|
||||||
|
[ "${1:-}" = "--wipe-db" ] && WIPE_DB=true
|
||||||
|
|
||||||
info "Updating NextWks..."
|
info "Updating NextWks..."
|
||||||
|
[ "$WIPE_DB" = true ] && warn "Database wipe requested — users will be restored from Authelia"
|
||||||
|
|
||||||
# Clone fresh copy
|
# Clone fresh copy
|
||||||
rm -rf "$REPO_DIR" 2>/dev/null
|
rm -rf "$REPO_DIR" 2>/dev/null
|
||||||
|
|
@ -35,10 +41,14 @@ go build -ldflags="-s -w \
|
||||||
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.CommitSHA=$(git rev-parse --short HEAD)" \
|
-X git.lohmar.co.uk/lexton-it/NextWks/core/version.CommitSHA=$(git rev-parse --short HEAD)" \
|
||||||
-o /tmp/nextwks-core .
|
-o /tmp/nextwks-core .
|
||||||
|
|
||||||
# Stop, wipe data, replace, restart
|
# Stop, optionally wipe, replace, restart
|
||||||
systemctl stop nextwks
|
systemctl stop nextwks
|
||||||
warn "Wiping NextWks database (users restored from Authelia on boot)"
|
|
||||||
find "$DATA_DIR" -name "*.db*" -delete 2>/dev/null || true
|
if [ "$WIPE_DB" = true ]; then
|
||||||
|
find "$DATA_DIR" -name "*.db*" -delete 2>/dev/null || true
|
||||||
|
ok "Database wiped"
|
||||||
|
fi
|
||||||
|
|
||||||
cp /tmp/nextwks-core "$BIN_DIR/core"
|
cp /tmp/nextwks-core "$BIN_DIR/core"
|
||||||
chmod 755 "$BIN_DIR/core"
|
chmod 755 "$BIN_DIR/core"
|
||||||
chown nextwks:nextwks "$BIN_DIR/core"
|
chown nextwks:nextwks "$BIN_DIR/core"
|
||||||
|
|
@ -49,9 +59,9 @@ sleep 2
|
||||||
# Verify
|
# Verify
|
||||||
if curl -s --max-time 3 http://localhost:8080/api/health | grep -q ok; then
|
if curl -s --max-time 3 http://localhost:8080/api/health | grep -q ok; then
|
||||||
ok "NextWks updated to v${VERSION} (${COMMIT_SHA})"
|
ok "NextWks updated to v${VERSION} (${COMMIT_SHA})"
|
||||||
info "Users bootstrapped from Authelia"
|
[ "$WIPE_DB" = true ] && info "Users bootstrapped from Authelia"
|
||||||
else
|
else
|
||||||
echo "Health check failed — check: sudo journalctl -u nextwks -n 20"
|
error "Health check failed — check: sudo journalctl -u nextwks -n 20"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue