|
1 | | -#!/usr/bin/env bash |
2 | | -# ------------------------------------------------------------------------------ |
3 | | -# Installer for PVESciptslocal |
4 | | -# Author: Canbiz |
5 | | -# ------------------------------------------------------------------------------ |
6 | | - |
7 | | -set -euo pipefail |
8 | | - |
9 | | -# Colors |
10 | | -RD=$(echo -e "\033[01;31m") |
11 | | -GN=$(echo -e "\033[1;92m") |
12 | | -YW=$(echo -e "\033[33m") |
13 | | -CL=$(echo -e "\033[m") |
14 | | - |
15 | | -# Status functions |
16 | | -msg_info() { echo -e "⏳ $YW$1$CL"; } |
17 | | -msg_ok() { echo -e "✔️ $GN$1$CL"; } |
18 | | -msg_err() { echo -e "❌ $RD$1$CL"; } |
19 | | - |
20 | | -# --- Check Proxmox VE environment --- |
21 | | -if ! command -v pveversion >/dev/null 2>&1; then |
22 | | - msg_err "This script must be executed on a Proxmox VE host." |
23 | | - exit 1 |
24 | | -fi |
25 | | -msg_ok "Proxmox VE detected: $(pveversion)" |
26 | | - |
27 | | -# --- Check git --- |
28 | | -if ! command -v git >/dev/null 2>&1; then |
29 | | - msg_info "Git not found, installing..." |
30 | | - apt-get update |
31 | | - apt-get install -y git |
32 | | - msg_ok "Git installed: $(git --version)" |
33 | | -else |
34 | | - msg_ok "Git already available: $(git --version)" |
35 | | -fi |
36 | | - |
37 | | -# --- Check Node.js --- |
38 | | -if ! command -v node >/dev/null 2>&1; then |
39 | | - msg_info "Node.js not found, installing Node.js 24.x..." |
40 | | - curl -fsSL https://deb.nodesource.com/setup_24.x | bash - |
41 | | - apt-get install -y nodejs |
42 | | - msg_ok "Node.js installed: $(node -v)" |
43 | | -else |
44 | | - msg_ok "Node.js already available: $(node -v)" |
45 | | -fi |
46 | | - |
47 | | -# --- Ask for installation path --- |
48 | | -read -rp "Installation directory [default: /opt/PVESciptslocal]: " INSTALL_DIR |
49 | | -INSTALL_DIR=${INSTALL_DIR:-/opt/PVESciptslocal} |
50 | | - |
51 | | -# --- Clone or update repository --- |
52 | | -if [ ! -d "$INSTALL_DIR/.git" ]; then |
53 | | - msg_info "Cloning repository into $INSTALL_DIR..." |
54 | | - git clone https://github.com/michelroegl-brunner/PVESciptslocal.git "$INSTALL_DIR" |
55 | | - msg_ok "Repository cloned." |
56 | | -else |
57 | | - msg_info "Directory already exists. Pulling latest changes..." |
58 | | - git -C "$INSTALL_DIR" pull |
59 | | - msg_ok "Repository updated." |
60 | | -fi |
61 | | - |
62 | | -cd "$INSTALL_DIR" |
63 | | - |
64 | | -# --- Install dependencies --- |
65 | | -msg_info "Installing dependencies..." |
66 | | -npm install |
67 | | -msg_ok "Dependencies installed." |
68 | | - |
69 | | -# --- Environment file --- |
70 | | -if [ ! -f .env ]; then |
71 | | - msg_info "Creating environment file from example..." |
72 | | - cp .env.example .env |
73 | | - msg_ok ".env file created." |
74 | | -else |
75 | | - msg_ok ".env file already exists, keeping it." |
76 | | -fi |
77 | | - |
78 | | -# --- Build the application --- |
79 | | -msg_info "Building application..." |
80 | | -npm run build |
81 | | -msg_ok "Build completed." |
82 | | - |
83 | | -# --- Start the application --- |
84 | | -read -rp "Do you want to start the application now? (y/N): " START_APP |
85 | | -if [[ "$START_APP" =~ ^[Yy]$ ]]; then |
86 | | - msg_info "Starting application..." |
87 | | - npm start |
88 | | -else |
89 | | - msg_info "You can start the app anytime by running: cd $INSTALL_DIR && npm start" |
90 | | -fi |
| 1 | +#!/usr/bin/env bash |
| 2 | +# ------------------------------------------------------------------------------ |
| 3 | +# Installer for PVESciptslocal with systemd integration |
| 4 | +# ------------------------------------------------------------------------------ |
| 5 | + |
| 6 | +set -euo pipefail |
| 7 | + |
| 8 | +# --- Core --------------------------------------------------------------------- |
| 9 | +RD=$(echo -e "\033[01;31m") |
| 10 | +GN=$(echo -e "\033[1;92m") |
| 11 | +YW=$(echo -e "\033[33m") |
| 12 | +CL=$(echo -e "\033[m") |
| 13 | + |
| 14 | +msg_info() { echo -e "⏳ $YW$1$CL"; } |
| 15 | +msg_ok() { echo -e "✔️ $GN$1$CL"; } |
| 16 | +msg_err() { echo -e "❌ $RD$1$CL"; } |
| 17 | + |
| 18 | +# --- PVE Check ---------------------------------------------------------------- |
| 19 | +check_pve() { |
| 20 | + if ! command -v pveversion >/dev/null 2>&1; then |
| 21 | + msg_err "This script must be executed on a Proxmox VE host." |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + msg_ok "Proxmox VE detected: $(pveversion)" |
| 25 | +} |
| 26 | + |
| 27 | +# --- Dependency Check & Install ----------------------------------------------- |
| 28 | +check_dependencies() { |
| 29 | + msg_info "Checking required packages (build-essential, git)..." |
| 30 | + apt-get update |
| 31 | + apt-get install -y build-essential git |
| 32 | + msg_ok "Dependencies installed." |
| 33 | +} |
| 34 | + |
| 35 | +check_nodejs() { |
| 36 | + if ! command -v node >/dev/null 2>&1; then |
| 37 | + msg_info "Node.js not found, installing Node.js 24.x..." |
| 38 | + curl -fsSL https://deb.nodesource.com/setup_24.x | bash - |
| 39 | + apt-get install -y nodejs |
| 40 | + msg_ok "Node.js installed: $(node -v)" |
| 41 | + else |
| 42 | + msg_ok "Node.js already available: $(node -v)" |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +# --- Repository Handling ------------------------------------------------------ |
| 47 | +clone_or_update_repo() { |
| 48 | + read -rp "Installation directory [default: /opt/PVESciptslocal]: " INSTALL_DIR |
| 49 | + INSTALL_DIR=${INSTALL_DIR:-/opt/PVESciptslocal} |
| 50 | + |
| 51 | + if [ ! -d "$INSTALL_DIR/.git" ]; then |
| 52 | + msg_info "Cloning repository into $INSTALL_DIR..." |
| 53 | + git clone https://github.com/michelroegl-brunner/PVESciptslocal.git "$INSTALL_DIR" |
| 54 | + msg_ok "Repository cloned." |
| 55 | + else |
| 56 | + msg_info "Directory already exists. Pulling latest changes..." |
| 57 | + git -C "$INSTALL_DIR" pull |
| 58 | + msg_ok "Repository updated." |
| 59 | + fi |
| 60 | + |
| 61 | + cd "$INSTALL_DIR" |
| 62 | +} |
| 63 | + |
| 64 | +# --- Application Setup -------------------------------------------------------- |
| 65 | +setup_app() { |
| 66 | + msg_info "Installing npm dependencies..." |
| 67 | + npm install |
| 68 | + msg_ok "Dependencies installed." |
| 69 | + |
| 70 | + if [ ! -f .env ]; then |
| 71 | + msg_info "Creating environment file from example..." |
| 72 | + cp .env.example .env |
| 73 | + msg_ok ".env file created." |
| 74 | + else |
| 75 | + msg_ok ".env file already exists, keeping it." |
| 76 | + fi |
| 77 | + |
| 78 | + msg_info "Building application..." |
| 79 | + npm run build |
| 80 | + msg_ok "Build completed." |
| 81 | +} |
| 82 | + |
| 83 | +# --- Systemd Service ---------------------------------------------------------- |
| 84 | +setup_systemd_service() { |
| 85 | + SERVICE_NAME="pvescriptslocal" |
| 86 | + SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service" |
| 87 | + |
| 88 | + msg_info "Creating systemd service at $SERVICE_FILE..." |
| 89 | + cat > "$SERVICE_FILE" <<EOF |
| 90 | +[Unit] |
| 91 | +Description=PVEScriptslocal Service |
| 92 | +After=network.target |
| 93 | +
|
| 94 | +[Service] |
| 95 | +WorkingDirectory=${INSTALL_DIR} |
| 96 | +ExecStart=/usr/bin/npm start |
| 97 | +Restart=always |
| 98 | +RestartSec=10 |
| 99 | +Environment=NODE_ENV=production |
| 100 | +User=root |
| 101 | +
|
| 102 | +[Install] |
| 103 | +WantedBy=multi-user.target |
| 104 | +EOF |
| 105 | + |
| 106 | + systemctl daemon-reexec |
| 107 | + msg_ok "Systemd service created." |
| 108 | + |
| 109 | + read -rp "Enable and start the service now? (y/N): " START_SERVICE |
| 110 | + if [[ "$START_SERVICE" =~ ^[Yy]$ ]]; then |
| 111 | + systemctl enable --now "$SERVICE_NAME" |
| 112 | + msg_ok "Service enabled and started." |
| 113 | + else |
| 114 | + msg_info "You can start it manually with: systemctl start $SERVICE_NAME" |
| 115 | + fi |
| 116 | + |
| 117 | + echo |
| 118 | + echo "---------------------------------------------" |
| 119 | + echo " Service installed: $SERVICE_NAME" |
| 120 | + echo " Manage it with:" |
| 121 | + echo " systemctl start $SERVICE_NAME" |
| 122 | + echo " systemctl stop $SERVICE_NAME" |
| 123 | + echo " systemctl status $SERVICE_NAME" |
| 124 | + echo " App will be available at: http://<IP>:3000" |
| 125 | + echo "---------------------------------------------" |
| 126 | +} |
| 127 | + |
| 128 | +# --- Main --------------------------------------------------------------------- |
| 129 | +main() { |
| 130 | + check_pve |
| 131 | + check_dependencies |
| 132 | + check_nodejs |
| 133 | + clone_or_update_repo |
| 134 | + setup_app |
| 135 | + setup_systemd_service |
| 136 | +} |
| 137 | + |
| 138 | +main "$@" |
0 commit comments