From 8bcc2fe4cca7515316f591589173be1811f55325 Mon Sep 17 00:00:00 2001 From: larzie Date: Sat, 14 Dec 2024 11:53:28 +0300 Subject: [PATCH] Update script Signed-off-by: larzie --- src/ci/free-disk-space.sh | 103 ++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/src/ci/free-disk-space.sh b/src/ci/free-disk-space.sh index 1c0244dcd..84566c6c3 100644 --- a/src/ci/free-disk-space.sh +++ b/src/ci/free-disk-space.sh @@ -1,18 +1,5 @@ #!/bin/bash -set -e - -fast_rmdir() { - cd "$@" || exit - pwd - ls - perl -e 'Unlink for glob "*"' -} - -list_installed_dpkg() { - dpkg --get-selections "$@" | grep -v deinstall | awk '{print $1}' -} - printSeparationLine() { str=${1:=} num=${2:-80} @@ -20,17 +7,17 @@ printSeparationLine() { output="" while [ $counter -le "$num" ]; do output="${output}${str}" - counter=$((counter + 1)) + counter=$((counter+1)) done echo "${output}" } -getAvailableSpace() { - echo $(df -a "$1" | awk 'NR > 1 {avail+=$4} END {print avail}') +getAvailableSpace() { + echo $(df -a $1 | awk 'NR > 1 {avail+=$4} END {print avail}') } -formatByteCount() { - echo $(numfmt --to=iec-i --suffix=B --padding=7 "$1"000) +formatByteCount() { + echo $(numfmt --to=iec-i --suffix=B --padding=7 $1'000') } printSavedSpace() { @@ -74,93 +61,98 @@ echo "" BEFORE=$(getAvailableSpace) -fast_rmdir "$AGENT_TOOLSDIRECTORY" || true +sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true + AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Agent tools" BEFORE=$(getAvailableSpace) -fast_rmdir /usr/local/share/powershell || true +sudo rm -rf /usr/local/share/powershell || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Powershell" BEFORE=$(getAvailableSpace) -fast_rmdir /usr/local/share/chromium || true +sudo rm -rf /usr/local/share/chromium || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Chromium" BEFORE=$(getAvailableSpace) -fast_rmdir /usr/local/lib/node_modules || true +sudo rm -rf /usr/local/lib/node_modules || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Node modules" BEFORE=$(getAvailableSpace) -fast_rmdir /usr/share/swift || true +sudo rm -rf /usr/share/swift || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Swift" BEFORE=$(getAvailableSpace) -fast_rmdir /usr/local/lib/android || true +sudo rm -rf /usr/local/lib/android || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Android library" BEFORE=$(getAvailableSpace) -fast_rmdir /usr/share/dotnet || true +sudo rm -rf /usr/share/dotnet || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED ".NET runtime" BEFORE=$(getAvailableSpace) -fast_rmdir /opt/ghc || true -fast_rmdir /usr/local/.ghcup || true +sudo rm -rf /opt/ghc || true +sudo rm -rf /usr/local/.ghcup || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Haskell runtime" BEFORE=$(getAvailableSpace) -pkgs=$(list_installed_dpkg 'microsoft-edge-*' 'snapd-*' 'aspnetcore-*' 'dotnet-*' 'llvm-*' '*php*' 'mongodb-*' 'mysql-*' azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri 'google-cloud-*' 'gcloud-*' || true) - -gcloud_prerm='#!/bin/sh -echo $0 -if [ -d "/usr/lib/google-cloud-sdk" ]; then - echo "Cleaning Google Cloud CLI files..." - find /usr/lib/google-cloud-sdk -type f -delete -print | wc -l - rm -rf /usr/lib/google-cloud-sdk - echo "Cleaning Google Cloud CLI manuals..." - find /usr/share/man -type f -name "gcloud*" -delete -print | wc -l -fi' -echo "$gcloud_prerm" | sudo tee /var/lib/dpkg/info/google-cloud-cli-anthoscli.prerm >/dev/null -echo "$gcloud_prerm" | sudo tee /var/lib/dpkg/info/google-cloud-cli.prerm >/dev/null -sudo apt-get remove --autoremove -y $pkgs || echo "::warning::The command [sudo apt-get remove -y] failed to complete successfully. Proceeding..." +sudo apt-get remove -y '^aspnetcore-.*' || echo "::warning::The command [sudo apt-get remove -y '^aspnetcore-.*'] failed." +sudo apt-get remove -y '^dotnet-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^dotnet-.*' --fix-missing] failed." +sudo apt-get remove -y '^llvm-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^llvm-.*' --fix-missing] failed." +sudo apt-get remove -y 'php.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y 'php.*' --fix-missing] failed." +sudo apt-get remove -y '^mongodb-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mongodb-.*' --fix-missing] failed." +sudo apt-get remove -y '^mysql-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mysql-.*' --fix-missing] failed." +sudo apt-get remove -y azure-cli --fix-missing || echo "::warning::The command [sudo apt-get remove -y azure-cli --fix-missing] failed." +sudo apt-get remove -y google-cloud-sdk --fix-missing || echo "::warning::The command [sudo apt-get remove -y google-chrome-stable --fix-missing] failed." +sudo apt-get remove -y firefox --fix-missing || echo "::warning::The command [sudo apt-get remove -y firefox --fix-missing] failed." +sudo apt-get remove -y powershell --fix-missing || echo "::warning::The command [sudo apt-get remove -y powershell --fix-missing] failed." +sudo apt-get remove -y mono-devel --fix-missing || echo "::warning::The command [sudo apt-get remove -y mono-devel --fix-missing] failed." +sudo apt-get remove -y libgl1-mesa-dri --fix-missing || echo "::warning::The command [sudo apt-get remove -y libgl1-mesa-dri --fix-missing] failed." +sudo apt-get remove -y google-cloud-sdk --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-sdk --fix-missing] failed." +sudo apt-get remove -y google-cloud-cli --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-cli --fix-missing] failed." +sudo apt-get remove -y microsoft-edge-stable --fix-missing || echo "::debug::The command [sudo apt-get remove -y microsoft-edge-stable --fix-missing] failed." +sudo apt-get remove -y snapd --fix-missing || echo "::debug::The command [sudo apt-get remove -y snapd --fix-missing] failed." +sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed." +sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed." AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Large misc. packages" BEFORE=$(getAvailableSpace) sudo docker image prune --all --force || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Docker images" BEFORE=$(getAvailableSpace) sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Tool cache" BEFORE=$(getAvailableSpace) sudo swapoff -a || true -sudo rm -f /mnt/swapfile || true +sudo rm -rf /mnt/swapfile || true free -h AFTER=$(getAvailableSpace) -SAVED=$((AFTER - BEFORE)) +SAVED=$((AFTER-BEFORE)) printSavedSpace $SAVED "Swap storage" AVAILABLE_END=$(getAvailableSpace) @@ -169,7 +161,8 @@ AVAILABLE_ROOT_END=$(getAvailableSpace '/') echo "" printDH "After clean-up:" +echo "" echo "/dev/root:" printSavedSpace $((AVAILABLE_ROOT_END - AVAILABLE_ROOT_INITIAL)) -echo "overall:" +echo "Overall:" printSavedSpace $((AVAILABLE_END - AVAILABLE_INITIAL))