lxc -> incus

This commit is contained in:
2025-03-23 11:26:28 +01:00
parent b0067645ba
commit 1b0b27d94a
12 changed files with 155 additions and 113 deletions

48
update-incus-container.sh Executable file
View File

@@ -0,0 +1,48 @@
#!/bin/bash
declare -A pids
BRed=$'\033[1;31m' # Red
BGreen=$'\033[1;32m' # Green
Color_Off=$'\033[0m' # Text Reset
TMSTMP=$(date +'%Y%m%d%H%M%S')
function stop_container() {
echo $(date) "- ${BGreen}Stop container ${1}${Color_Off}"
incus stop ${1} | sed "s/^/$(date) - ${BGreen}${1}${Color_Off} /"
wait
echo -e $(date) "- ${BGreen}Container ${1} stopped${Color_Off}"
}
function update_container() {
incus exec ${1} -- sh -c "apt update 2>&1" | sed "s/^/$(date) - ${BGreen}${1}${Color_Off} /"
sleep 2
incus exec ${1} -- sh -c "apt upgrade -y 2>&1" | sed "s/^/$(date) - ${BGreen}${1}${Color_Off} /"
sleep 2
incus exec ${1} -- sh -c "apt autoremove -y 2>&1" | sed "s/^/$(date) - ${BGreen}${1}${Color_Off} /"
sleep 2
echo -e $(date) "- ${BGreen}Refresh snap packages${Color_Off}"
incus exec ${1} -- bash -c "if [[ \$(which snap > /dev/null; echo \$?) == 0 ]]; then snap refresh ; fi" | sed "s/^/$(date) - ${BGreen}${1}${Color_Off} /"
if [ "${2}" == "STOPPED" ]; then
stop_container ${1}
fi
}
echo $(date) "- ${BGreen}Start updating incus container...${Color_Off}"
for cont_name in $(incus list type=container -c n --format csv); do
echo $(date) "- ${BGreen}Make ${cont_name} container snapshot...${Color_Off}"
incus snapshot create ${cont_name} | sed "s/^/$(date) - ${BGreen}${cont_name}${Color_Off} /"
echo $(date) "- ${BGreen}Updating ${cont_name} container...${Color_Off}"
Status=$(incus list type=container -c ns --format csv | grep ${cont_name} | cut -d',' -f 2)
if [ "${Status}" == "STOPPED" ]; then
echo -e $(date) "- ${BGreen}Start container ${cont_name}.${Color_Off}"
incus start ${cont_name} | sed 's/^/'${date}' - '${cont_name}' /'
sleep 5
else
echo -e $(date) "- ${BGreen}Container ${cont_name} is already started.${Color_Off}"
fi
update_container ${cont_name} ${Status} &
done
wait
echo $(date) "- ${BGreen}Updating incus container ended.${Color_Off}"