moved the cleanup and prune logic to always run. Changed some wording on messages.

This commit is contained in:
mag37 2025-11-15 20:02:48 +01:00
parent 42d35b7a03
commit 6576a36fda

View file

@ -638,30 +638,34 @@ if [[ -n "${GotUpdates:-}" ]]; then
${DockerBin} ${CompleteConfs} ${ContEnvs} up -d ${SpecificContainer} || { printf "\n%bDocker error, exiting!%b\n" "$c_red" "$c_reset" ; exit 1; }
fi
done
# Clean up old backup image tags if -k is used
if [[ -n "${DaysKept:-}" ]]; then
IFS=$'\n'
for backup_img in $(docker images --format "{{.Repository}} {{.Tag}}" dockcheck/\*); do
repo_name=${backup_img% *}
backup_tag=${backup_img#* }
backup_date=${backup_tag%%_*}
# UNTAGGING HERE
if datecheck "$backup_date" "$DaysKept"; then
docker rmi "${repo_name}:${backup_tag}"
fi
done
unset IFS
fi
fi
if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune all dangling images? y/[n]: " AutoPrune; fi
if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then printf "\nAuto pruning.."; docker image prune -f; fi
printf "\n%bAll done!%b\n" "$c_green" "$c_reset"
printf "\n%bAll updates done!%b\n" "$c_green" "$c_reset"
else
printf "\nNo updates installed, exiting.\n"
printf "\nNo updates installed.\n"
fi
else
printf "\nNo updates available, exiting.\n"
printf "\nNo updates available.\n"
fi
# Clean up old backup image tags if -k is used
if [[ -n "${DaysKept:-}" ]]; then
IFS=$'\n'
CleanupCount=0
for backup_img in $(docker images --format "{{.Repository}} {{.Tag}}" dockcheck/\*); do
repo_name=${backup_img% *}
backup_tag=${backup_img#* }
backup_date=${backup_tag%%_*}
# UNTAGGING HERE
if datecheck "$backup_date" "$DaysKept"; then
[[ "$CleanupCount" == 0 ]] && echo "Removing backed up images older then $DaysKept days."
docker rmi "${repo_name}:${backup_tag}" && ((CleanupCount+=1))
fi
[[ "$CleanupCount" == 0 ]] && printf "No backup images to remove.%b\n" || printf "%b%s%b backup images removed." "$c_blue" "$c_teal" "$CleanupCount" "$c_reset"
done
unset IFS
fi
if [[ "$AutoPrune" == false ]] && [[ "$AutoMode" == false ]]; then printf "\n"; read -rep "Would you like to prune all dangling images? y/[n]: " AutoPrune; fi
if [[ "$AutoPrune" == true ]] || [[ "$AutoPrune" =~ [yY] ]]; then printf "\nAuto pruning.."; docker image prune -f; fi
exit 0