├── README.md ├── check_upgrade.sh ├── send_ct.sh └── update.sh /README.md: -------------------------------------------------------------------------------- 1 | # LXC Proxmox Upgrade 2 | 3 | You will find here some script I use for every date job on my Proxmox 4 | 5 | - `check_upgrade.sh` - Script to check if Containers have upgrade in progress 6 | - `send_ct.sh` - Send a command to every CT 7 | - `update.sh` - My script to auto update all my Containers and the Host. It additionnaly run the script ~/maj if it exist on the Container. 8 | 9 | -------------------------------------------------------------------------------- /check_upgrade.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | packages_to_upgrade=() 4 | regex="The following packages will be upgraded:\s(.*)[0-9]+ upgraded, [0-9]+ newly installed, [0-9]+ to remove" 5 | 6 | check_update () { 7 | sudo lxc-attach -n $1 -- apt-get update -qq 8 | res=$(sudo lxc-attach -n $1 -- apt-get upgrade --show-upgraded --assume-no) 9 | res="${res//[$'\t\r\n']}" 10 | if [[ "$res" =~ $regex ]]; then 11 | packages_to_upgrade+=${BASH_REMATCH[1]} 12 | fi 13 | } 14 | 15 | # Check upgrades for all active containers 16 | for cx in `sudo lxc-ls --active --line`; do 17 | check_update $cx 18 | done 19 | 20 | # Check upgrade for the Host 21 | apt-get update -qq 22 | res=$(apt-get upgrade --show-upgraded --assume-no) 23 | res="${res//[$'\t\r\n']}" 24 | if [[ "$res" =~ $regex ]]; then 25 | packages_to_upgrade+=${BASH_REMATCH[1]} 26 | fi 27 | 28 | # Send email to root if there are upgrades available 29 | if [ ! -z "$packages_to_upgrade" ]; then 30 | res=$(echo $packages_to_upgrade | tr ' ' '\n' | sort | uniq -c) 31 | echo -e "Packages waiting for upgrade\n\n$res" | mail -s "Proxmox upgrade list" root 32 | fi 33 | 34 | -------------------------------------------------------------------------------- /send_ct.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | send () { 4 | echo "------------------------------" 5 | echo " Send to $1..." 6 | echo "------------------------------" 7 | sudo lxc-attach -n $1 -- ${@:2} 8 | } 9 | 10 | # Need "all" or container ID 11 | if [ -z "$1" ]; then 12 | echo "usage: | command" 13 | exit 1 14 | fi 15 | 16 | if [ -z "$2" ]; then 17 | echo "command is missing" 18 | exit 1 19 | fi 20 | 21 | # Upgrade all active containers 22 | if [ "all" = "$1" ]; then 23 | for cx in `sudo lxc-ls --active --line`; do 24 | send $cx ${@:2} 25 | done 26 | exit 27 | fi 28 | 29 | # Should be a container 30 | send $1 ${@:2} 31 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | update () { 4 | echo "------------------------------" 5 | echo " Send to $1..." 6 | echo "------------------------------" 7 | sudo lxc-attach -n $1 -- apt update -qq 8 | sudo lxc-attach -n $1 -- apt upgrade -q -y 9 | sudo lxc-attach -n $1 -- apt autoremove 10 | 11 | if [ $2 -eq 1 ]; then 12 | sudo lxc-attach -n $1 -- /root/maj 13 | fi 14 | } 15 | 16 | # Need "all" or container ID 17 | if [ -z "$1" ]; then 18 | echo "usage: |" 19 | exit 1 20 | fi 21 | 22 | # Upgrade all active containers 23 | if [ "all" = "$1" ]; then 24 | read -p "Full update (y/n)?" choice 25 | case "$choice" in 26 | y|Y ) full=1;; 27 | * ) full=0;; 28 | esac 29 | 30 | for cx in `sudo lxc-ls --active --line`; do 31 | update $cx $full 32 | done 33 | 34 | echo "------------------------------" 35 | echo " Proxmox ..." 36 | echo "------------------------------" 37 | sudo apt update 38 | sudo apt upgrade 39 | exit 40 | fi 41 | 42 | # Should be a container 43 | read -p "Full update (y/n)?" choice 44 | case "$choice" in 45 | y|Y ) update $1 1;; 46 | * ) update $1 0;; 47 | esac 48 | 49 | --------------------------------------------------------------------------------