Compare commits

...

4 Commits

Author SHA1 Message Date
tteckster 5da67255d6
Update archlinux.sh
update PVE_CHECK
fixes https://github.com/tteck/Proxmox/issues/1625
2023-07-18 06:28:30 -04:00
tteckster 991b0c1c69
Update cron-update-lxcs.sh
tweak
2023-07-18 04:54:43 -04:00
tteckster a5b70669c5
Update cron-update-lxcs.sh
tweak
2023-07-18 04:38:50 -04:00
tteckster 3a920bbceb
Update update-lxcs-cron.sh
shfmt
2023-07-18 04:28:46 -04:00
3 changed files with 46 additions and 49 deletions

View File

@ -65,13 +65,13 @@ function msg_error() {
} }
function PVE_CHECK() { function PVE_CHECK() {
if [ $(pveversion | grep -c "pve-manager/7\.[0-9]") -eq 0 ]; then if ! pveversion | grep -Eq "pve-manager/(7\.[2-9]|8\.[0-9])"; then
echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported" echo -e "${CROSS} This version of Proxmox Virtual Environment is not supported"
echo -e "Requires PVE Version 7.0 or higher" echo -e "Requires PVE Version 7.2 or higher"
echo -e "Exiting..." echo -e "Exiting..."
sleep 2 sleep 2
exit exit
fi fi
} }
function ARCH_CHECK() { function ARCH_CHECK() {
if [ "$(dpkg --print-architecture)" != "amd64" ]; then if [ "$(dpkg --print-architecture)" != "amd64" ]; then

View File

@ -4,56 +4,53 @@
# Author: tteck (tteckster) # Author: tteck (tteckster)
# License: MIT # License: MIT
# https://github.com/tteck/Proxmox/raw/main/LICENSE # https://github.com/tteck/Proxmox/raw/main/LICENSE
# bash -c "$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/misc/cron-update-lxcs.sh)"
clear clear
cat <<"EOF" cat <<"EOF"
__ __ __ __ __ _ ________ ______ ______ __ __ __ __ __ _ ________
/ / / /___ ____/ /___ _/ /____ / / | |/ / ____/____ / ____/________ ____ / ____/________ ____ / / / /___ ____/ /___ _/ /____ / / | |/ / ____/____
/ / / / __ \/ __ / __ `/ __/ _ \ / / | / / / ___/ / / / ___/ __ \/ __ \ / / / ___/ __ \/ __ \ / / / / __ \/ __ / __ `/ __/ _ \ / / | / / / ___/
/ /_/ / /_/ / /_/ / /_/ / /_/ __/ / /___/ / /___(__ ) / /___/ / / /_/ / / / / / /___/ / / /_/ / / / / / /_/ / /_/ / /_/ / /_/ / /_/ __/ / /___/ / /___(__ )
\____/ .___/\__,_/\__,_/\__/\___/ /_____/_/|_\____/____/ \____/_/ \____/_/ /_/ \____/_/ \____/_/ /_/ \____/ .___/\__,_/\__,_/\__/\___/ /_____/_/|_\____/____/
/_/ /_/
EOF EOF
add() { add() {
while true; do while true; do
read -p "This script will schedule a cron job that updates all LXCs every Sunday at midnight. Proceed(y/n)?" yn read -p "This script will add a crontab schedule that updates all LXCs every Sunday at midnight. Proceed(y/n)?" yn
case $yn in case $yn in
[Yy]*) break ;; [Yy]*) break ;;
[Nn]*) exit ;; [Nn]*) exit ;;
*) echo "Please answer yes or no." ;; *) echo "Please answer yes or no." ;;
esac esac
done done
sh -c '(crontab -l -u root 2>/dev/null; echo "0 0 * * 0 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/bash -c \"\$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh)\" >>/var/log/update-lxcs-cron.log 2>/dev/null") | crontab -u root -' sh -c '(crontab -l -u root 2>/dev/null; echo "0 0 * * 0 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /bin/bash -c \"\$(wget -qLO - https://github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh)\" >>/var/log/update-lxcs-cron.log 2>/dev/null") | crontab -u root -'
clear clear
echo -e "\n To view Update LXCs Cron logs: cat /var/log/update-lxcs-cron.log" echo -e "\n To view Cron Update LXCs logs: cat /var/log/update-lxcs-cron.log"
} }
remove() { remove() {
(crontab -l | grep -v "github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh") | crontab - (crontab -l | grep -v "github.com/tteck/Proxmox/raw/main/misc/update-lxcs-cron.sh") | crontab -
rm /var/log/update-lxcs-cron.log rm -rf /var/log/update-lxcs-cron.log
echo "Removed Update LXCs Cron from Proxmox VE" echo "Removed Crontab Schedule from Proxmox VE"
} }
# Define options for the whiptail menu OPTIONS=(Add "Add Crontab Schedule"
OPTIONS=(Add "Add Update LXCs Cron to Proxmox VE" \ Remove "Remove Crontab Schedule")
Remove "Remove Update LXCs Cron from Proxmox VE")
# Show the whiptail menu and save the user's choice CHOICE=$(whiptail --title "Cron Update LXCs" --menu "Select an option:" 10 58 2 \
CHOICE=$(whiptail --title "Update LXCs Cron for Proxmox VE" --menu "Select an option:" 10 58 2 \ "${OPTIONS[@]}" 3>&1 1>&2 2>&3)
"${OPTIONS[@]}" 3>&1 1>&2 2>&3)
# Check the user's choice and perform the corresponding action
case $CHOICE in case $CHOICE in
"Add") "Add")
add add
;; ;;
"Remove") "Remove")
remove remove
;; ;;
*) *)
echo "Exiting..." echo "Exiting..."
exit 0 exit 0
;; ;;
esac esac

