diff --git a/cleanup.sh b/cleanup.sh index 355bfb5..f623c18 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -17,7 +17,7 @@ cleanup() { #box="\033[1;41m" #reset="\033[0m" -opt_cache=true +opt_cache=false opt_log=false opt_adobe=false opt_chrome=false # @@ -108,11 +108,7 @@ else echo fi -_bytesToHuman() { - b=$1 - echo $b - } - + bytesToHuman() { b=${1:-0} d='' @@ -128,6 +124,26 @@ bytesToHuman() { echo $human_size } +_dehumanise() { + octet=$(echo $1 | awk '/[0-9]$/{print $1;next};/[mM(iB)]$/{printf "%u\n", $1*(1024*1024);next};/[kK]$/{printf "%u\n", $1*1024;next}') + echo $octet +} + +dehumanise() { + echo $1 | awk \ + 'BEGIN{IGNORECASE = 1} + function printpower(n,b,p) {printf "%u\n", n*b^p;} + /[0-9]$/{print $1;next}; + /K(iB)?$/{printpower($1, 2, 10)}; + /M(iB)?$/{printpower($1, 2, 20)}; + /G(iB)?$/{printpower($1, 2, 30)}; + /T(iB)?$/{printpower($1, 2, 40)}; + /KB$/{ printpower($1, 10, 3)}; + /MB$/{ printpower($1, 10, 6)}; + /GB$/{ printpower($1, 10, 9)}; + /TB$/{ printpower($1, 10, 12)}' +} + count_dry() { #echo "count_dry" #local dry_results @@ -261,6 +277,7 @@ echo -e "${RED}System log: $count_section${NOFORMAT}" echo "totalFree $totalFree" fi + ### Adobe Cache ### if [[ $opt_adobe = true ]]; then @@ -562,6 +579,8 @@ fi # https://docs.docker.com/desktop/faqs/macfaqs/ + + if [[ $opt_docker = true ]]; then if type "docker" &>/dev/null; then @@ -570,21 +589,30 @@ if [[ $opt_docker = true ]]; then vm_size=$(($(/usr/bin/stat -f%z ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw) / 1000)) # 1000->38.14 GiB; 1024->37.25 GiB # 40 000 028 672 octets (2,53 Go sur disque) - msg "\nOn macOS, Docker Desktop stores Linux containers and images in a single, large disk image file in the Mac filesystem (located à ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw)(size=$(bytesToHuman $vm_size))." + msg "\nOn macOS, Docker Desktop stores Linux containers and images in a single, large disk image file in the Mac filesystem (located at ~/Library/Containers/com.docker.docker/Data/vms/0/data/Docker.raw)(size=$(bytesToHuman $vm_size))." msg "\nhttps://docs.docker.com/desktop/faqs/macfaqs/" msg "\n${RED}Delete ou prune some images and container will free up space on this large disk image, not on the Mac filesystem.${NOFORMAT}" if [ -z "$dry_run" ]; then + # if (! docker stats --no-stream ); then if ! docker ps >/dev/null 2>&1; then close_docker=true - echo "Docker closed" + echo "Docker closed! We launch it!" open --background -a Docker fi msg '\nCleaning up Docker' echo -e "Running ${ITALIC}docker system prune -af${NOFORMAT}" - docker_prune=$(docker system prune -af) # &>/dev/null - docker_free=$(echo "$docker_prune" | grep 'Total reclaimed space' | awk -F"=" '{print $2}' | xargs) - msg "${BLUE}\nApprox $docker_free of space has been cleaned up${NOFORMAT}." + + docker_prune=$(docker system prune -af) # -af &>/dev/null + docker_free=$(echo "$docker_prune" | grep 'Total reclaimed space' | awk -F":" '{print $2}' | xargs) + # Total reclaimed space: 1.292GB + # Total reclaimed space: 60.37MB + # Total reclaimed space: 0B + g=$(dehumanise $docker_free) + #echo "bytesToHuman: "$(bytesToHuman $g) + + [ -z $docker_free ] && docker_free="0 KiB" + msg "${BLUE}\nApprox $docker_free of space has been cleaned up in the Docker's VM${NOFORMAT}." if [ "$close_docker" = true ]; then killall Docker