mirror of https://github.com/tteck/Proxmox.git
				
				
				
			Update clean-lxcs.sh
add a new menu that allows you to choose which containers you want to exclude from the cleaning process.
This commit is contained in:
		
							parent
							
								
									858a00176d
								
							
						
					
					
						commit
						fb57234263
					
				| 
						 | 
				
			
			@ -33,6 +33,21 @@ while true; do
 | 
			
		|||
  esac
 | 
			
		||||
done
 | 
			
		||||
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() {
 | 
			
		||||
  container=$1
 | 
			
		||||
  header_info
 | 
			
		||||
| 
						 | 
				
			
			@ -40,8 +55,12 @@ function clean_container() {
 | 
			
		|||
  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"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
for container in $(pct list | awk '{if(NR>1) print $1}'); do
 | 
			
		||||
  if [[ " ${excluded_containers[@]} " =~ " $container " ]]; then
 | 
			
		||||
    header_info
 | 
			
		||||
    echo -e "${BL}[Info]${GN} Skipping ${BL}$container${CL}"
 | 
			
		||||
    sleep 1
 | 
			
		||||
  else
 | 
			
		||||
    os=$(pct config "$container" | awk '/^ostype/ {print $2}')
 | 
			
		||||
    if [ "$os" != "debian" ] && [ "$os" != "ubuntu" ]; then
 | 
			
		||||
      header_info
 | 
			
		||||
| 
						 | 
				
			
			@ -49,6 +68,7 @@ for container in $(pct list | awk '{if(NR>1) print $1}'); do
 | 
			
		|||
      sleep 1
 | 
			
		||||
      continue
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    status=$(pct status $container)
 | 
			
		||||
    template=$(pct config $container | grep -q "template:" && echo "true" || echo "false")
 | 
			
		||||
    if [ "$template" == "false" ] && [ "$status" == "status: stopped" ]; then
 | 
			
		||||
| 
						 | 
				
			
			@ -62,7 +82,9 @@ for container in $(pct list | awk '{if(NR>1) print $1}'); do
 | 
			
		|||
    elif [ "$status" == "status: running" ]; then
 | 
			
		||||
      clean_container $container
 | 
			
		||||
    fi
 | 
			
		||||
  fi
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
wait
 | 
			
		||||
header_info
 | 
			
		||||
echo -e "${GN} Finished, Containers Cleaned. ${CL} \n"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue