Skip to content

Commit 7b8482c

Browse files
authored
bump to 4.1.3
Add a function to restore a working self-signed certificate in case of mistake, replace sleep with a more permissive method
1 parent 1943650 commit 7b8482c

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

proxmox_toolbox.sh

+43-19
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
# Cosmetic corrections
4141

4242
# Proxmox_toolbox
43-
version=4.1.2
43+
version=4.1.3
4444

4545
# V1.0: Initial Release
4646
# V1.1: correct detecition of subscription message removal
@@ -79,6 +79,7 @@ version=4.1.2
7979
# V4.1.0: Correction and optimisations in fail2ban setup
8080
# V4.1.1: Important fix in permissions for ssh keys
8181
# V4.1.2: Add Ceph enterprise list to ignored sources when using no-subcription
82+
# V4.1.3: Add a function to restore a working self-signed certificate in case of mistake, replace sleep with a more permissive method
8283

8384
# check if root
8485
if [[ $(id -u) -ne 0 ]] ; then echo "- Please run as root / sudo" ; exit 1 ; fi
@@ -97,13 +98,23 @@ hostname=$(hostname)
9798
date=$(date +%Y_%m_%d-%H_%M_%S)
9899
# ---------------END OF VARIABLES-----------------
99100

101+
wait_or_input() {
102+
local timeout=30 # timeout
103+
local input
104+
105+
if read -t "$timeout" -n 1 -p "- Continue: press any key or wait $timeout seconds... " input; then
106+
echo "Key pressed: continuing"
107+
else
108+
echo "- No key pressed until $timeout tiemout. continuing..."
109+
fi
110+
}
111+
100112
if [ ! -f /root/proxmox_config_backups/$hostname-firstrun.tar.gz ]; then
101113
echo "- Creating a backup at first run - dont delete it :-)"
102114
mkdir -p /root/proxmox_config_backups/
103-
sleep 2
104115
tar -czf /root/proxmox_config_backups/$hostname-firstrun.tar.gz --absolute-names $backup_content
105116
echo "- First run: a backup of the actual configurations has been created at /root/proxmox_config_backups/$hostname-firstrun.tar.gz"
106-
sleep 2
117+
wait_or_input
107118
fi
108119