View File

@ -13,16 +13,16 @@ function update_container() {
os=$(pct config "$container" | awk '/^ostype/ {print $2}') os=$(pct config "$container" | awk '/^ostype/ {print $2}')
if [[ "$os" == "ubuntu" || "$os" == "debian" ]]; then if [[ "$os" == "ubuntu" || "$os" == "debian" ]]; then
disk_info=$(pct exec "$container" df /boot | awk 'NR==2{gsub("%","",$5); printf "%s %.1fG %.1fG %.1fG", $5, $3/1024/1024, $2/1024/1024, $4/1024/1024 }') disk_info=$(pct exec "$container" df /boot | awk 'NR==2{gsub("%","",$5); printf "%s %.1fG %.1fG %.1fG", $5, $3/1024/1024, $2/1024/1024, $4/1024/1024 }')
read -ra disk_info_array <<< "$disk_info" read -ra disk_info_array <<<"$disk_info"
echo -e "\n[Info] Updating $container : $name - Boot Disk: ${disk_info_array[0]}% full [${disk_info_array[1]}/${disk_info_array[2]} used, ${disk_info_array[3]} free]" echo -e "\n[Info] Updating $container : $name - Boot Disk: ${disk_info_array[0]}% full [${disk_info_array[1]}/${disk_info_array[2]} used, ${disk_info_array[3]} free]"
else else
echo -e "\n[Info] Updating $container : $name - [No disk info for ${os}]" echo -e "\n[Info] Updating $container : $name - [No disk info for ${os}]"
fi fi
case "$os" in case "$os" in
alpine) pct exec "$container" -- ash -c "apk update && apk upgrade" ;; alpine) pct exec "$container" -- ash -c "apk update && apk upgrade" ;;
archlinux) pct exec "$container" -- bash -c "pacman -Syyu --noconfirm";; archlinux) pct exec "$container" -- bash -c "pacman -Syyu --noconfirm" ;;
fedora|rocky|centos|alma) pct exec "$container" -- bash -c "dnf -y update && dnf -y upgrade" ;; fedora | rocky | centos | alma) pct exec "$container" -- bash -c "dnf -y update && dnf -y upgrade" ;;
ubuntu|debian|devuan) pct exec "$container" -- bash -c "apt-get update 2>/dev/null | grep 'packages.*upgraded'; apt list --upgradable && apt-get -y dist-upgrade" ;; ubuntu | debian | devuan) pct exec "$container" -- bash -c "apt-get update 2>/dev/null | grep 'packages.*upgraded'; apt list --upgradable && apt-get -y dist-upgrade" ;;
esac esac
} }