Skip to content

Commit d6e4980

Browse files
authored
Refactor: Post-PBS Script (#7213)
1 parent 4a69a7b commit d6e4980

File tree

1 file changed

+219
-100
lines changed

1 file changed

+219
-100
lines changed

tools/pve/post-pbs-install.sh

Lines changed: 219 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#!/usr/bin/env bash
22

3-
# Copyright (c) 2021-2025 tteck
4-
# Author: tteck (tteckster)
5-
# License: MIT
6-
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
3+
# Copyright (c) 2021-2025 community-scripts ORG
4+
# Author: tteck (tteckster) | MickLesk (CanbiZ) | thost96
5+
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
76

87
header_info() {
98
clear
109
cat <<"EOF"
1110
____ ____ _____ ____ __ ____ __ ____
1211
/ __ \/ __ ) ___/ / __ \____ _____/ /_ / _/___ _____/ /_____ _/ / /
13-
/ /_/ / __ \__ \ / /_/ / __ \/ ___/ __/ / // __ \/ ___/ __/ __ `/ / /
14-
/ ____/ /_/ /__/ / / ____/ /_/ (__ ) /_ _/ // / / (__ ) /_/ /_/ / / /
15-
/_/ /_____/____/ /_/ \____/____/\__/ /___/_/ /_/____/\__/\__,_/_/_/
12+
/ /_/ / __ \__ \ / /_/ / __ \/ ___/ __/ / // __ \/ ___/ __/ __ `/ / /
13+
/ ____/ /_/ /__/ / / ____/ /_/ (__ ) /_ _/ // / / (__ ) /_/ /_/ / / /
14+
/_/ /_____/____/ /_/ \____/____/\__/ /___/_/ /_/____/\__/\__,_/_/_/
1615
1716
EOF
1817
}
@@ -29,156 +28,276 @@ CROSS="${RD}✗${CL}"
2928
set -euo pipefail
3029
shopt -s inherit_errexit nullglob
3130

