Skip to content

Commit 3e643f4

Browse files
authored
Create debloat_ubuntu.sh
1 parent 699ef22 commit 3e643f4

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

Github/Runners/debloat_ubuntu.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
3+
# Use:
4+
# bash <(curl -qfsSL "https://raw.githubusercontent.com/pkgforge/devscripts/main/Github/Runners/debloat_ubuntu.sh")
5+
6+
#Ref: https://github.com/easimon/maximize-build-space
7+
# https://github.com/easimon/maximize-build-space/blob/master/action.yml
8+
9+
#The Build Image & Docs: https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
10+
11+
#----------------------------------------------------------------------------#
12+
# If On Github Actions, remove bloat to get space (~ 40 GB)
13+
if [ "$USER" = "runner" ] || [ "$(whoami)" = "runner" ] && [ -s "/opt/runner/provisioner" ]; then
14+
echo -e "\n[+] Debloating GH Runner...\n"
15+
export DEBIAN_FRONTEND="noninteractive"
16+
sudo apt-get update -y -qq >/dev/null 2>&1
17+
ROOT_DISK="$(df -h / | awk 'NR==2 {print $1}')" && export ROOT_DISK="${ROOT_DISK}"
18+
TOTAL_DSIZE="$(df -h ${ROOT_DISK} | awk 'NR==2 {print $2}')" && export TOTAL_DSIZE="${TOTAL_DSIZE}"
19+
INITIAL_DSIZE="$(df -h ${ROOT_DISK} | awk 'NR==2 {print $3}')" && export INITIAL_DSIZE="${INITIAL_DSIZE}"
20+
INITIAL_FREEP="$(df -h ${ROOT_DISK} | awk 'NR==2 {print $5}')" && export INITIAL_FREEP="${INITIAL_FREEP}"
21+
#----------------------------------------------------------------------------#
22+
## Android NDK :: ~ 12.0 GB
23+
sudo rm "/usr/local/lib/android" -rf >/dev/null 2>&1 &
24+
#----------------------------------------------------------------------------#
25+
## AWS :: ~ 500 MB
26+
find "/usr/local" -maxdepth 1 -type d -name '*aws*cli*' -exec sudo rm {} -rf \; >/dev/null 2>&1 &
27+
#----------------------------------------------------------------------------#
28+
## Azure cli :: ~ 800 MB
29+
sudo rm "/opt/az" -rf >/dev/null 2>&1 &
30+
#----------------------------------------------------------------------------#
31+
## AZ (PowerShell) :: ~ 500 MB
32+
find "/usr/share" -maxdepth 1 -type d -name 'az_*' -exec sudo rm {} -rf \; >/dev/null 2>&1 &
33+
#----------------------------------------------------------------------------#
34+
## DotNET :: ~ 2.0 GB
35+
sudo rm "/usr/lib/dotnet" -rf >/dev/null 2>&1 &
36+
sudo rm "/usr/share/dotnet" -rf >/dev/null 2>&1 &
37+
#----------------------------------------------------------------------------#
38+
## GCP SDK :: ~ 2.0 GB
39+
sudo rm "/usr/lib/google-cloud-sdk" -rf >/dev/null 2>&1 &
40+
#----------------------------------------------------------------------------#
41+
## Haskell :: ~ 5.0 GB
42+
sudo rm "/usr/local/.ghcup" -rf >/dev/null 2>&1 &
43+
#----------------------------------------------------------------------------#
44+
## Heroku :: ~ 500 MB
45+
sudo rm "/usr/local/lib/heroku" -rf >/dev/null 2>&1 &
46+
#----------------------------------------------------------------------------#
47+
## HostedToolCache :: ~ 12 GB
48+
sudo rm "/opt/hostedtoolcache" -rf >/dev/null 2>&1 &
49+
#----------------------------------------------------------------------------#
50+
## JVM :: ~ 1.5 GB
51+
sudo rm "/usr/lib/jvm" -rf >/dev/null 2>&1 &
52+
#----------------------------------------------------------------------------#
53+
## Julia :: ~ 500 MB
54+
find "/usr/local" -maxdepth 1 -type d -name '*julia*' -exec sudo rm {} -rf \; >/dev/null 2>&1 &
55+
#----------------------------------------------------------------------------#
56+
## Miniconda :: ~ 700 MB
57+
sudo rm "/usr/share/miniconda" -rf >/dev/null 2>&1 &
58+
#----------------------------------------------------------------------------#
59+
## Microsoft :: ~ 700 MB
60+
sudo rm "/opt/microsoft" -rf >/dev/null 2>&1 &
61+
#----------------------------------------------------------------------------#
62+
## Mono (.NET) :: ~ 1.5 GB
63+
sudo rm "/usr/lib/mono" -rf >/dev/null 2>&1 &
64+
#----------------------------------------------------------------------------#
65+
#WARNING: This seem to break some core components, rendering the runner unusable & terminate
66+
## Node Modules :: ~ 1.1 GB
67+
#sudo rm "/usr/local/lib/node_modules" -rf >/dev/null 2>&1 &
68+
#----------------------------------------------------------------------------#
69+
## PowerShell :: ~ 1.0 GB
70+
sudo rm "/usr/local/share/powershell" -rf >/dev/null 2>&1 &
71+
#----------------------------------------------------------------------------#
72+
## Snap :: ~ 5 GB
73+
#https://github.com/grobo021/snap-nuke/blob/main/snap-nuke.sh
74+
#https://github.com/polkaulfield/ubuntu-debullshit/blob/main/ubuntu-debullshit.sh
75+
#while [ "$(snap list 2>/dev/null | wc -l)" -gt 0 ]; do for snap in $(snap list 2>/dev/null | tail -n +2 | cut -d ' ' -f 1); do snap remove --purge "$snap" 2>/dev/null ; done ; done
76+
sudo snap remove "$(snap list 2>/dev/null | awk '!/^Name|^core|^bare|^snapd/ {print $1}')" >/dev/null 2>&1 &
77+
wait ; sudo snap remove "$(snap list 2>/dev/null | awk '/^bare/ {print $1}')" >/dev/null 2>&1 &
78+
wait ; sudo snap remove "$(snap list 2>/dev/null | awk '/^core/ {print $1}')" >/dev/null 2>&1 &
79+
wait ; sudo snap remove "$(snap list 2>/dev/null | awk '/^snapd/ {print $1}')" >/dev/null 2>&1 &
80+
wait ; sudo systemctl disable --now snapd >/dev/null 2>&1 &
81+
wait ; sudo systemctl disable snapd >/dev/null 2>&1 &
82+
wait ; sudo systemctl mask snapd >/dev/null 2>&1 &
83+
wait ; sudo apt purge snapd -y -qq >/dev/null 2>&1 &
84+
wait ; sudo rm "/snap" -rf >/dev/null 2>&1 &
85+
sudo rm "$HOME/snap" -rf >/dev/null 2>&1 &
86+
sudo rm "/root/snap" -rf >/dev/null 2>&1 &
87+
sudo rm "/var/snap" -rf >/dev/null 2>&1 &
88+
sudo rm "/var/cache/snapd" -rf >/dev/null 2>&1 &
89+
sudo rm "/var/lib/snapd" -rf >/dev/null 2>&1 &
90+
echo "" | sudo tee "/etc/apt/preferences.d/no-snap.pref" >/dev/null 2>&1
91+
echo 'Package: snapd' | sudo tee -a "/etc/apt/preferences.d/no-snap.pref" >/dev/null 2>&1 &
92+
wait ; echo 'Pin: release a=*' | sudo tee -a "/etc/apt/preferences.d/no-snap.pref" >/dev/null 2>&1 &
93+
wait ; echo 'Pin-Priority: -10' | sudo tee -a "/etc/apt/preferences.d/no-snap.pref" >/dev/null 2>&1 &
94+
wait ; sudo chown "root:root" "/etc/apt/preferences.d/no-snap.pref" >/dev/null 2>&1 &
95+
wait ; sudo apt-get update -qq -y >/dev/null 2>&1 &
96+
for S in "$(df -h | awk '/snap/ {print $6}')"; do sudo umount "$S" >/dev/null 2>&1 ; done
97+
#----------------------------------------------------------------------------#
98+
## Swift :: ~ 1.7 GB
99+
sudo rm "/usr/share/swift" -rf >/dev/null 2>&1 &
100+
#----------------------------------------------------------------------------#
101+
#wait
102+
wait ; reset >/dev/null 2>&1 ; echo
103+
FINAL_DSIZE="$(df -h ${ROOT_DISK} | awk 'NR==2 {print $3}')" && export FINAL_DSIZE="${FINAL_DSIZE}"
104+
FINAL_FREEP="$(df -h ${ROOT_DISK} | awk 'NR==2 {print $5}')" && export FINAL_FREEP="${FINAL_FREEP}"
105+
echo -e "\n[+] Reduced Disk (Total: ${TOTAL_DSIZE}) :: (Used: ${INITIAL_DSIZE}) (Free: ${INITIAL_FREEP}) --> (Used: ${FINAL_DSIZE}) (Free: ${FINAL_FREEP})\n"
106+
unset DEBIAN_FRONTEND ROOT_DISK TOTAL_DSIZE INITIAL_DSIZE INITIAL_FREEP FINAL_DSIZE FINAL_FREEP
107+
fi
108+
#----------------------------------------------------------------------------#

0 commit comments

Comments
 (0)