#!/bin/bash # --------------------------------------------------------------------- # pvesnap - Installation # # ./install.sh installieren, Dienst aktivieren und starten # ./install.sh --no-start installieren, aber Dienst nicht starten # ./install.sh --force auch ohne erkanntes Proxmox VE installieren # --------------------------------------------------------------------- set -euo pipefail LIB_DIR="/usr/lib/pvesnap" BIN="/usr/local/bin/pvesnap" CONF_DIR="/etc/pvesnap" CONF="${CONF_DIR}/pvesnap.conf" STATE_DIR="/var/lib/pvesnap" DOC_DIR="/usr/share/doc/pvesnap" UNIT="/etc/systemd/system/pvesnap.service" SRC="$(cd "$(dirname "$0")" && pwd)" START=1 FORCE=0 for arg in "$@"; do case "$arg" in --no-start) START=0 ;; --force) FORCE=1 ;; -h|--help) sed -n '2,8p' "$0" | sed 's/^#[[:space:]]\{0,1\}//'; exit 0 ;; *) echo "Unbekannte Option: $arg" >&2; exit 1 ;; esac done info() { printf '\033[1;32m==>\033[0m %s\n' "$*"; } warn() { printf '\033[1;33m==>\033[0m %s\n' "$*" >&2; } fail() { printf '\033[1;31m==>\033[0m %s\n' "$*" >&2; exit 1; } [ "$(id -u)" -eq 0 ] || fail "Bitte als root ausfuehren (sudo ./install.sh)." command -v python3 >/dev/null 2>&1 || fail "python3 wird benoetigt." python3 - <<'PY' || fail "Python 3.7 oder neuer wird benoetigt." import sys sys.exit(0 if sys.version_info >= (3, 7) else 1) PY if ! command -v pvesh >/dev/null 2>&1; then if [ "$FORCE" -eq 1 ]; then warn "pvesh nicht gefunden - installiere trotzdem (--force)." START=0 else fail "pvesh nicht gefunden. pvesnap gehoert auf einen Proxmox-VE-Host. Mit --force laesst sich die Installation trotzdem erzwingen." fi fi command -v systemctl >/dev/null 2>&1 || fail "systemd wird benoetigt." [ -d "${SRC}/pvesnap" ] || fail "Verzeichnis 'pvesnap' nicht gefunden (Aufruf aus dem Projektordner?)." # --- Programm --------------------------------------------------------- info "Installiere Programm nach ${LIB_DIR}" rm -rf "${LIB_DIR}/pvesnap" install -d -m 0755 "${LIB_DIR}" cp -r "${SRC}/pvesnap" "${LIB_DIR}/pvesnap" find "${LIB_DIR}/pvesnap" -name '__pycache__' -type d -exec rm -rf {} + 2>/dev/null || true chmod -R go-w "${LIB_DIR}/pvesnap" info "Installiere Startbefehl ${BIN}" cat > "${BIN}" </dev/null 2>&1; then info "Dienst beim Systemstart aktiviert" else warn "Dienst konnte nicht aktiviert werden - bitte 'systemctl enable pvesnap' pruefen." fi if [ "$START" -eq 1 ]; then info "Starte Dienst" systemctl restart pvesnap.service sleep 1 systemctl --no-pager --lines=5 status pvesnap.service || true else warn "Dienst wurde nicht gestartet." fi cat <