fix: dkprune -r forces docker

This commit is contained in:
AngeD 2023-06-08 00:39:33 +02:00
parent c496aba180
commit cf8428b2ac

View File

@ -2,8 +2,8 @@
function usage() { function usage() {
cat << EOF cat << EOF
Usage: $0 [-hcCviIna] Usage: ${0##*/} [-hcCviInar]
Prune $RUNTIME resources. Prune ${CRI##*/} resources.
If no option provided, defaults to -Cvn If no option provided, defaults to -Cvn
Options: Options:
-h Show this help and exits -h Show this help and exits
@ -14,7 +14,7 @@ Options:
-I Remove unused images -I Remove unused images
-n Remove unused networks -n Remove unused networks
-a All of the above, equivalent of -CvIn -a All of the above, equivalent of -CvIn
-r Run as root -r Run docker as root
EOF EOF
exit 0 exit 0
} }
@ -31,7 +31,7 @@ function add_opt() {
echo "$RESULT" echo "$RESULT"
} }
RUNTIME="$(command -v podman || command -v docker)" CRI="${CRI-"$(command -v podman || command -v docker)"}"
c=1 c=1
# C=2 # C=2
@ -73,7 +73,7 @@ while getopts hcCviInar o; do
IMG_OPT='-a' IMG_OPT='-a'
;; ;;
r) r)
echo exec sudo -- "$0" "${@/r/}" exec sudo CRI="$(command -v docker)" -- "$0" "${@/r/}"
;; ;;
*) *)
exit 1 exit 1
@ -97,15 +97,15 @@ VALUES=(
CON='container' CON='container'
PRUNE='prune -f' PRUNE='prune -f'
COMMANDS=( COMMANDS=(
"$RUNTIME system $PRUNE $IMG_OPT --volumes" "$CRI system $PRUNE $IMG_OPT --volumes"
"$RUNTIME system $PRUNE $IMG_OPT" "$CRI system $PRUNE $IMG_OPT"
"$RUNTIME volume $PRUNE" "$CRI volume $PRUNE"
"$RUNTIME image $PRUNE $IMG_OPT" "$CRI image $PRUNE $IMG_OPT"
"$RUNTIME network $PRUNE" "$CRI network $PRUNE"
) )
if [ "$((CLEAN & "$c"))" == "$c" ]; then if [ "$((CLEAN & "$c"))" == "$c" ]; then
$RUNTIME "$CON" ls -aq | xargs "$RUNTIME" "$CON" rm "$CON_OPT" 2> /dev/null $CRI "$CON" ls -aq | xargs "$CRI" "$CON" rm "$CON_OPT" 2> /dev/null || true
fi fi
for idx in "${!VALUES[@]}"; do for idx in "${!VALUES[@]}"; do