Update update-lxcs.sh

use the command line to exclude multiple containers simultaneously
This commit is contained in:
tteckster 2023-03-10 19:36:10 -05:00 committed by GitHub
parent c47326ff25
commit dc4e460b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,8 +34,7 @@ while true; do
esac esac
done done
clear clear
exclude_container="$@" excluded_containers=("$@")
containers=$(pct list | tail -n +2 | cut -f1 -d' ' | grep -vE "^($exclude_container)$")
function update_container() { function update_container() {
container=$1 container=$1
header_info header_info
@ -50,10 +49,22 @@ function update_container() {
esac esac
} }
header_info header_info
for container in $containers; do for container in $(pct list | tail -n +2 | cut -f1 -d' '); do
status=$(pct status $container) excluded=false
template=$(pct config $container | grep -q "template:" && echo "true" || echo "false") for excluded_container in "${excluded_containers[@]}"; do
if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then if [ "$container" == "$excluded_container" ]; then
excluded=true
break
fi
done
if [ "$excluded" == true ]; then
header_info
echo -e "${BL}[Info]${GN} Skipping ${BL}$container${CL}"
sleep 1
else
status=$(pct status $container)
template=$(pct config $container | grep -q "template:" && echo "true" || echo "false")
if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then
echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n" echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n"
pct start $container pct start $container
echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n" echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n"
@ -63,6 +74,7 @@ for container in $containers; do
pct shutdown $container & pct shutdown $container &
elif [ "$status" == "status: running" ]; then elif [ "$status" == "status: running" ]; then
update_container $container update_container $container
fi
fi fi
done done
wait wait