-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·93 lines (81 loc) · 2.87 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·93 lines (81 loc) · 2.87 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# SampleTown setup for a fresh Linux server (Ubuntu/Debian).
# Installs Node + pm2, clones the repo, builds, and starts the app under pm2.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/<owner>/SampleTown/main/setup.sh | bash
# # or locally:
# ./setup.sh
#
# Override defaults via env vars:
# APP_DIR install path (default: /opt/sampletown)
# PORT port pm2 will bind (default: 3000)
# NODE_VERSION major Node version to install (default: 20)
# REPO_URL git repo to clone (default: https://github.com/sampletown-org/edna-sampletown.git)
# BRANCH branch to check out (default: main)
set -euo pipefail
APP_DIR="${APP_DIR:-/opt/sampletown}"
PORT="${PORT:-3000}"
NODE_VERSION="${NODE_VERSION:-20}"
REPO_URL="${REPO_URL:-https://github.com/sampletown-org/edna-sampletown.git}"
BRANCH="${BRANCH:-main}"
echo "=== SampleTown Setup ==="
echo " app dir: $APP_DIR"
echo " port: $PORT"
echo " repo: $REPO_URL ($BRANCH)"
echo
# Node.js via NodeSource. Also installs a C toolchain + python3 so that
# native modules (better-sqlite3) can compile if npm doesn't find a
# prebuilt binary for the host's Node/arch combination.
if ! command -v node &>/dev/null; then
echo ">> Installing Node.js ${NODE_VERSION} + build tools..."
curl -fsSL "https://deb.nodesource.com/setup_${NODE_VERSION}.x" | sudo -E bash -
sudo apt-get install -y nodejs build-essential python3
fi
echo "Node: $(node --version)"
# pm2
if ! command -v pm2 &>/dev/null; then
echo ">> Installing pm2..."
sudo npm install -g pm2
fi
# App directory
sudo mkdir -p "$APP_DIR/data"
sudo chown -R "$(whoami):$(whoami)" "$APP_DIR"
# Clone or pull
if [ -d "$APP_DIR/.git" ]; then
echo ">> Pulling latest..."
cd "$APP_DIR"
git pull --ff-only origin "$BRANCH"
else
echo ">> Cloning $REPO_URL..."
git clone -b "$BRANCH" "$REPO_URL" "$APP_DIR"
cd "$APP_DIR"
fi
# Dependencies + build
echo ">> Installing dependencies..."
npm ci --production=false
echo ">> Building..."
npm run build
# .env (create template if missing)
if [ ! -f "$APP_DIR/.env" ]; then
echo ">> Creating .env template — edit $APP_DIR/.env before going to production"
cp "$APP_DIR/.env.example" "$APP_DIR/.env"
fi
# pm2
echo ">> Starting under pm2 on port $PORT..."
cd "$APP_DIR"
pm2 delete sampletown 2>/dev/null || true
env $(grep -v '^#' .env | grep -v '^$' | xargs) PORT="$PORT" HOST=0.0.0.0 \
pm2 start build/index.js --name sampletown
pm2 save
echo
echo ">> To enable auto-start on reboot, run the command pm2 prints below:"
pm2 startup | tail -1
echo
echo "=== Done! ==="
echo "App running on port $PORT"
echo "Logs: pm2 logs sampletown"
echo "Status: pm2 status"
echo
echo "Next: configure nginx to proxy your hostname to 127.0.0.1:$PORT"
echo " (see docs/DEPLOYMENT.md for an example server block)"