-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·60 lines (51 loc) · 2.48 KB
/
update.sh
File metadata and controls
executable file
·60 lines (51 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env bash
# update.sh — update a self-hosted pm2-hawkeye installation to the latest version.
#
# Usage:
# chmod +x update.sh
# ./update.sh
#
# What it does:
# 1. Pulls the latest commits from the upstream repository (fast-forward only).
# 2. Installs / updates Node.js dependencies.
# 3. Rebuilds the frontend bundle.
# 4. Restarts the pm2-hawkeye process under PM2 (if running).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── Colour helpers ────────────────────────────────────────────────────────────
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Colour
info() { echo -e "${GREEN}[update]${NC} $*"; }
warn() { echo -e "${YELLOW}[update]${NC} $*"; }
die() { echo -e "${RED}[update] ERROR:${NC} $*" >&2; exit 1; }
# ── 1. Pull latest changes ────────────────────────────────────────────────────
info "Pulling latest changes..."
if ! git diff --quiet || ! git diff --cached --quiet; then
die "Working directory has uncommitted changes. Commit or stash them first."
fi
git pull --ff-only || die "git pull failed — resolve any conflicts and try again."
# ── 2. Install / update dependencies ─────────────────────────────────────────
info "Installing dependencies..."
if command -v yarn &>/dev/null; then
yarn install --frozen-lockfile
else
npm ci
fi
# ── 3. Build frontend ─────────────────────────────────────────────────────────
info "Building frontend..."
npm run build
# ── 4. Restart pm2-hawkeye ───────────────────────────────────────────────────
if command -v pm2 &>/dev/null && pm2 describe pm2-hawkeye &>/dev/null 2>&1; then
info "Restarting pm2-hawkeye via PM2..."
pm2 restart pm2-hawkeye
pm2 save
info "Done. pm2-hawkeye is running the latest version."
else
warn "pm2-hawkeye is not running under PM2."
warn "Start it manually with:"
warn " pm2 start lib/transport/server.js --name pm2-hawkeye"
warn " pm2 save"
fi