55
66set -euo pipefail
77
8- # Colors
8+ # --- Core ---------------------------------------------------------------------
99RD=$( echo -e " \033[01;31m" )
1010GN=$( echo -e " \033[1;92m" )
1111YW=$( echo -e " \033[33m" )
1212CL=$( echo -e " \033[m" )
1313
14- # Status functions
1514msg_info () { echo -e " ⏳ $YW $1 $CL " ; }
1615msg_ok () { echo -e " ✔️ $GN $1 $CL " ; }
1716msg_err () { echo -e " ❌ $RD $1 $CL " ; }
1817
19- # --- Check Proxmox VE environment ---
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- # --- Check git ---
27- if ! command -v git > /dev/null 2>&1 ; then
28- msg_info " Git not found, installing..."
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)..."
2930 apt-get update
30- apt-get install -y git
31- msg_ok " Git installed: $( git --version) "
32- else
33- msg_ok " Git already available: $( git --version) "
34- fi
35-
36- # --- Check Node.js ---
37- if ! command -v node > /dev/null 2>&1 ; then
38- msg_info " Node.js not found, installing Node.js 24.x..."
39- curl -fsSL https://deb.nodesource.com/setup_24.x | bash -
40- apt-get install -y nodejs
41- msg_ok " Node.js installed: $( node -v) "
42- else
43- msg_ok " Node.js already available: $( node -v) "
44- fi
45-
46- # --- Ask for installation path ---
47- read -rp " Installation directory [default: /opt/PVESciptslocal]: " INSTALL_DIR
48- INSTALL_DIR=${INSTALL_DIR:-/ opt/ PVESciptslocal}
49-
50- # --- Clone or update repository ---
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- # --- Install dependencies ---
64- msg_info " Installing dependencies..."
65- npm install
66- msg_ok " Dependencies installed."
67-
68- # --- Environment file ---
69- if [ ! -f .env ]; then
70- msg_info " Creating environment file from example..."
71- cp .env.example .env
72- msg_ok " .env file created."
73- else
74- msg_ok " .env file already exists, keeping it."
75- fi
76-
77- # --- Build the application ---
78- msg_info " Building application..."
79- npm run build
80- msg_ok " Build completed."
81-
82- # --- Create systemd service ---
83- SERVICE_NAME=" pvescriptslocal"
84- SERVICE_FILE=" /etc/systemd/system/${SERVICE_NAME} .service"
85-
86- msg_info " Creating systemd service at $SERVICE_FILE ..."
87- cat > " $SERVICE_FILE " << EOF
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
8890[Unit]
8991Description=PVEScriptslocal Service
9092After=network.target
@@ -101,24 +103,36 @@ User=root
101103WantedBy=multi-user.target
102104EOF
103105
104- systemctl daemon-reexec
105- msg_ok " Systemd service created and started."
106-
107- # --- Enable/Start Service ---
108- read -rp " Enable and start the service now? (y/N): " START_SERVICE
109- if [[ " $START_SERVICE " =~ ^[Yy]$ ]]; then
110- systemctl enable --now pvescriptslocal.service
111- msg_ok " Service enabled and started. Check status with: systemctl status pvescriptslocal"
112- else
113- msg_info " You can start it manually with: systemctl start pvescriptslocal"
114- fi
115-
116- echo
117- echo " ---------------------------------------------"
118- echo " Service installed: $SERVICE_NAME "
119- echo " Manage it with:"
120- echo " systemctl start $SERVICE_NAME "
121- echo " systemctl stop $SERVICE_NAME "
122- echo " systemctl status $SERVICE_NAME "
123- echo " App will be available at: http://<IP>:3000"
124- echo " ---------------------------------------------"
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