|
| 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 |
0 commit comments