package-lock.json generated on Windows includes win32 rollup binary but not linux-x64-gnu, breaking the frontend build on the server. - Add package-lock.json to .gitignore and remove it from git tracking - update.sh: rm -rf node_modules + package-lock.json before npm install so the server always generates a platform-correct lock file from scratch - update.sh: remove --silent from build steps so errors are visible - .gitignore: fix stale whm/cpanel dist paths → nixserver/nixclient
63 lines
2.2 KiB
Bash
Executable File
63 lines
2.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# NixPanel updater — pulls latest code and rebuilds
|
|
set -euo pipefail
|
|
|
|
RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; BOLD='\033[1m'; RESET='\033[0m'
|
|
info() { echo -e "${CYAN}[INFO]${RESET} $*"; }
|
|
success() { echo -e "${GREEN}[OK]${RESET} $*"; }
|
|
error() { echo -e "${RED}[ERROR]${RESET} $*" >&2; exit 1; }
|
|
step() { echo -e "\n${BOLD}${CYAN}━━━ $* ━━━${RESET}"; }
|
|
|
|
[[ $EUID -ne 0 ]] && error "Must be run as root"
|
|
|
|
INSTALL_DIR="${1:-/opt/nixpanel}"
|
|
[[ -d "$INSTALL_DIR/.git" ]] || error "NixPanel not found at $INSTALL_DIR"
|
|
|
|
step "Pulling latest code"
|
|
# package-lock.json is not tracked (platform-specific), but discard any other
|
|
# locally modified tracked files that could block a fast-forward pull
|
|
git -C "$INSTALL_DIR" checkout -- . 2>/dev/null || true
|
|
git -C "$INSTALL_DIR" pull --ff-only
|
|
success "Code updated"
|
|
|
|
step "Installing dependencies"
|
|
cd "$INSTALL_DIR"
|
|
# Delete node_modules and any stale lock file so npm regenerates them fresh
|
|
# for this platform (avoids the rollup native binary mismatch between
|
|
# Windows dev machines and Linux servers)
|
|
rm -rf node_modules package-lock.json
|
|
npm install --workspaces --include-workspace-root
|
|
success "Dependencies ready"
|
|
|
|
step "Running migrations"
|
|
cd "$INSTALL_DIR/server"
|
|
npx prisma generate
|
|
npx prisma db push
|
|
success "Migrations applied"
|
|
|
|
step "Rebuilding frontends"
|
|
cd "$INSTALL_DIR"
|
|
npm run build --workspace=nixserver
|
|
npm run build --workspace=nixclient
|
|
# Ensure Apache (www-data) can read the rebuilt assets
|
|
chmod 755 "$INSTALL_DIR/nixserver" "$INSTALL_DIR/nixclient"
|
|
find "$INSTALL_DIR/nixserver/dist" -type d -exec chmod 755 {} \;
|
|
find "$INSTALL_DIR/nixserver/dist" -type f -exec chmod 644 {} \;
|
|
find "$INSTALL_DIR/nixclient/dist" -type d -exec chmod 755 {} \;
|
|
find "$INSTALL_DIR/nixclient/dist" -type f -exec chmod 644 {} \;
|
|
success "Frontends rebuilt"
|
|
|
|
step "Rebuilding server"
|
|
cd "$INSTALL_DIR/server"
|
|
npm run build 2>/dev/null || npx tsc 2>/dev/null || true
|
|
success "Server rebuilt"
|
|
|
|
step "Restarting service"
|
|
systemctl restart nixpanel
|
|
sleep 3
|
|
systemctl is-active nixpanel && success "nixpanel restarted" || error "nixpanel failed to start — check: journalctl -u nixpanel -n 50"
|
|
|
|
echo ""
|
|
echo -e "${BOLD}${GREEN}NixPanel updated successfully!${RESET}"
|
|
echo ""
|