Skip to content

Commit cc08395

Browse files
authored
Feature: Netdata support PVE9 (#7012)
1 parent d5093a3 commit cc08395

File tree

1 file changed

+83
-34
lines changed

1 file changed

+83
-34
lines changed

tools/addon/netdata.sh

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,93 @@ function msg_ok() {
3939
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
4040
}
4141

42+
function msg_error() { echo -e "${RD}$1${CL}"; }
43+
44+
pve_check() {
45+
if ! command -v pveversion >/dev/null 2>&1; then
46+
msg_error "This script can only be run on a Proxmox VE host."
47+
exit 1
48+
fi
49+
50+
local PVE_VER
51+
PVE_VER="$(pveversion | awk -F'/' '{print $2}' | awk -F'-' '{print $1}')"
52+
53+
# Proxmox VE 8.x: allow 8.0 – 8.9
54+
if [[ "$PVE_VER" =~ ^9\.([0-9]+)(\.[0-9]+)?$ ]]; then
55+
local MINOR="${BASH_REMATCH[1]}"
56+
if ((MINOR != 0)); then
57+
msg_error "Unsupported Proxmox VE version: $PVE_VER"
58+
msg_error "Supported versions: 8.0 – 8.9 or 9.0.x"
59+
exit 1
60+
fi
61+
return 0
62+
fi
63+
64+
# Proxmox VE 9.x: allow only 9.0
65+
if [[ "$PVE_VER" =~ ^9\.([0-9]+)$ ]]; then
66+
local MINOR="${BASH_REMATCH[1]}"
67+
if ((MINOR != 0)); then
68+
msg_error "Unsupported Proxmox VE version: $PVE_VER"
69+
msg_error "Supported versions: 8.0 – 8.9 or 9.0"
70+
exit 1
71+
fi
72+
return 0
73+
fi
74+
75+
msg_error "Unsupported Proxmox VE version: $PVE_VER"
76+
msg_error "Supported versions: 8.0 – 8.9 or 9.0"
77+
exit 1
78+
}
79+
80+
detect_codename() {
81+
source /etc/os-release
82+
if [[ "$ID" != "debian" ]]; then
83+
msg_error "Unsupported base OS: $ID (only Proxmox VE / Debian supported)."
84+
exit 1
85+
fi
86+
CODENAME="${VERSION_CODENAME:-}"
87+
if [[ -z "$CODENAME" ]]; then
88+
msg_error "Could not detect Debian codename."
89+
exit 1
90+
fi
91+
echo "$CODENAME"
92+
}
93+
94+
get_latest_repo_pkg() {
95+
local REPO_URL=$1
96+
curl -fsSL "$REPO_URL" |
97+
grep -oP 'netdata-repo_[^"]+all\.deb' |
98+
sort -V |
99+
tail -n1
100+
}
101+
42102
install() {
43103
header_info
44104
while true; do
45-
read -p "Are you sure you want to install NetData on Proxmox VE host. Proceed(y/n)?" yn
105+
read -p "Are you sure you want to install NetData on Proxmox VE host. Proceed(y/n)? " yn
46106
case $yn in
47107
[Yy]*) break ;;
48108
[Nn]*) exit ;;
49109
*) echo "Please answer yes or no." ;;
50110
esac
51111
done
52-
header_info
112+
53113
read -r -p "Verbose mode? <y/N> " prompt
54-
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
55-
STD=""
56-
else
57-
STD="silent"
58-
fi
59-
header_info
114+
[[ ${prompt,,} =~ ^(y|yes)$ ]] && STD="" || STD="silent"
115+
116+
CODENAME=$(detect_codename)
117+
REPO_URL="https://repo.netdata.cloud/repos/repoconfig/debian/${CODENAME}/"
60118

61119
msg_info "Setting up repository"
62120
$STD apt-get install -y debian-keyring
63-
curl -fsSL "https://repo.netdata.cloud/repos/repoconfig/debian/bookworm/netdata-repo_5-1+debian12_all.deb" -o $(basename "https://repo.netdata.cloud/repos/repoconfig/debian/bookworm/netdata-repo_5-1+debian12_all.deb")
64-
$STD dpkg -i netdata-repo_5-1+debian12_all.deb
65-
rm -rf netdata-repo_5-1+debian12_all.deb
121+
PKG=$(get_latest_repo_pkg "$REPO_URL")
122+
if [[ -z "$PKG" ]]; then
123+
msg_error "Could not find netdata-repo package for Debian $CODENAME"
124+
exit 1
125+
fi
126+
curl -fsSL "${REPO_URL}${PKG}" -o "$PKG"
127+
$STD dpkg -i "$PKG"
128+
rm -f "$PKG"
66129
msg_ok "Set up repository"
67130

68131
msg_info "Installing Netdata"
@@ -76,46 +139,32 @@ install() {
76139
uninstall() {
77140
header_info
78141
read -r -p "Verbose mode? <y/N> " prompt
79-
if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then
80-
STD=""
81-
else
82-
STD="silent"
83-
fi
84-
header_info
142+
[[ ${prompt,,} =~ ^(y|yes)$ ]] && STD="" || STD="silent"
85143

86144
msg_info "Uninstalling Netdata"
87-
systemctl stop netdata
145+
systemctl stop netdata || true
88146
rm -rf /var/log/netdata /var/lib/netdata /var/cache/netdata /etc/netdata/go.d
89147
rm -rf /etc/apt/trusted.gpg.d/netdata-archive-keyring.gpg /etc/apt/sources.list.d/netdata.list
90148
$STD apt-get remove --purge -y netdata netdata-repo
91149
systemctl daemon-reload
92150
$STD apt autoremove -y
93-
$STD userdel netdata
151+
$STD userdel netdata || true
94152
msg_ok "Uninstalled Netdata"
95153
msg_ok "Completed Successfully!\n"
96154
}
97155

98-
if ! pveversion | grep -Eq "pve-manager/8\.[0-4](\.[0-9]+)*"; then
99-
echo -e "This version of Proxmox Virtual Environment is not supported"
100-
echo -e "Requires PVE Version 8.0 or higher"
101-
echo -e "Exiting..."
102-
sleep 2
103-
exit
104-
fi
156+
header_info
157+
pve_check
105158

106159
OPTIONS=(Install "Install NetData on Proxmox VE"
107160
Uninstall "Uninstall NetData from Proxmox VE")
108161

109-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "NetData" --menu "Select an option:" 10 58 2 \
110-
"${OPTIONS[@]}" 3>&1 1>&2 2>&3)
162+
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "NetData" \
163+
--menu "Select an option:" 10 58 2 "${OPTIONS[@]}" 3>&1 1>&2 2>&3)
111164

112165
case $CHOICE in
113-
"Install")
114-
install
115-
;;
116-
"Uninstall")
117-
uninstall
118-
;;
166+
"Install") install ;;
167+
"Uninstall") uninstall ;;
119168
*)
120169
echo "Exiting..."
121170
exit 0

0 commit comments

Comments
 (0)