Update clean-lxcs.sh

add a new menu that allows you to choose which containers you want to exclude from the cleaning process.
pull/1851/head
tteckster 1 year ago committed by GitHub
parent 858a00176d
commit fb57234263
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -33,6 +33,21 @@ while true; do
esac esac
done done
clear clear
TITLE="Containers on node"
while read -r line; do
TAG=$(echo "$line" | awk '{print $1}')
ITEM=$(echo "$line" | awk '{print substr($0,36)}')
OFFSET=2
if [[ $((${#ITEM} + $OFFSET)) -gt ${MSG_MAX_LENGTH:-} ]]; then
MSG_MAX_LENGTH=$((${#ITEM} + $OFFSET))
fi
CTID_MENU+=("$TAG" "$ITEM " "OFF")
done < <(pct list | awk 'NR>1')
excluded_containers=$(whiptail --title "$TITLE" --checklist \
"\nSelect containers to skip from cleaning:\n" \
16 $(($MSG_MAX_LENGTH + 23)) 6 \
"${CTID_MENU[@]}" 3>&1 1>&2 2>&3 | tr -d '"') || exit
function clean_container() { function clean_container() {
container=$1 container=$1
header_info header_info
@ -40,29 +55,36 @@ function clean_container() {
echo -e "${BL}[Info]${GN} Cleaning ${name} ${CL} \n" echo -e "${BL}[Info]${GN} Cleaning ${name} ${CL} \n"
pct exec $container -- bash -c "apt-get -y --purge autoremove && apt-get -y autoclean && bash <(curl -fsSL https://github.com/tteck/Proxmox/raw/main/misc/clean.sh) && rm -rf /var/lib/apt/lists/* && apt-get update" pct exec $container -- bash -c "apt-get -y --purge autoremove && apt-get -y autoclean && bash <(curl -fsSL https://github.com/tteck/Proxmox/raw/main/misc/clean.sh) && rm -rf /var/lib/apt/lists/* && apt-get update"
} }
for container in $(pct list | awk '{if(NR>1) print $1}'); do for container in $(pct list | awk '{if(NR>1) print $1}'); do
os=$(pct config "$container" | awk '/^ostype/ {print $2}') if [[ " ${excluded_containers[@]} " =~ " $container " ]]; then
if [ "$os" != "debian" ] && [ "$os" != "ubuntu" ]; then
header_info header_info
echo -e "${BL}[Info]${GN} Skipping ${name} ${RD}$container is not Debian or Ubuntu ${CL} \n" echo -e "${BL}[Info]${GN} Skipping ${BL}$container${CL}"
sleep 1 sleep 1
continue else
fi os=$(pct config "$container" | awk '/^ostype/ {print $2}')
status=$(pct status $container) if [ "$os" != "debian" ] && [ "$os" != "ubuntu" ]; then
template=$(pct config $container | grep -q "template:" && echo "true" || echo "false") header_info
if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then echo -e "${BL}[Info]${GN} Skipping ${name} ${RD}$container is not Debian or Ubuntu ${CL} \n"
echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n" sleep 1
pct start $container continue
echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n" fi
sleep 5
clean_container $container status=$(pct status $container)
echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL} \n" template=$(pct config $container | grep -q "template:" && echo "true" || echo "false")
pct shutdown $container & if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then
elif [ "$status" == "status: running" ]; then echo -e "${BL}[Info]${GN} Starting${BL} $container ${CL} \n"
clean_container $container pct start $container
echo -e "${BL}[Info]${GN} Waiting For${BL} $container${CL}${GN} To Start ${CL} \n"
sleep 5
clean_container $container
echo -e "${BL}[Info]${GN} Shutting down${BL} $container ${CL} \n"
pct shutdown $container &
elif [ "$status" == "status: running" ]; then
clean_container $container
fi
fi fi
done done
wait wait
header_info header_info
echo -e "${GN} Finished, Containers Cleaned. ${CL} \n" echo -e "${GN} Finished, Containers Cleaned. ${CL} \n"

Loading…
Cancel
Save

Powered by BW's shoe-string budget.