Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·397 lines (357 loc) · 14.6 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·397 lines (357 loc) · 14.6 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/usr/bin/env bash
set -e
# ==============================================================================
# Fire PM — Automated Installer & System Prerequisite Checker
# Supports both:
# 1) Standalone execution: sudo ./install.sh
# 2) One-liner curl pipe: curl -fsSL <url> | sudo bash
# ==============================================================================
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
NODE_VERSION="22.16.0"
echo -e "${CYAN}${BOLD}"
echo " ▄████████ ▄█ ███▄▄▄▄ ▄████████ "
echo " ███ ███ ███ ███▀▀▀██▄ ███ ███ "
echo " ███ █▀ ███▌ ███ ███ ███ █▀ "
echo " ▄███▄▄▄ ███▌ ███ ███ ▄███▄▄▄ "
echo " ▀▀███▀▀▀ ███▌ ███ ███ ▀▀███▀▀▀ "
echo " ███ ███ ███ ███ ███ █▄ "
echo " ███ ███ ███ ███ ███ ███ "
echo " ███ █▀ ▀█ █▀ ████████▀ "
echo -e "${NC}"
echo -e "${BOLD}Fire PM — Linux Process & Application Management Platform${NC}"
echo -e "${CYAN}================================================================${NC}"
echo ""
# 1. Root Check
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}✖ This installer must be run as root (use: sudo ./install.sh or curl ... | sudo bash)${NC}"
exit 1
fi
SCRIPT_DIR=""
if [[ -n "${BASH_SOURCE[0]}" && -f "${BASH_SOURCE[0]}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
# Parse options and environment variables for Web UI installation
INSTALL_WEB=""
if [[ -n "$FIRE_INSTALL_WEB" ]]; then
if [[ "$FIRE_INSTALL_WEB" =~ ^([yY][eE][sS]|[tT][rR][uU][eE]|1)$ ]]; then
INSTALL_WEB=true
elif [[ "$FIRE_INSTALL_WEB" =~ ^([nN][oO]|[fF][aA][lL][sS][eE]|0)$ ]]; then
INSTALL_WEB=false
fi
fi
FORCE_INSTALL=false
for arg in "$@"; do
case "$arg" in
--with-web)
INSTALL_WEB=true
;;
--no-web|--without-web)
INSTALL_WEB=false
;;
--force|-f)
FORCE_INSTALL=true
;;
-h|--help)
echo "Usage: sudo ./install.sh [options]"
echo ""
echo "Options:"
echo " --with-web Build and configure the Web UI Dashboard"
echo " --no-web Skip building the Web UI Dashboard (CLI & TUI only)"
echo " --force, -f Force overwrite unstaged local modifications"
echo " -h, --help Show this help message"
exit 0
;;
esac
done
# Package manager helper
install_package() {
local pkg="$1"
if command -v apt-get &>/dev/null; then
DEBIAN_FRONTEND=noninteractive apt-get install -y "$pkg" &>/dev/null || true
elif command -v dnf &>/dev/null; then
dnf install -y "$pkg" &>/dev/null || true
elif command -v yum &>/dev/null; then
yum install -y "$pkg" &>/dev/null || true
elif command -v pacman &>/dev/null; then
pacman -Sy --noconfirm "$pkg" &>/dev/null || true
elif command -v zypper &>/dev/null; then
zypper install -y "$pkg" &>/dev/null || true
elif command -v apk &>/dev/null; then
apk add "$pkg" &>/dev/null || true
fi
}
# Prompt user for Web UI installation if not specified via flag or env var
if [[ -z "$INSTALL_WEB" ]]; then
echo -ne "${CYAN}? Would you like to build and configure the Web UI Dashboard? (takes ~2-3 mins) (y/n): ${NC}"
user_choice=""
if [[ -t 0 ]]; then
read -r user_choice
elif [[ -r /dev/tty ]] && ( exec 2>/dev/null; read -r user_choice < /dev/tty ) 2>/dev/null; then
:
else
echo "n (headless mode)"
user_choice="n"
fi
case "$user_choice" in
[yY]|[yY][eE][sS])
INSTALL_WEB=true
;;
*)
INSTALL_WEB=false
;;
esac
fi
echo ""
echo -e "${CYAN}Checking and installing system prerequisites...${NC}"
# 2. Check systemd / systemctl
if ! command -v systemctl &>/dev/null; then
echo -e " ${YELLOW}⚠ systemd not found. Attempting to install systemd...${NC}"
install_package "systemd"
install_package "systemd-sysv"
if ! command -v systemctl &>/dev/null; then
echo -e " ${RED}✖ Could not find or install systemd.${NC}"
echo -e " Fire PM requires a Linux system with systemd init."
echo -e " If you are running in a Docker container, ensure systemd init is enabled."
exit 1
fi
fi
echo -e " ${GREEN}✔${NC} systemd / systemctl is active"
# 3. Check core CLI utilities
if ! command -v ps &>/dev/null; then
echo -e " ${YELLOW}Installing procps (ps)...${NC}"
install_package "procps"
fi
if ! command -v ss &>/dev/null; then
echo -e " ${YELLOW}Installing iproute2 (ss)...${NC}"
install_package "iproute2"
fi
if ! command -v curl &>/dev/null; then
install_package "curl"
fi
if ! command -v git &>/dev/null; then
install_package "git"
fi
if ! command -v tar &>/dev/null; then
install_package "tar"
fi
# 4. Check Python 3 and pip / venv
if ! command -v python3 &>/dev/null; then
echo -e " ${YELLOW}Installing python3...${NC}"
install_package "python3"
fi
if ! command -v pip3 &>/dev/null && ! command -v pip &>/dev/null; then
echo -e " ${YELLOW}Installing python3-pip & python3-venv...${NC}"
install_package "python3-pip"
install_package "python3-venv"
fi
# 5. Check Node.js & pnpm (only if Web UI is requested)
if [[ "$INSTALL_WEB" == "true" ]]; then
NEED_NODE=false
if ! command -v node &>/dev/null; then
NEED_NODE=true
else
NODE_MAJOR=$(node -v 2>/dev/null | sed 's/^v//' | cut -d. -f1)
if [[ -z "$NODE_MAJOR" || "$NODE_MAJOR" -lt 22 ]]; then
echo -e " ${YELLOW}⚠ Node.js v${NODE_MAJOR:-unknown} detected, but v22+ is required. Upgrading...${NC}"
NEED_NODE=true
fi
fi
if [[ "$NEED_NODE" == "true" ]]; then
echo -e " ${CYAN}Installing Node.js v${NODE_VERSION} (official binary)...${NC}"
ARCH=$(uname -m)
case "$ARCH" in
x86_64) NODE_ARCH="x64" ;;
aarch64) NODE_ARCH="arm64" ;;
armv7l) NODE_ARCH="armv7l" ;;
*)
echo -e " ${RED}✖ Unsupported architecture: ${ARCH}${NC}"
echo -e " Please install Node.js v22+ manually: https://nodejs.org/en/download"
;;
esac
if [[ -n "$NODE_ARCH" ]]; then
NODE_TARBALL="node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz"
NODE_URL="https://nodejs.org/dist/v${NODE_VERSION}/${NODE_TARBALL}"
TMP_DIR=$(mktemp -d)
if curl -fsSL "$NODE_URL" -o "${TMP_DIR}/${NODE_TARBALL}"; then
tar -xJf "${TMP_DIR}/${NODE_TARBALL}" -C "${TMP_DIR}"
cp -rf "${TMP_DIR}/node-v${NODE_VERSION}-linux-${NODE_ARCH}"/bin/* /usr/local/bin/
cp -rf "${TMP_DIR}/node-v${NODE_VERSION}-linux-${NODE_ARCH}"/lib/* /usr/local/lib/ 2>/dev/null || true
cp -rf "${TMP_DIR}/node-v${NODE_VERSION}-linux-${NODE_ARCH}"/include/* /usr/local/include/ 2>/dev/null || true
cp -rf "${TMP_DIR}/node-v${NODE_VERSION}-linux-${NODE_ARCH}"/share/* /usr/local/share/ 2>/dev/null || true
rm -rf "${TMP_DIR}"
hash -r
echo -e " ${GREEN}✔${NC} Node.js $(node -v) installed to /usr/local/bin/node"
else
rm -rf "${TMP_DIR}"
echo -e " ${RED}✖ Failed to download Node.js v${NODE_VERSION}.${NC}"
echo -e " Please install manually: https://nodejs.org/en/download"
fi
fi
fi
# Check pnpm
if command -v node &>/dev/null && ! command -v pnpm &>/dev/null; then
echo -e " ${CYAN}Installing pnpm package manager...${NC}"
if command -v corepack &>/dev/null; then
corepack enable &>/dev/null || true
corepack prepare pnpm@latest --activate &>/dev/null || npm install -g pnpm &>/dev/null || true
else
npm install -g pnpm &>/dev/null || true
fi
fi
fi
echo -e " ${GREEN}✔${NC} System dependencies verified"
echo ""
# Determine source directory (local clone or pull into /opt/fire-pm)
INSTALL_SOURCE_DIR=""
if [[ -n "$SCRIPT_DIR" && -f "${SCRIPT_DIR}/app/fire" ]]; then
INSTALL_SOURCE_DIR="${SCRIPT_DIR}"
else
TARGET_OPT_DIR="/opt/fire-pm"
echo -e "${CYAN}Setting up Fire PM repository in ${TARGET_OPT_DIR}...${NC}"
mkdir -p /opt
if [[ -d "${TARGET_OPT_DIR}/.git" ]]; then
if [[ "$FORCE_INSTALL" == "true" ]]; then
git -C "${TARGET_OPT_DIR}" fetch --all --prune &>/dev/null || true
git -C "${TARGET_OPT_DIR}" checkout main 2>/dev/null || git -C "${TARGET_OPT_DIR}" checkout master 2>/dev/null || true
git -C "${TARGET_OPT_DIR}" reset --hard origin/main 2>/dev/null || git -C "${TARGET_OPT_DIR}" reset --hard origin/master 2>/dev/null || true
git -C "${TARGET_OPT_DIR}" clean -fd &>/dev/null || true
else
if ! git -C "${TARGET_OPT_DIR}" pull --ff-only &>/dev/null; then
# Reset local unstaged/untracked modifications to allow clean upgrade
git -C "${TARGET_OPT_DIR}" fetch --all --prune &>/dev/null || true
git -C "${TARGET_OPT_DIR}" checkout main 2>/dev/null || git -C "${TARGET_OPT_DIR}" checkout master 2>/dev/null || true
git -C "${TARGET_OPT_DIR}" reset --hard origin/main 2>/dev/null || git -C "${TARGET_OPT_DIR}" reset --hard origin/master 2>/dev/null || true
git -C "${TARGET_OPT_DIR}" clean -fd &>/dev/null || true
fi
fi
else
git clone https://github.com/Fire-Package/fire-pm.git "${TARGET_OPT_DIR}"
fi
INSTALL_SOURCE_DIR="${TARGET_OPT_DIR}"
fi
# 7. Install CLI binary
echo -e "${CYAN}1/4 Installing Fire CLI engine...${NC}"
cp "${INSTALL_SOURCE_DIR}/app/fire" /usr/local/bin/fire.tmp
chmod +x /usr/local/bin/fire.tmp
mv -f /usr/local/bin/fire.tmp /usr/local/bin/fire
if [[ -f "${INSTALL_SOURCE_DIR}/app/ff-service" ]]; then
cp "${INSTALL_SOURCE_DIR}/app/ff-service" /usr/local/bin/ff-service.tmp
chmod +x /usr/local/bin/ff-service.tmp
mv -f /usr/local/bin/ff-service.tmp /usr/local/bin/ff-service
fi
if [[ -f "${INSTALL_SOURCE_DIR}/app/fire_ssh.py" ]]; then
cp "${INSTALL_SOURCE_DIR}/app/fire_ssh.py" /usr/local/bin/fire_ssh.py.tmp
chmod +x /usr/local/bin/fire_ssh.py.tmp
mv -f /usr/local/bin/fire_ssh.py.tmp /usr/local/bin/fire_ssh.py
fi
# Configure sudoers rule so fire can manage systemd without password prompts
if [[ -d "/etc/sudoers.d" ]]; then
SUDOERS_FILE="/etc/sudoers.d/fire-pm"
{
echo "# Fire PM — Allow administrative users to manage fire services without password prompt"
echo "%sudo ALL=(ALL) NOPASSWD: /usr/local/bin/fire"
echo "%wheel ALL=(ALL) NOPASSWD: /usr/local/bin/fire"
if [[ -n "$SUDO_USER" && "$SUDO_USER" != "root" ]]; then
echo "$SUDO_USER ALL=(ALL) NOPASSWD: /usr/local/bin/fire"
fi
} > "$SUDOERS_FILE"
chmod 0440 "$SUDOERS_FILE"
if command -v visudo &>/dev/null; then
if ! visudo -c -f "$SUDOERS_FILE" &>/dev/null; then
rm -f "$SUDOERS_FILE"
fi
fi
fi
echo -e " ${GREEN}✔${NC} Fire CLI installed to /usr/local/bin/fire"
# Install Shell Auto-Completion
if [[ -d "/etc/bash_completion.d" ]]; then
/usr/local/bin/fire completion bash > /etc/bash_completion.d/fire 2>/dev/null || true
chmod 644 /etc/bash_completion.d/fire 2>/dev/null || true
elif [[ -d "/usr/share/bash-completion/completions" ]]; then
/usr/local/bin/fire completion bash > /usr/share/bash-completion/completions/fire 2>/dev/null || true
fi
echo -e " ${GREEN}✔${NC} Shell auto-completion configured"
# 8. Install TUI
echo -e "${CYAN}2/4 Installing Terminal UI (TUI)...${NC}"
cp "${INSTALL_SOURCE_DIR}/tui/fire_tui.py" /usr/local/bin/fire_tui.py
chmod +x /usr/local/bin/fire_tui.py
# Install Python requirements for TUI
REQUIREMENTS_FILE="${INSTALL_SOURCE_DIR}/tui/requirements.txt"
PIP_CMD=""
if command -v pip3 &>/dev/null; then
PIP_CMD="pip3"
elif command -v pip &>/dev/null; then
PIP_CMD="pip"
fi
if [[ -n "$PIP_CMD" ]]; then
if [[ -f "$REQUIREMENTS_FILE" ]]; then
$PIP_CMD install -r "$REQUIREMENTS_FILE" &>/dev/null || \
$PIP_CMD install --break-system-packages -r "$REQUIREMENTS_FILE" &>/dev/null || true
else
$PIP_CMD install "textual>=0.70.0" &>/dev/null || \
$PIP_CMD install --break-system-packages "textual>=0.70.0" &>/dev/null || true
fi
fi
if python3 -c "import textual" &>/dev/null; then
echo -e " ${GREEN}✔${NC} Fire TUI and dependencies installed"
else
echo -e " ${YELLOW}⚠${NC} Fire TUI installed to /usr/local/bin/fire_tui.py"
echo -e " ${GREY}(Run 'pip3 install textual' if TUI does not start)${NC}"
fi
# 9. Install Systemd templates
echo -e "${CYAN}3/4 Registering Systemd templates...${NC}"
mkdir -p /etc/systemd/system /etc/fire-pm
chmod 0700 /etc/fire-pm
if [[ -f "${INSTALL_SOURCE_DIR}/shared/units/fire-reload@.service" ]]; then
cp "${INSTALL_SOURCE_DIR}/shared/units/fire-reload@.service" /etc/systemd/system/
fi
systemctl daemon-reload
echo -e " ${GREEN}✔${NC} Systemd unit templates registered"
# 10. Web UI Build or Skip
if [[ "$INSTALL_WEB" == "true" ]]; then
echo -e "${CYAN}4/4 Building Web UI Dashboard & API...${NC}"
if [[ -d "${INSTALL_SOURCE_DIR}/web" ]]; then
cd "${INSTALL_SOURCE_DIR}/web"
if command -v pnpm &>/dev/null; then
pnpm install --prod=false
pnpm build
elif command -v npm &>/dev/null; then
npm install
npm run build
else
echo -e " ${YELLOW}⚠ Node.js not found. Install Node.js (v22+) to run the Web UI.${NC}"
fi
chmod +x "${INSTALL_SOURCE_DIR}/web/start.sh" 2>/dev/null || true
echo -e " ${GREEN}✔${NC} Web UI built successfully"
fi
else
echo -e "${CYAN}4/4 Web UI Dashboard build skipped${NC}"
if [[ -f "${INSTALL_SOURCE_DIR}/web/start.sh" ]]; then
chmod +x "${INSTALL_SOURCE_DIR}/web/start.sh" 2>/dev/null || true
fi
fi
echo ""
echo -e "${GREEN}${BOLD}✔ Fire PM installation completed successfully!${NC}"
echo -e "${CYAN}================================================================${NC}"
echo -e " ${BOLD}Commands:${NC}"
echo -e " ${YELLOW}fire${NC} — Launch interactive dashboard"
echo -e " ${YELLOW}fire start <file>${NC} — Start a Python/Node.js/Bash service"
echo -e " ${YELLOW}fire list${NC} — List all managed processes"
echo -e " ${YELLOW}fire tunnel open <p>${NC} — Expose local port via reverse proxy"
echo -e " ${YELLOW}fire doctor${NC} — Run system diagnostics"
echo ""
if [[ "$INSTALL_WEB" == "true" ]]; then
echo -e " ${BOLD}Start Web UI Dashboard:${NC}"
echo -e " ${CYAN}fire start ${INSTALL_SOURCE_DIR}/web/start.sh --name fire-web --env PORT=3000${NC}"
else
echo -e " ${BOLD}Web UI Dashboard (Optional):${NC}"
echo -e " To build and start the Web UI at any time:"
echo -e " ${CYAN}cd ${INSTALL_SOURCE_DIR}/web && pnpm install && pnpm build${NC}"
echo -e " ${CYAN}fire start ${INSTALL_SOURCE_DIR}/web/start.sh --name fire-web --env PORT=3000${NC}"
fi
echo ""