Create update-lxcs.sh

This commit is contained in:
tteckster 2022-03-02 08:33:52 -05:00 committed by GitHub
parent 35f132e6a4
commit 8ea1e80b3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 0 deletions

54
misc/update-lxcs.sh Normal file
View File

@ -0,0 +1,54 @@
#!/bin/bash
set -e
YW=`echo "\033[33m"`
BL=`echo "\033[36m"`
RD=`echo "\033[01;31m"`
CM='\xE2\x9C\x94\033'
GN=`echo "\033[1;92m"`
CL=`echo "\033[m"`
while true; do
read -p "This Will Update All LXC Containers. Proceed(y/n)?" yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
clear
function header_info {
echo -e "${BL}
_ _ _____ _____ _______ ______
| | | | __ \| __ \ /\|__ __| ____|
| | | | |__) | | | | / \ | | | |__
| | | | ___/| | | |/ /\ \ | | | __|
| |__| | | | |__| / ____ \| | | |____
\____/|_| |_____/_/ \_\_| |______|
${CL}"
}
header_info
containers=$(pct list | tail -n +2 | cut -f1 -d' ')
function update_container() {
container=$1
echo -e "${BL}[Info]${GN} Updating${BL} $container... ${CL}"
# to chain commands within one exec we will need to wrap them in bash
pct exec $container -- bash -c "apt update && apt upgrade -y && apt autoremove -y"
}
for container in $containers
do
status=`pct status $container`
if [ "$status" == "status: stopped" ]; then
echo -e "${BL}[Info]${GN} Starting${BL} $container... ${CL}"
pct start $container
echo -e "${BL}[Info]${GN} Waiting For${BL} $container To Start... ${CL}"
sleep 5
update_container $container
echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL}"
pct shutdown $container &
elif [ "$status" == "status: running" ]; then
update_container $container
fi
done; wait