109120
update () {
@@ -140,7 +151,7 @@ getcontentcheck() {
140151
exitcode=$?
141152
if [ $exitcode -ne 0 ]; then
142153
echo "- Error retreiving ressources - control your internet connexion"
143-
sleep 7
154+
wait_or_input
144155
main_menu
145156
fi
146157
}
@@ -234,13 +245,13 @@ main_menu(){
234245
sed -i 's/^/#/' /etc/apt/sources.list.d/pbs-enterprise.list
235246
fi
236247
fi
237-
sleep 3
248+
wait_or_input
238249
fi
239250
main_menu
240251
;;
241252
2) clear;
242253
update
243-
sleep 3
254+
wait_or_input
244255
main_menu
245256
;;
246257
3) clear;
@@ -279,7 +290,7 @@ main_menu(){
279290
else
280291
echo "- lm-sensors already installed"
281292
fi
282-
sleep 3
293+
wait_or_input
283294
fi
284295
main_menu
285296
;;
@@ -323,7 +334,6 @@ main_menu(){
323334
systemctl restart fail2ban.service
324335
echo "- Cleaning git ressources"
325336
rm -rf ./proxmox_toolbox/
326-
327337
fi
328338
clear
329339
echo "- Do you want to create another SSH user ?"
@@ -383,7 +393,7 @@ main_menu(){
383393
pveum user modify $pveusername@pve -group $admingroup
384394
clear
385395
echo "- You can now login on GUI with $pveusername@Proxmox VE authenticaton Realm"
386-
sleep 2
396+
wait_or_input
387397
echo " "
388398
echo "!! Warning - root@pam is required to update host from Proxmox web ui !!"
389399
read -p "- Do you want to disable "root@pam"? y = yes / anything = no: " -n 1 -r
@@ -423,11 +433,11 @@ main_menu(){
423433
swapoff -a
424434
echo "- Re-enabling with a swapiness of: $newswapvalue"
425435
swapon -a
426-
sleep 3
436+
wait_or_input
427437
fi
428438
else
429439
echo " - System has no swap - Nothing to do"
430-
sleep 7
440+
wait_or_input
431441
fi
432442
main_menu
433443
;;
@@ -444,7 +454,7 @@ main_menu(){
444454
echo "- Short smart test will occure every sunday at 22H and long smart tests every 1 of month at 22H"
445455
echo "DEVICESCAN -d auto -n never -a -s (S/../../7/22|L/../01/./22) -m root -M exec /usr/share/smartmontools/smartd-runner" > "/etc/smartd.conf"
446456
fi
447-
sleep 7
457+
wait_or_input
448458
fi
449459
main_menu
450460
;;
@@ -490,11 +500,11 @@ main_menu(){
490500
else
491501
clear
492502
echo "- Returning to menu - no valid choice selected"
493-
sleep 7
503+
wait_or_input
494504
main_menu
495505
fi
496506
systemctl restart snmpd
497-
sleep 3
507+
wait_or_input
498508
fi
499509
main_menu
500510
;;
@@ -650,7 +660,6 @@ mail_menu(){
650660
else
651661
postconf sender_canonical_maps=hash:/etc/postfix/canonical
652662
fi
653-
654663
echo "- Encrypting password and canonical entry"
655664
postmap /etc/postfix/sasl_passwd
656665
postmap /etc/postfix/canonical
@@ -659,7 +668,7 @@ mail_menu(){
659668
echo "- Cleaning file used to generate password hash"
660669
rm -rf "/etc/postfix/sasl_passwd"
661670
echo "- Files cleaned"
662-
671+
wait_or_input
663672
mail_menu;
664673
;;
665674

@@ -669,7 +678,7 @@ mail_menu(){
669678
echo "- An email will be sent to: $vardestaddress"
670679
echo “If you reveive this, it means your email configurations looks correct. Yay!| mail -s "test mail - $hostname - $date" $vardestaddress
671680
echo "- Email should have been sent - If none received, you may want to check for errors in menu 3"
672-
sleep 3
681+
wait_or_input
673682

674683
mail_menu;
675684
;;
@@ -723,7 +732,7 @@ mail_menu(){
723732
fi
724733
else
725734
echo "- No configured error found - nothing to do!"
726-
sleep 3
735+
wait_or_input
727736
fi
728737
mail_menu;
729738
;;
@@ -737,6 +746,7 @@ mail_menu(){
737746
echo "- Restarting services "
738747
systemctl restart postfix
739748
echo "- Restoration done"
749+
wait_or_input
740750
fi
741751
mail_menu;
742752
;;
@@ -773,6 +783,7 @@ backup_menu(){
773783
echo " "
774784
echo -e "${MENU}**${NUMBER} 1)${MENU} Backup configuration ${NORMAL}"
775785
echo -e "${MENU}**${NUMBER} 2)${MENU} Restore configuration ${NORMAL}"
786+
echo -e "${MENU}**${NUMBER} 3)${MENU} Restore a Self signed certificate ${NORMAL}"
776787
echo -e "${MENU}**${NUMBER} 0)${MENU} Back ${NORMAL}"
777788
echo " "
778789
echo -e "${MENU}*********************************************${NORMAL}"
@@ -791,7 +802,7 @@ backup_menu(){
791802
clear
792803
echo "- Backup done - please control and test it"
793804
echo "- Archive is located in $backupdir"
794-
sleep 7
805+
wait_or_input
795806
clear
796807
backup_menu
797808
;;
@@ -851,6 +862,7 @@ backup_menu(){
851862
echo "- Importing pool $pool"
852863
zpool import -f $pool
853864
done
865+
wait_or_input
854866
read -p "- Do you want to reboot host now? y = yes / anything = no: " -n 1 -r
855867
if [[ $REPLY =~ ^[Yy]$ ]]; then
856868
reboot now
@@ -871,6 +883,18 @@ backup_menu(){
871883
esac
872884
done
873885
;;
886+
3) clear;
887+
echo "- Removing old certificates "
888+
rm -f /etc/pve/pve-root-ca.pem
889+
rm -f /etc/pve/priv/pve-root-ca.key
890+
rm -f /etc/pve/nodes/$hostname/pve-ssl.pem
891+
rm -f /etc/pve/nodes/$hostname/pve-ssl.key
892+
echo "- Generating new certificates"
893+
pvecm updatecerts -f
894+
wait_or_input
895+
clear
896+
backup_menu
897+
;;
874898
0) clear;
875899
main_menu;
876900
;;

0 commit comments

Comments
 (0)