Skip to content

Commit 9d2a1a1

Browse files
install.sh
1 parent 433d812 commit 9d2a1a1

File tree

1 file changed

+136
-137
lines changed

1 file changed

+136
-137
lines changed

install.sh

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

0 commit comments

Comments
 (0)