32-
msg_info() {
33-
local msg="$1"
34-
echo -ne " ${HOLD} ${YW}${msg}..."
31+
msg_info() { echo -ne " ${HOLD} ${YW}$1..."; }
32+
msg_ok() { echo -e "${BFR} ${CM} ${GN}$1${CL}"; }
33+
msg_error() { echo -e "${BFR} ${CROSS} ${RD}$1${CL}"; }
34+
35+
# ---- helpers ----
36+
get_pbs_codename() {
37+
awk -F'=' '/^VERSION_CODENAME=/{print $2}' /etc/os-release
38+
}
39+
40+
repo_state_list() {
41+
local repo="$1"
42+
local file=""
43+
local state="missing"
44+
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
45+
[[ -f "$f" ]] || continue
46+
if grep -q "$repo" "$f"; then
47+
file="$f"
48+
if grep -qE "^[^#].*${repo}" "$f"; then
49+
state="active"
50+
elif grep -qE "^#.*${repo}" "$f"; then
51+
state="disabled"
52+
fi
53+
break
54+
fi
55+
done
56+
echo "$state $file"
3557
}
3658

37-
msg_ok() {
38-
local msg="$1"
39-
echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
59+
component_exists_in_sources() {
60+
local component="$1"
61+
grep -h -E "^[^#]*Components:[^#]*\b${component}\b" /etc/apt/sources.list.d/*.sources 2>/dev/null | grep -q .
4062
}
4163

42-
msg_error() {
43-
local msg="$1"
44-
echo -e "${BFR} ${CROSS} ${RD}${msg}${CL}"
64+
# ---- main ----
65+
main() {
66+
header_info
67+
echo -e "\nThis script will Perform Post Install Routines.\n"
68+
while true; do
69+
read -rp "Start the Proxmox Backup Server Post Install Script (y/n)? " yn
70+
case $yn in
71+
[Yy]*) break ;;
72+
[Nn]*)
73+
clear
74+
exit
75+
;;
76+
*) echo "Please answer yes or no." ;;
77+
esac
78+
done
79+
80+
if command -v pveversion >/dev/null 2>&1; then
81+
echo -e "\n🛑 PVE Detected, Wrong Script!\n"
82+
exit 1
83+
fi
84+
85+
local CODENAME
86+
CODENAME="$(get_pbs_codename)"
87+
88+
case "$CODENAME" in
89+
bookworm) start_routines_3 ;;
90+
trixie) start_routines_4 ;;
91+
*)
92+
msg_error "Unsupported Debian codename: $CODENAME"
93+
echo -e "Supported: bookworm (PBS 3.x) and trixie (PBS 4.x)"
94+
exit 1
95+
;;
96+
esac
4597
}
4698

47-
start_routines() {
99+
# ---- PBS 3.x (Bookworm) ----
100+
start_routines_3() {
48101
header_info
49-
VERSION="$(awk -F'=' '/^VERSION_CODENAME=/{ print $NF }' /etc/os-release)"
50-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PBS SOURCES" --menu "This will set the correct sources to update and install Proxmox Backup Server.\n \nChange to Proxmox Backup Server sources?" 14 58 2 \
51-
"yes" " " \
52-
"no" " " 3>&2 2>&1 1>&3)
102+
local VERSION="bookworm"
103+
104+
# --- Debian sources ---
105+
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PBS SOURCES" --menu \
106+
"Correct Debian sources for Proxmox Backup Server 3.x?" 14 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
53107
case $CHOICE in
54108
yes)
55-
msg_info "Changing to Proxmox Backup Server Sources"
109+
msg_info "Correcting Debian Sources"
56110
cat <<EOF >/etc/apt/sources.list
57111
deb http://deb.debian.org/debian ${VERSION} main contrib
58112
deb http://deb.debian.org/debian ${VERSION}-updates main contrib
59113
deb http://security.debian.org/debian-security ${VERSION}-security main contrib
60114
EOF
61-
msg_ok "Changed to Proxmox Backup Server Sources"
62-
;;
63-
no)
64-
msg_error "Selected no to Correcting Proxmox Backup Server Sources"
115+
msg_ok "Corrected Debian Sources"
65116
;;
117+
no) msg_error "Selected no to Correcting Debian Sources" ;;
66118
esac
67119

68-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PBS-ENTERPRISE" --menu "The 'pbs-enterprise' repository is only available to users who have purchased a Proxmox VE subscription.\n \nDisable 'pbs-enterprise' repository?" 14 58 2 \
69-
"yes" " " \
70-
"no" " " 3>&2 2>&1 1>&3)
71-
case $CHOICE in
72-
yes)
73-
msg_info "Disabling 'pbs-enterprise' repository"
74-
cat <<EOF >/etc/apt/sources.list.d/pbs-enterprise.list
75-
# deb https://enterprise.proxmox.com/debian/pbs ${VERSION} pbs-enterprise
76-
EOF
120+
# --- Enterprise repo ---
121+
read -r state file <<<"$(repo_state_list pbs-enterprise)"
122+
case $state in
123+
active)
124+
sed -i "s/^[^#].*pbs-enterprise/# &/" "$file"
77125
msg_ok "Disabled 'pbs-enterprise' repository"
78126
;;
79-
no)
80-
msg_error "Selected no to Disabling 'pbs-enterprise' repository"
127+
disabled) msg_ok "'pbs-enterprise' already disabled" ;;
128+
missing)
129+
cat >/etc/apt/sources.list.d/pbs-enterprise.list <<EOF
130+
# deb https://enterprise.proxmox.com/debian/pbs ${VERSION} pbs-enterprise
131+
EOF
132+
msg_ok "Added 'pbs-enterprise' repository (disabled)"
81133
;;
82134
esac
83135

84-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PBS-NO-SUBSCRIPTION" --menu "The 'pbs-no-subscription' repository provides access to all of the open-source components of Proxmox Backup Server.\n \nEnable 'pbs-no-subscription' repository?" 14 58 2 \
85-
"yes" " " \
86-
"no" " " 3>&2 2>&1 1>&3)
87-
case $CHOICE in
88-
yes)
89-
msg_info "Enabling 'pbs-no-subscription' repository"
90-
cat <<EOF >/etc/apt/sources.list.d/pbs-install-repo.list
136+
# --- No-subscription repo ---
137+
read -r state file <<<"$(repo_state_list pbs-no-subscription)"
138+
if [[ "$state" == "missing" ]]; then
139+
cat >/etc/apt/sources.list.d/pbs-install-repo.list <<EOF
91140
deb http://download.proxmox.com/debian/pbs ${VERSION} pbs-no-subscription
92141
EOF
93142
msg_ok "Enabled 'pbs-no-subscription' repository"
94-
;;
95-
no)
96-
msg_error "Selected no to Enabling 'pbs-no-subscription' repository"
97-
;;
98-
esac
143+
else
144+
msg_ok "'pbs-no-subscription' repository already present"
145+
fi
146+
147+
# --- Test repo (legacy name pbstest) ---
148+
read -r state file <<<"$(repo_state_list pbstest)"
149+
if [[ "$state" == "missing" ]]; then
150+
cat >/etc/apt/sources.list.d/pbstest-for-beta.list <<EOF
151+
# deb http://download.proxmox.com/debian/pbs ${VERSION} pbstest
152+
EOF
153+
msg_ok "Added 'pbstest' repository (disabled)"
154+
else
155+
msg_ok "'pbstest' repository already exists"
156+
fi
99157

100-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PBS TEST" --menu "The 'pbstest' repository can give advanced users access to new features and updates before they are officially released.\n \nAdd (Disabled) 'pbstest' repository?" 14 58 2 \
101-
"yes" " " \
102-
"no" " " 3>&2 2>&1 1>&3)
158+
post_routines_common
159+
}
160+
161+
# ---- PBS 4.x (Trixie, deb822) ----
162+
start_routines_4() {
163+
header_info
164+
local VERSION="trixie"
165+
166+
# --- Debian sources (deb822) ---
167+
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "PBS SOURCES" --menu \
168+
"Correct Debian sources for Proxmox Backup Server 4.x (deb822)?" 14 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
103169
case $CHOICE in
104170
yes)
105-
msg_info "Adding 'pbstest' repository and set disabled"
106-
cat <<EOF >/etc/apt/sources.list.d/pbstest-for-beta.list
107-
# deb http://download.proxmox.com/debian/pbs ${VERSION} pbstest
171+
msg_info "Correcting Debian Sources (deb822)"
172+
rm -f /etc/apt/sources.list.d/*.list
173+
sed -i '/proxmox/d;/bookworm/d' /etc/apt/sources.list || true
174+
cat >/etc/apt/sources.list.d/debian.sources <<EOF
175+
Types: deb
176+
URIs: http://deb.debian.org/debian
177+
Suites: trixie
178+
Components: main contrib
179+
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
180+
181+
Types: deb
182+
URIs: http://security.debian.org/debian-security
183+
Suites: trixie-security
184+
Components: main contrib
185+
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
186+
187+
Types: deb
188+
URIs: http://deb.debian.org/debian
189+
Suites: trixie-updates
190+
Components: main contrib
191+
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg
108192
EOF
109-
msg_ok "Added 'pbstest' repository"
110-
;;
111-
no)
112-
msg_error "Selected no to Adding 'pbstest' repository"
193+
msg_ok "Corrected Debian Sources"
113194
;;
195+
no) msg_error "Selected no to Correcting Debian Sources" ;;
114196
esac
115197

116-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SUBSCRIPTION NAG" --menu "This will disable the nag message reminding you to purchase a subscription every time you log in to the web interface.\n \nDisable subscription nag?" 14 58 2 \
117-
"yes" " " \
118-
"no" " " 3>&2 2>&1 1>&3)
198+
# --- Enterprise repo ---
199+
if ! component_exists_in_sources "pbs-enterprise"; then
200+
cat >/etc/apt/sources.list.d/pbs-enterprise.sources <<EOF
201+
Types: deb
202+
URIs: https://enterprise.proxmox.com/debian/pbs
203+
Suites: trixie
204+
Components: pbs-enterprise
205+
Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg
206+
EOF
207+
msg_ok "Added 'pbs-enterprise' repository"
208+
else
209+
msg_ok "'pbs-enterprise' repository already present"
210+
fi
211+
212+
# --- No-subscription repo ---
213+
if ! component_exists_in_sources "pbs-no-subscription"; then
214+
cat >/etc/apt/sources.list.d/proxmox.sources <<EOF
215+
Types: deb
216+
URIs: http://download.proxmox.com/debian/pbs
217+
Suites: trixie
218+
Components: pbs-no-subscription
219+
Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg
220+
EOF
221+
msg_ok "Added 'pbs-no-subscription' repository"
222+
else
223+
msg_ok "'pbs-no-subscription' repository already present"
224+
fi
225+
226+
# --- Test repo (pbs-test, renamed) ---
227+
if ! component_exists_in_sources "pbs-test"; then
228+
cat >/etc/apt/sources.list.d/pbs-test.sources <<EOF
229+
# Types: deb
230+
# URIs: http://download.proxmox.com/debian/pbs
231+
# Suites: trixie
232+
# Components: pbs-test
233+
# Signed-By: /usr/share/keyrings/proxmox-archive-keyring.gpg
234+
EOF
235+
msg_ok "Added 'pbs-test' repository (disabled)"
236+
else
237+
msg_ok "'pbs-test' repository already present"
238+
fi
239+
240+
post_routines_common
241+
}
242+
243+
# ---- Shared routines ----
244+
post_routines_common() {
245+
# Subscription nag
246+
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "SUBSCRIPTION NAG" --menu \
247+
"Disable subscription nag in PBS UI?" 14 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
119248
case $CHOICE in
120249
yes)
121-
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Support Subscriptions" "Supporting the software's development team is essential. Check their official website's Support Subscriptions for pricing. Without their dedicated work, we wouldn't have this exceptional software." 10 58
250+
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox \
251+
"Supporting the software's development team is essential.\nPlease consider buying a subscription." 10 58
122252
msg_info "Disabling subscription nag"
123-
echo "DPkg::Post-Invoke { \"if [ -s /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js ] && ! grep -q -F 'NoMoreNagging' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; then echo 'Removing subscription nag from UI...'; sed -i '/data\.status/{s/\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; fi\" };" >/etc/apt/apt.conf.d/no-nag-script
124-
msg_ok "Disabled subscription nag (Delete browser cache)"
253+
echo "DPkg::Post-Invoke { \"if [ -s /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js ] && ! grep -q -F 'NoMoreNagging' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; then sed -i '/data\\.status/{s/\\!//;s/active/NoMoreNagging/}' /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js; fi\" };" >/etc/apt/apt.conf.d/no-nag-script
254+
msg_ok "Disabled subscription nag (clear browser cache!)"
125255
;;
126256
no)
127-
whiptail --backtitle "Proxmox VE Helper Scripts" --msgbox --title "Support Subscriptions" "Supporting the software's development team is essential. Check their official website's Support Subscriptions for pricing. Without their dedicated work, we wouldn't have this exceptional software." 10 58
128257
msg_error "Selected no to Disabling subscription nag"
258+
rm -f /etc/apt/apt.conf.d/no-nag-script 2>/dev/null
129259
;;
130260
esac
131-
apt --reinstall install proxmox-widget-toolkit &>/dev/null
261+
apt --reinstall install proxmox-widget-toolkit &>/dev/null || msg_error "Widget toolkit reinstall failed"
132262

133-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UPDATE" --menu "\nUpdate Proxmox Backup Server now?" 11 58 2 \
134-
"yes" " " \
135-
"no" " " 3>&2 2>&1 1>&3)
263+
# Update
264+
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "UPDATE" --menu \
265+
"Update Proxmox Backup Server now?" 11 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
136266
case $CHOICE in
137267
yes)
138268
msg_info "Updating Proxmox Backup Server (Patience)"
139-
apt-get update &>/dev/null
140-
apt-get -y dist-upgrade &>/dev/null
269+
apt update &>/dev/null || msg_error "apt update failed"
270+
apt -y dist-upgrade &>/dev/null || msg_error "apt dist-upgrade failed"
141271
msg_ok "Updated Proxmox Backup Server"
142272
;;
143-
no)
144-
msg_error "Selected no to Updating Proxmox Backup Server"
145-
;;
273+
no) msg_error "Selected no to updating Proxmox Backup Server" ;;
146274
esac
147275

148-
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "REBOOT" --menu "\nReboot Proxmox Backup Server now? (recommended)" 11 58 2 \
149-
"yes" " " \
150-
"no" " " 3>&2 2>&1 1>&3)
276+
# Reminder
277+
whiptail --backtitle "Proxmox VE Helper Scripts" --title "Post-Install Reminder" --msgbox \
278+
"IMPORTANT:
279+
280+
Please run this script on every PBS node individually if you have multiple nodes.
281+
282+
After completing these steps, it is strongly recommended to REBOOT your node.
283+
284+
After the upgrade or post-install routines, always clear your browser cache or perform a hard reload (Ctrl+Shift+R) before using the PBS Web UI to avoid UI display issues." 20 80
285+
286+
# Reboot
287+
CHOICE=$(whiptail --backtitle "Proxmox VE Helper Scripts" --title "REBOOT" --menu \
288+
"Reboot Proxmox Backup Server now? (recommended)" 11 58 2 "yes" " " "no" " " 3>&2 2>&1 1>&3)
151289
case $CHOICE in
152290
yes)
153-
msg_info "Rebooting Proxmox Backup Server"
291+
msg_info "Rebooting PBS"
154292
sleep 2
155293
msg_ok "Completed Post Install Routines"
156294
reboot
157295
;;
158296
no)
159-
msg_error "Selected no to Rebooting Proxmox Backup Server (Reboot recommended)"
297+
msg_error "Selected no to Reboot (Reboot recommended)"
160298
msg_ok "Completed Post Install Routines"
161299
;;
162300
esac
163301
}
164302

165-
header_info
166-
echo -e "\nThis script will Perform Post Install Routines.\n"
167-
while true; do
168-
read -p "Start the Proxmox Backup Server Post Install Script (y/n)?" yn
169-
case $yn in
170-
[Yy]*) break ;;
171-
[Nn]*)
172-
clear
173-
exit
174-
;;
175-
*) echo "Please answer yes or no." ;;
176-
esac
177-
done
178-
179-
if command -v pveversion >/dev/null 2>&1; then
180-
echo -e "\n🛑 PVE Detected, Wrong Script!\n"
181-
exit 1
182-
fi
183-
184-
start_routines
303+
main

0 commit comments

Comments
 (0)