-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall_dependencies.sh
More file actions
executable file
·94 lines (81 loc) · 3.34 KB
/
Copy pathinstall_dependencies.sh
File metadata and controls
executable file
·94 lines (81 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# install_dependencies.sh — install optional helpers and global pman command for proxmox-manager
# Idempotent install script for Debian/Proxmox VE nodes.
#
# Optional packages installed:
# curl — general HTTP client
# git — version control
# sc-shellcheck — Bash static analysis (CI/dev)
# virt-viewer — SPICE/VNC viewer (for --spice workflow)
# jq — JSON processor (for --json output)
set -euo pipefail
# ---------------------------------------------------------------------------
# Root check — must run as root to install system packages
# ---------------------------------------------------------------------------
if [[ "${EUID:-$(id -u)}" -ne 0 ]]; then
printf 'Error: %s must be run as root.\n' "$(basename "$0")" >&2
printf 'Try: sudo %s\n' "$0" >&2
exit 1
fi
# ---------------------------------------------------------------------------
# Logging helpers
# ---------------------------------------------------------------------------
_log() { printf '[%s] %s\n' "$(date '+%H:%M:%S')" "$*"; }
_ok() { printf '[%s] OK: %s\n' "$(date '+%H:%M:%S')" "$*"; }
_err() { printf '[%s] Error: %s\n' "$(date '+%H:%M:%S')" "$*" >&2; }
# ---------------------------------------------------------------------------
# Detect package manager
# ---------------------------------------------------------------------------
if ! command -v apt-get >/dev/null 2>&1; then
_err "apt-get not found. This script requires a Debian-based system."
exit 1
fi
# ---------------------------------------------------------------------------
# Check which packages are already installed
# ---------------------------------------------------------------------------
PKGS=(curl git shellcheck virt-viewer jq)
MISSING=()
for pkg in "${PKGS[@]}"; do
if dpkg -s "$pkg" >/dev/null 2>&1; then
_log "Already installed: $pkg"
else
_log "Will install: $pkg"
MISSING+=("$pkg")
fi
done
# ---------------------------------------------------------------------------
# Install missing packages
# ---------------------------------------------------------------------------
if [[ "${#MISSING[@]}" -eq 0 ]]; then
_ok "All optional packages are already installed."
else
_log "Updating package lists..."
if ! apt-get update -qq; then
_err "apt-get update failed. Check your network connection or /etc/apt/sources.list."
exit 1
fi
_log "Installing: ${MISSING[*]}"
if ! apt-get install -y "${MISSING[@]}"; then
_err "Package installation failed for: ${MISSING[*]}"
exit 1
fi
_ok "Installed: ${MISSING[*]}"
fi
# ---------------------------------------------------------------------------
# Install pman — global symlink in /usr/local/bin
# ---------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
PMAN_SRC="${SCRIPT_DIR}/proxmox-manager.sh"
PMAN_DST="/usr/local/bin/pman"
if [[ ! -f "$PMAN_SRC" ]]; then
_err "proxmox-manager.sh not found at ${PMAN_SRC}. Run install_dependencies.sh from the repo root."
exit 1
fi
chmod +x "$PMAN_SRC"
if [[ -L "$PMAN_DST" && "$(readlink -f "$PMAN_DST")" == "$(readlink -f "$PMAN_SRC")" ]]; then
_log "pman already installed: ${PMAN_DST}"
else
ln -sf "$PMAN_SRC" "$PMAN_DST"
_ok "Installed: pman -> ${PMAN_SRC}"
fi
_ok "Done. All optional dependencies are available. Run 'pman' to start."