Compare commits
No commits in common. "a28a11a35d81967c82448c183cb17a34b7514a9a" and "3dac4f5d6c77c453a7a2297e72d55e87312570ab" have entirely different histories.
a28a11a35d
...
3dac4f5d6c
6 changed files with 142 additions and 738 deletions
46
.github/checker.sh
vendored
46
.github/checker.sh
vendored
|
@ -1,46 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd $(mktemp -d) || exit
|
||||
echo "::group:: Environment Variables"
|
||||
printenv | sort | tee -a env.vars.${state}.${wf_os}.list
|
||||
echo "::endgroup::"
|
||||
echo "::group:: Disk Space"
|
||||
df --sync -BM -T -a | tee -a disk.usage.${state}.${wf_os}.list
|
||||
echo "::endgroup::"
|
||||
echo "::group:: apt List Area"
|
||||
sudo apt list --installed | sed '1d' | tee -a apt.installed.${state}.${wf_os}.list
|
||||
echo "::endgroup::"
|
||||
echo "::group:: dpkg-query Debug Area"
|
||||
dpkg-query -Wf 'Package: ${Package}\nSynopsis: ${binary:Summary}\nVersion: ${Version}\nSizeInKB: ${Installed-Size}\nPre-Depends: ${Pre-Depends}\nDepends: ${Depends}\n\n' | sed -e '/^Synopsis: $/d;/^Version: $/d;/^SizeInKB: $/d;/^Pre-Depends: $/d;/^Depends: $/d' | tee -a apt.dependencies.${state}.${wf_os}.list
|
||||
echo "::endgroup::"
|
||||
echo "::group:: Storage-hungry APT Packages dpkg-query Debug Area"
|
||||
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -rh 2>/dev/null | head -n30 | awk '{print $2}' >apt.hugeapps.names.${state}.${wf_os}.list
|
||||
cat apt.hugeapps.names.${state}.${wf_os}.list | while read -r i; do
|
||||
dpkg-query -f='Package: ${Package}\nSynopsis: ${binary:Summary}\nVersion: ${Version}\nSizeInKB: ${Installed-Size}\nPre-Depends: ${Pre-Depends}\nDepends: ${Depends}\n\n' -W "${i}" | sed -e '/^Synopsis: $/d;/^Version: $/d;/^SizeInKB: $/d;/^Pre-Depends: $/d;/^Depends: $/d' | tee -a apt.hugeappsdependencies.${state}.${wf_os}.list
|
||||
done
|
||||
echo "::endgroup::"
|
||||
echo "::group:: Bin Debug Area"
|
||||
ls -lAog /usr/local/bin 2>&1 | tee -a bin.local.${state}.${wf_os}.list
|
||||
ls -lAog /usr/bin 2>&1 | tee -a bin.global.${state}.${wf_os}.list
|
||||
echo "::endgroup::"
|
||||
echo "::group:: Directory List Debug Area"
|
||||
ls -lAog ~/.* 2>/dev/null | tee -a dotfiles.${state}.${wf_os}.list || true
|
||||
tree -a -h -I "*.py|__pycache__|*.h|*.dll|*.git" -L 4 /opt/ 2>/dev/null >tree.opt.${state}.${wf_os}.list || true
|
||||
tree -a -h -I "*.py|__pycache__|*.h|*.dll|*.git" -L 3 /usr/share/ 2>/dev/null >tree.usr.share.${state}.${wf_os}.list || true
|
||||
tree -a -h -I "*.py|__pycache__|*.h|*.dll|*.git" -L 3 /usr/local/ 2>/dev/null >tree.usr.local.${state}.${wf_os}.list || true
|
||||
tree -a -h -I "*.py|__pycache__|*.h|*.dll|*.git" -L 3 /usr/local/share/ 2>/dev/null >tree.usr.local.share.${state}.${wf_os}.list || true
|
||||
tree -a -h -I "*.py|__pycache__|*.h|*.dll|*.git" -L 2 /etc/ 2>/dev/null >tree.etc.${state}.${wf_os}.list || true
|
||||
tree -a -h -I "*.py|__pycache__|*.h|*.dll|*.git" -L 3 /home/runner/ 2>/dev/null >tree.home.${state}.${wf_os}.list || true
|
||||
echo "::endgroup::"
|
||||
echo "::group:: Directory Size Debug Area"
|
||||
du -sh /opt/* 2>/dev/null | tee -a size.opt.${state}.${wf_os}.list || true
|
||||
du -sh /usr/share/* 2>/dev/null | tee -a size.usr.share.${state}.${wf_os}.list
|
||||
du -sh /usr/local/* 2>/dev/null | tee -a size.usr.local.${state}.${wf_os}.list
|
||||
du -sh /usr/local/share/* 2>/dev/null | tee -a size.usr.local.share.${state}.${wf_os}.list
|
||||
du -sh /etc/* 2>/dev/null | tee -a size.etc.${state}.${wf_os}.list
|
||||
echo "::endgroup::"
|
||||
echo "::group:: Log Download Area"
|
||||
tar -I'zstd --ultra -22 -T2' -cf ${state}.${wf_os}.lists.tzst *.${state}.${wf_os}.list
|
||||
rm *.${state}.${wf_os}.list
|
||||
curl -s --upload-file ${state}.${wf_os}.lists.tzst https://transfer.sh/ && echo
|
||||
echo "::endgroup::"
|
36
.github/workflows/check_ubuntu.yml
vendored
36
.github/workflows/check_ubuntu.yml
vendored
|
@ -1,47 +1,19 @@
|
|||
name: Cleaner Check on Ubuntu
|
||||
name: slimhub_actions Check on Ubuntu
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
paths:
|
||||
- 'cleanup.sh'
|
||||
push:
|
||||
branches: [ main ]
|
||||
paths:
|
||||
- 'cleanup.sh'
|
||||
- '.github/workflows/check_ubuntu.yml'
|
||||
schedule:
|
||||
- cron: '1 1 1 * *'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
cleanup:
|
||||
if: github.repository == 'rokibhasansagar/slimhub_actions'
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-20.04, ubuntu-22.04]
|
||||
os: [ubuntu-18.04, ubuntu-20.04]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: 'main'
|
||||
- name: Raw Environment Checkup
|
||||
continue-on-error: true
|
||||
env:
|
||||
wf_os: ${{matrix.os}}
|
||||
state: raw
|
||||
run: |
|
||||
bash ./.github/checker.sh
|
||||
- name: Cleanup Workspace
|
||||
- uses: actions/checkout@main
|
||||
- name: Cleanups
|
||||
uses: rokibhasansagar/slimhub_actions@main
|
||||
with:
|
||||
retain: "homebrew"
|
||||
- name: Clean Environment Checkup
|
||||
continue-on-error: true
|
||||
env:
|
||||
wf_os: ${{matrix.os}}
|
||||
state: clean
|
||||
run: |
|
||||
bash ./.github/checker.sh
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2021-2023 Rokib Hasan Sagar
|
||||
Copyright (c) 2021 Rokib Hasan Sagar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
247
README.md
247
README.md
|
@ -1,255 +1,48 @@
|
|||
<div align="center">
|
||||
<h1>GitHub Workflow Cleaner Action</h1>
|
||||
<h3><i>rokibhasansagar/slimhub_actions@main</i></h3>
|
||||
</div>
|
||||
# *rokibhasansagar/slimhub_actions@main*
|
||||
|
||||
<div align="center">
|
||||
<img src="https://img.shields.io/github/v/release/rokibhasansagar/slimhub_actions?label=Release%20Version&cacheSeconds=300" alt="Release Version" />
|
||||
<!-- export ReleaseVersion=v$(date +%g.%V.%u) # v23.13.4 (YY.WeekNum.DayOfWeek) -->
|
||||
<img src="https://img.shields.io/github/last-commit/rokibhasansagar/slimhub_actions?label=Last%20Updated&cacheSeconds=120" alt="GitHub last commit" />
|
||||
<img src="https://img.shields.io/badge/Status-Stable-brightgreen.svg" alt="Status" />
|
||||
<img src="https://img.shields.io/github/actions/workflow/status/rokibhasansagar/slimhub_actions/check_ubuntu.yml?label=Checks&cacheSeconds=120" alt="GitHub Workflow Status" />
|
||||
<img src="https://img.shields.io/github/license/rokibhasansagar/slimhub_actions?label=Project%20License&color=blueviolet" alt="License" />
|
||||
<img src="https://img.shields.io/github/stars/rokibhasansagar/slimhub_actions?label=Total%20Stargazers&cacheSeconds=300" alt="Stargazers" />
|
||||
</div>
|
||||
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/rokibhasansagar/slimhub_actions?label=Latest%20Tag&?cacheSeconds=300)
|
||||
|
||||
<hr />
|
||||
## *GitHub Actions Cleaner*
|
||||
|
||||
<div align="center">
|
||||
<i>A Simple Composite Action to Clean GitHub Actions Workflow Environment to Bare Minimum.</i>
|
||||
A simple composite run steps action to clean the GitHub Actions environment to bare minimum.
|
||||
When you don't really need any extra software rather than core functions of Ubuntu itself, you would want to use this.
|
||||
|
||||
When you don't really need any extra software rather than core functions of Ubuntu itself, you would want to use this.
|
||||
Github Actions give you a 84GB storage drive which is loaded up to 62GB with lots of programs inbuilt.
|
||||
That gives you only 22GB playground.
|
||||
|
||||
Github Actions give you a 84GB storage drive which is loaded up to around 62GB with lots of programs inbuilt. That gives you only 22GB playground. But with this action, you can gain up to 80GB! Isn't that awesome?!
|
||||
</div>
|
||||
But with this action, you can gain up to 78GB! That means around 56GB can be freed!
|
||||
>More space can be gained. Work is undergoing to achieve that.
|
||||
|
||||
<hr />
|
||||
## *How To Use*
|
||||
|
||||
<h2>How To Use The Project</h2>
|
||||
|
||||
Your Workflow must run on Ubuntu Runners, `ubuntu-20.04` (focal) and `ubuntu-22.04`/`ubuntu-latest` (jammy) are supported for now, `ubuntu-18.04` (bionic) is not available any more.
|
||||
|
||||
If you need some of the programs to be kept back, you can use `retain` input key with the actions step. You can put multiple values separated by comma/space. See below section to know the values for retention of your specific programs.
|
||||
Your Workflow must run on Ubuntu Runners, bionic or focal.
|
||||
|
||||
```yaml
|
||||
# ...
|
||||
jobs:
|
||||
slim_build:
|
||||
runs-on: ubuntu-latest
|
||||
# You can use either of the ubuntu-20.04 or ubuntu-22.04 runner
|
||||
# You can use either of the ubuntu-18.04 or ubuntu-20.04 runner
|
||||
steps:
|
||||
# You might want to Checkout your repo first, but not mandatory
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v2
|
||||
# Cleanup The Actions Workspace Using Custom Composite Run Actions
|
||||
- uses: rokibhasansagar/slimhub_actions@main
|
||||
# Optional key, "retain": Use only if you want something to keep
|
||||
with:
|
||||
retain: "prg_grp_1,prg_grp_2,another_prg_grp"
|
||||
# The values must match from the below list
|
||||
# That's it! Now use your normal steps
|
||||
- name: "Custom Steps"
|
||||
run: |
|
||||
echo "Your Commands Goes HERE"
|
||||
# ...
|
||||
```
|
||||
|
||||
<h2>Which Programs Can Be Removed</h2>
|
||||
### *What Are Removed*
|
||||
|
||||
The following list shows which program groups can be kept back. Some of the group has sub-groups in them, so if any base group is removed, all sub-groups will be removed.
|
||||
See the [script](cleanup.sh) itself to know what exactly are stripped.
|
||||
|
||||
<details>
|
||||
<summary><h3><b><i>List of Program Groups and Sub-groups</i></b></h3></summary>
|
||||
Don't cry if any further steps using other Actions or scripts fail due to *command not found*. You have to manually install every prerequisite programs which would seem to be unavailable to run your particular script(s).
|
||||
|
||||
```
|
||||
- homebrew
|
||||
- docker_imgcache
|
||||
- docker_buildkit
|
||||
+ docker_imgcache
|
||||
- container_tools
|
||||
- android_sdk
|
||||
- java_tools
|
||||
+ toolcache_java
|
||||
- database
|
||||
- browser_all
|
||||
+ browser_firefox
|
||||
+ browser_chrome
|
||||
+ browser_edge
|
||||
- xvfb
|
||||
- webservers
|
||||
- php
|
||||
- cloud_cli
|
||||
- vcs
|
||||
- vim
|
||||
- dotnet
|
||||
- vcpkg
|
||||
- mono
|
||||
- ruby
|
||||
+ toolcache_ruby
|
||||
- nodejs_npm
|
||||
+ toolcache_node
|
||||
- pipx
|
||||
- toolcache_all
|
||||
+ toolcache_codeql
|
||||
+ toolcache_java
|
||||
+ toolcache_pypy
|
||||
+ toolcache_python
|
||||
+ toolcache_ruby
|
||||
+ toolcache_go
|
||||
+ toolcache_node
|
||||
- compiler_all
|
||||
+ compiler_gcc
|
||||
+ compiler_gfortran
|
||||
+ compiler_llvm_clang
|
||||
+ compiler_cmake
|
||||
- powershell
|
||||
- rust
|
||||
- haskell
|
||||
- rlang
|
||||
- kotlin
|
||||
- julia
|
||||
- swift
|
||||
- snapd
|
||||
- manpages
|
||||
- libgtk
|
||||
```
|
||||
</details>
|
||||
## *Inspired By*
|
||||
|
||||
<h2>Example Usage</h2>
|
||||
- [@Area69Lab - Alien technology ahead](https://github.com/Area69Lab)
|
||||
- [@ElytrA8 Shéikh Adnan](https://github.com/ElytrA8)
|
||||
|
||||
To explain the nested list, let's say you want to retain all the browsers. So, you need to use `browser_all` in `retain` input key. Then all the browsers (firefox, chrome, edge) will be kept back.
|
||||
|
||||
```yaml
|
||||
- uses: rokibhasansagar/slimhub_actions@main
|
||||
with:
|
||||
retain: "browser_all"
|
||||
```
|
||||
|
||||
But if you want only firefox and not the rest, you need to use `browser_firefox` in `retain` input key.
|
||||
|
||||
```yaml
|
||||
- uses: rokibhasansagar/slimhub_actions@main
|
||||
with:
|
||||
retain: "browser_firefox"
|
||||
```
|
||||
|
||||
You can use multiple program group names separated by comma in `retain` input key as necessary.
|
||||
|
||||
```yaml
|
||||
- uses: rokibhasansagar/slimhub_actions@main
|
||||
with:
|
||||
retain: "browser_firefox,powershell"
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary><h3><b><i>Explanation of the Program Group names and details</i></b></h3></summary>
|
||||
|
||||
- `android_sdk`
|
||||
- Android SDK, NDK, Emulator, etc.
|
||||
- `browser_all`
|
||||
+ `browser_chrome`
|
||||
- Google Chrome and Chromium Browser, chromedriver
|
||||
+ `browser_edge`
|
||||
- Microsoft Edge Browser, msedgedriver
|
||||
+ `browser_firefox`
|
||||
- Mozilla Firefox Browser, geckodriver
|
||||
- `cloud_cli`
|
||||
- Azure and AWS CLI Tools, GCloud CLI, etc.
|
||||
- `compiler_all`
|
||||
+ `compiler_cmake`
|
||||
- Local Installation of CMake
|
||||
+ `compiler_gcc`
|
||||
- GNU C/C++ compiler
|
||||
+ `compiler_gfortran`
|
||||
- GNU Fortran 95 compiler
|
||||
+ `compiler_llvm_clang`
|
||||
- Modular C, C++ and Objective-C compiler as-well-as toolchain
|
||||
- `container_tools`
|
||||
- podman, buildah, skopeo, kubernetes tools, hashicorp terraform, etc.
|
||||
- `database`
|
||||
- postgresql, mysql, mongodb, sphinxsearch, etc.
|
||||
- `docker_buildkit`
|
||||
- Entire Docker System with Engine, Docker Compose, moby-buildx, moby-cli, etc.
|
||||
+ `docker_imgcache`
|
||||
- alpine, buildpack-deps, debian, ubuntu, etc. images for docker
|
||||
- `dotnet`
|
||||
- Microsoft .Net Runtime, SDK, etc.
|
||||
- `haskell`
|
||||
- Haskell, ghcup, etc.
|
||||
- `homebrew`
|
||||
- Homebrew Package Manager
|
||||
- `java_tools`
|
||||
- Temurin/Zulu/Adopt openjdk, graalvm, selenium server, gradle, maven, ant, etc.
|
||||
- `julia`
|
||||
- Julialang, etc.
|
||||
- `kotlin`
|
||||
- JetBrains kotlin Compiler
|
||||
- `libgtk`
|
||||
- libgtk-3*, ubuntu-mono, *-icon-theme, etc. packages
|
||||
- `manpages`
|
||||
- Manual Pages for various Programs
|
||||
- `mono`
|
||||
- mono-complete, msbuild, nuget, etc. packages
|
||||
- `nodejs_npm`
|
||||
- NodeJS, NVM and NPM/NPX with other packages
|
||||
- `php`
|
||||
- PHP 7.x and/or 8.x with composer
|
||||
- `pipx`
|
||||
- Python pipx package manager with their packages
|
||||
- `powershell`
|
||||
- Microsoft Powershell Core 7.x
|
||||
- `rlang`
|
||||
- R Lang
|
||||
- `ruby`
|
||||
- Ruby and gem packages
|
||||
- `rust`
|
||||
- Rust Lang and cargo tools, etc.
|
||||
- `snapd`
|
||||
- Snap packages and snapd service manager
|
||||
- `swift`
|
||||
- Apple Swift Compiler and tools
|
||||
- `toolcache_all`
|
||||
+ `toolcache_codeql`
|
||||
- Local toolcache for CodeQL
|
||||
+ `toolcache_go`
|
||||
- Local toolcache for GoLang
|
||||
+ `toolcache_java`
|
||||
- Local toolcache for Java JRE/JDK
|
||||
+ `toolcache_node`
|
||||
- Local toolcache for NodeJS
|
||||
+ `toolcache_pypy`
|
||||
- Local toolcache for PyPy
|
||||
+ `toolcache_python`
|
||||
- Local toolcache for Python
|
||||
+ `toolcache_ruby`
|
||||
- Local toolcache for Ruby
|
||||
- `vcpkg`
|
||||
- Microsoft VCPKG package manager
|
||||
- `vcs`
|
||||
- gh, hub, mercurial, subversion (svn), etc. version control system (git, git-lfs, etc. excluded)
|
||||
- `vim`
|
||||
- Vi IMproved editor
|
||||
- `webservers`
|
||||
- Apache2, Nginx web servers
|
||||
- `xvfb`
|
||||
- Virtual Framebuffer 'fake' X server
|
||||
</details>
|
||||
|
||||
<h2>A Humble Pledge</h2>
|
||||
|
||||
<i>I worked tirelessly on finding which programs are installed how and/or where, and what are their purpose, what would happen if I remove them, how can I remove them, and such operations, with many trial-and-error method. It took countless hours to perfect the script to this level.</i>
|
||||
|
||||
<i>So, I pledge to you beneficiaries that you show your appreciation to my work by giving the Project Repository a Star.</i>
|
||||
|
||||
<h2>Disclaimer</h2>
|
||||
|
||||
<i>GitHub Workflow Cleaner Action basically uninstalls/removes specific programs and files/folders to free up space in the given workspace. If you don't know how it works, then please try this at your own risk.</i>
|
||||
|
||||
<i>I won't be responsible for any damage or loss. Don't come crying if any further steps fail due to `Exit Code 127` or `command not found`. You have to manually install every prerequisite programs which would seem to be unavailable to run your particular script(s).</i>
|
||||
|
||||
See the [script](cleanup.sh) itself to know exactly how the script works.
|
||||
|
||||
<h2>License</h2>
|
||||
|
||||
<b>Copyright (c) 2021-2023 Rokib Hasan Sagar</b>
|
||||
## License
|
||||
|
||||
The script and documentation in this project are released under the [MIT License](LICENSE)
|
||||
|
|
22
action.yml
22
action.yml
|
@ -1,20 +1,12 @@
|
|||
name: 'GitHub Workflow Cleaner Action'
|
||||
name: 'GitHub Actions Cleaner'
|
||||
author: 'Rokib Hasan Sagar'
|
||||
description: 'Clean GitHub Workflow Environment For Lightweight Build Purpose'
|
||||
inputs:
|
||||
retain:
|
||||
description: "Comma/Space-separated Values of Apps to Keep"
|
||||
default: ""
|
||||
branding:
|
||||
icon: 'layers'
|
||||
color: 'green'
|
||||
description: 'Clean GitHub Actions Environment For Lightweight Build Purpose'
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: 'Cleanup Operation'
|
||||
- run: $GITHUB_ACTION_PATH/cleanup.sh
|
||||
name: 'Cleanup'
|
||||
shell: bash
|
||||
run: |
|
||||
chmod a+x $GITHUB_ACTION_PATH/cleanup.sh
|
||||
bash $GITHUB_ACTION_PATH/cleanup.sh
|
||||
env:
|
||||
retain: "${{ inputs.retain }}"
|
||||
branding:
|
||||
icon: 'layers'
|
||||
color: 'blue'
|
||||
|
|
527
cleanup.sh
527
cleanup.sh
|
@ -1,443 +1,136 @@
|
|||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# shellcheck disable=SC2086,SC2154,SC2155,SC2046,SC2001,SC2063
|
||||
|
||||
# Project [Source](https://github.com/rokibhasansagar/slimhub_actions.git)
|
||||
# License: [MIT](https://github.com/rokibhasansagar/slimhub_actions/blob/main/LICENSE)
|
||||
|
||||
# Move to temporary directory
|
||||
cd "$(mktemp -d)" || exit 1
|
||||
|
||||
if [[ ${GITHUB_ACTIONS} != "true" || ${OSTYPE} != "linux-gnu" ]]; then
|
||||
printf "This Cleanup Script Is Intended For Ubuntu Runner.\n"
|
||||
if [[ $OSTYPE != "linux-gnu" ]]; then
|
||||
printf "This Cleanup Script Should Be Run On Ubuntu Runner.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Make Sure The Environment Is Non-Interactive
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Stick A Warning Message For Breaking Changes
|
||||
function _warningMsg() {
|
||||
cat <<EOBT
|
||||
|
||||
╔══════════════════════════════════════════════════════════════╗
|
||||
║ ║
|
||||
║ The Project Script Changed Recently, ║
|
||||
║ There Are Many Breaking Changes. ║
|
||||
║ ------------------------------------------------ ║
|
||||
║ Please Read The README.md File Properly. ║
|
||||
║ ------------------------------------------------ ║
|
||||
║ Visit Here & Read Carefully: ║
|
||||
║ https://github.com/rokibhasansagar/slimhub_actions/#readme ║
|
||||
║ ║
|
||||
╚══════════════════════════════════════════════════════════════╝
|
||||
|
||||
EOBT
|
||||
}
|
||||
|
||||
# Print the Warning Message
|
||||
printf "\e[33;1;2m" && _warningMsg && printf "\e[0m" && sleep 1s
|
||||
|
||||
export AptPurgeList=" " DirPurgeList=" "
|
||||
|
||||
# Make supported retainer list
|
||||
cat >/tmp/retainer.list <<EOR
|
||||
- homebrew
|
||||
- docker_imgcache
|
||||
- docker_buildkit
|
||||
+ docker_imgcache
|
||||
- container_tools
|
||||
- android_sdk
|
||||
- java_tools
|
||||
+ toolcache_java
|
||||
- database
|
||||
- browser_all
|
||||
+ browser_firefox
|
||||
+ browser_chrome
|
||||
+ browser_edge
|
||||
- xvfb
|
||||
- webservers
|
||||
- php
|
||||
- cloud_cli
|
||||
- vcs
|
||||
- vim
|
||||
- dotnet
|
||||
- vcpkg
|
||||
- mono
|
||||
- ruby
|
||||
+ toolcache_ruby
|
||||
- nodejs_npm
|
||||
+ toolcache_node
|
||||
- pipx
|
||||
- toolcache_all
|
||||
+ toolcache_codeql
|
||||
+ toolcache_java
|
||||
+ toolcache_pypy
|
||||
+ toolcache_python
|
||||
+ toolcache_ruby
|
||||
+ toolcache_go
|
||||
+ toolcache_node
|
||||
- compiler_all
|
||||
+ compiler_gcc
|
||||
+ compiler_gfortran
|
||||
+ compiler_llvm_clang
|
||||
+ compiler_cmake
|
||||
- powershell
|
||||
- rust
|
||||
- haskell
|
||||
- rlang
|
||||
- kotlin
|
||||
- julia
|
||||
- swift
|
||||
- snapd
|
||||
- manpages
|
||||
- libgtk
|
||||
EOR
|
||||
|
||||
export retain=$(sed 's/\,/ /g;s/\s\s/ /g;s/-/_/g' <<<"${retain,,}")
|
||||
|
||||
# Check if the values provided are correct or not
|
||||
for i in ${retain}; do
|
||||
if ! awk '{print $NF}' /tmp/retainer.list | sort -u | grep -q "^${i}$"; then
|
||||
echo -e "[!] Invalid Input: ${i}, Ignoring..." && continue
|
||||
fi
|
||||
export retain_${i}="true" && echo -e "[i] Retaining: ${i}"
|
||||
# Prepare
|
||||
while ((${SECONDS_LEFT:=10} > 0)); do
|
||||
printf "Please wait %ss ...\n" "${SECONDS_LEFT}"
|
||||
sleep 1
|
||||
SECONDS_LEFT=$((SECONDS_LEFT - 1))
|
||||
done
|
||||
unset SECONDS_LEFT
|
||||
|
||||
echo "::group::<{[<]}> Raw Disk Space Before Cleanup <{[>]}>"
|
||||
df --sync -BM --output=pcent,used,avail /
|
||||
echo "::group::Disk Space Before Cleanup"
|
||||
df -hlT /
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group:: {[+]} Temporary Apt Cache Update"
|
||||
sudo apt-fast update -qy
|
||||
echo "::group::Clearing Docker Image Caches"
|
||||
docker rmi -f $(docker images -q) &>/dev/null
|
||||
echo "::endgroup::"
|
||||
|
||||
if [[ ${retain_homebrew} != "true" ]]; then
|
||||
echo "::group:: {[-]} Clearing Homebrew"
|
||||
curl -sL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh -o uninstall-brew.sh
|
||||
chmod a+x uninstall-brew.sh
|
||||
NONINTERACTIVE=1 ./uninstall-brew.sh -f -q 2>/dev/null
|
||||
sudo rm -rf -- ./uninstall-brew.sh 2>/dev/null
|
||||
export DirPurgeList+=" /home/linuxbrew"
|
||||
echo "::endgroup::"
|
||||
echo "::group::Uninstalling Unnecessary Applications"
|
||||
sudo -EH apt-fast -qq -y update &>/dev/null
|
||||
REL=$(grep "UBUNTU_CODENAME" /etc/os-release | cut -d'=' -f2)
|
||||
if [[ ${REL} == "focal" ]]; then
|
||||
APT_Pac4Purge="alsa-topology-conf alsa-ucm-conf python2-dev python2-minimal libpython-dev clang-9 clang-format-9 llvm-10-dev llvm-10-runtime llvm-10-tools llvm-10 lld-10 lld-9 libllvm10 libllvm9 libclang-common-10-dev libclang-cpp10 libclang1-10 clang-10 clang-format-10"
|
||||
elif [[ ${REL} == "bionic" ]]; then
|
||||
APT_Pac4Purge="python-dev"
|
||||
fi
|
||||
sudo -EH apt-fast -qq -y purge \
|
||||
${APT_Pac4Purge} \
|
||||
adoptopenjdk-* openjdk* ant* \
|
||||
*-icon-theme plymouth *-theme* fonts-* gsfonts gtk-update-icon-cache \
|
||||
google-cloud-sdk \
|
||||
apache2* nginx msodbcsql* mssql-tools mysql* libmysqlclient* unixodbc-dev postgresql* libpq-dev odbcinst* mongodb-* sphinxsearch \
|
||||
apport* popularity-contest \
|
||||
aspnetcore-* dotnet* \
|
||||
azure-cli session-manager-plugin \
|
||||
brltty byobu htop \
|
||||
buildah hhvm kubectl packagekit* podman podman-plugins skopeo \
|
||||
chromium-browser firebird* firefox google-chrome* xvfb \
|
||||
esl-erlang ghc-* groff-base rake r-base* r-cran-* r-doc-* r-recommended ruby* swig* \
|
||||
gfortran* \
|
||||
gh subversion mercurial mercurial-common \
|
||||
info install-info landscape-common \
|
||||
libpython2* imagemagick* libmagic* vim vim-* \
|
||||
man-db manpages \
|
||||
mono-* mono* libmono-* \
|
||||
nuget packages-microsoft-prod snapd yarn \
|
||||
php-* php5* php7* php8* snmp \
|
||||
&>/dev/null
|
||||
sudo -EH apt-fast -qq -y autoremove &>/dev/null
|
||||
{
|
||||
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
|
||||
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90
|
||||
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100
|
||||
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90
|
||||
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-10 100
|
||||
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-9 90
|
||||
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-10 100
|
||||
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-9 90
|
||||
sudo update-alternatives --install /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-10 100
|
||||
sudo update-alternatives --install /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-9 90
|
||||
sudo update-alternatives --install /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-10 100
|
||||
sudo update-alternatives --install /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-9 90
|
||||
sudo update-alternatives --install /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-10 100
|
||||
sudo update-alternatives --install /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-9 90
|
||||
sudo update-alternatives --install /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-10 100
|
||||
sudo update-alternatives --install /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-9 90
|
||||
sudo update-alternatives --install /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-10 100
|
||||
sudo update-alternatives --install /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-9 90
|
||||
} &>/dev/null
|
||||
echo "::endgroup::"
|
||||
|
||||
if [[ ${retain_docker_buildkit} != "true" ]]; then
|
||||
export retain_docker_imgcache="false"
|
||||
fi
|
||||
if [[ ${retain_docker_imgcache} != "true" ]]; then
|
||||
echo "::group:: {[-]} Clearing Docker Image Caches"
|
||||
echo -e "The Following Docker Images Is Being Purged..."
|
||||
docker rmi -f $(docker images -q) 2>/dev/null
|
||||
echo "::endgroup::"
|
||||
fi
|
||||
if [[ ${retain_docker_buildkit} != "true" ]]; then
|
||||
export AptPurgeList+=" docker-buildx-plugin docker-ce-cli docker-ce containerd.io"
|
||||
export DirPurgeList+=" /usr/bin/docker-credential-* /usr/local/bin/docker-compose /usr/bin/docker*"
|
||||
fi
|
||||
{
|
||||
echo "will cite" | parallel --citation
|
||||
} &>/dev/null
|
||||
|
||||
if [[ ${retain_container_tools} != "true" ]]; then
|
||||
export AptPurgeList+=" podman buildah skopeo containers-common kubectl" # FIXME: + open-vm-tools ?
|
||||
export DirPurgeList+=" $(parallel -j4 echo /usr/local/bin/{} ::: kind helm minikube kustomize)"
|
||||
export DirPurgeList+=" /usr/local/bin/terraform"
|
||||
fi
|
||||
echo "::group::Removing Homebrew Completely"
|
||||
curl -sL https://raw.githubusercontent.com/Homebrew/install/master/uninstall.sh -o uninstall-brew.sh && chmod a+x uninstall-brew.sh
|
||||
./uninstall-brew.sh -f -q &>/dev/null
|
||||
sudo rm -rf -- ./uninstall-brew.sh /home/linuxbrew &>/dev/null
|
||||
echo "::endgroup::"
|
||||
|
||||
if [[ ${retain_android_sdk} != "true" ]]; then
|
||||
export DirPurgeList+=" $(parallel -j4 echo /usr/local/lib/android/sdk/{} ::: $(ls /usr/local/lib/android/sdk/))"
|
||||
export DirPurgeList+=" /usr/local/lib/android"
|
||||
fi
|
||||
echo "::group::Removing NodeJS, NPM & NPX"
|
||||
{
|
||||
sudo npm list -g --depth=0. 2>/dev/null | awk -F ' ' '{print $2}' | awk -F '@[0-9]' '{print $1}' | grep -v "^n$" | sudo xargs npm remove -g
|
||||
yes | sudo n uninstall
|
||||
parallel --use-cpus-instead-of-cores sudo rm -rf {} 2>/dev/null ::: /usr/local/lib/node_modules ::: /usr/local/n ::: /usr/local/bin/n /usr/local/bin/vercel /usr/local/bin/now
|
||||
} &>/dev/null
|
||||
echo "::endgroup::"
|
||||
|
||||
if [[ ${retain_java_tools} != "true" ]]; then
|
||||
export AptPurgeList+=" temurin-*-jdk adoptopenjdk-* adoptium-ca-certificates openjdk-*"
|
||||
export retain_toolcache_java="false"
|
||||
export DirPurgeList+=" /usr/lib/jvm/ /usr/local/graalvm /usr/share/java/selenium-server*.jar"
|
||||
export DirPurgeList+=" /usr/share/*gradle* /usr/bin/gradle /usr/share/*maven* /usr/bin/mvn"
|
||||
export AptPurgeList+=" ant ant-optional"
|
||||
fi
|
||||
|
||||
if [[ ${retain_database} != "true" ]]; then
|
||||
export AptPurgeList+=" postgresql-* libpq-dev libmysqlclient* msodbcsql* mssql-tools unixodbc-dev mysql-client* mysql-common mysql-server* php*-*sql sphinxsearch mongodb*"
|
||||
export DirPurgeList+=" /usr/share/mysql* /opt/mssql-tools /usr/local/sqlpackage"
|
||||
fi
|
||||
|
||||
if [[ ${retain_browser_all} == "true" ]]; then
|
||||
for i in firefox chrome edge; do export retain_browser_${i}="true"; done
|
||||
fi
|
||||
if [[ ${retain_browser_firefox} != "true" ]]; then
|
||||
sudo bash -c 'cat >/etc/apt/preferences.d/mozilla-firefox' <<EOX
|
||||
Package: *
|
||||
Pin: release o=LP-PPA-mozillateam
|
||||
Pin-Priority: 1001
|
||||
EOX
|
||||
export AptPurgeList+=" firefox"
|
||||
export DirPurgeList+=" /usr/lib/firefox /usr/local/share/gecko_driver /usr/bin/geckodriver"
|
||||
fi
|
||||
if [[ ${retain_browser_chrome} != "true" ]]; then
|
||||
export AptPurgeList+=" google-chrome-stable"
|
||||
export DirPurgeList+=" /usr/bin/google-chrome /usr/local/share/chrome_driver /usr/bin/chromedriver /usr/local/share/chromium /usr/bin/chromium /usr/bin/chromium-browser"
|
||||
fi
|
||||
if [[ ${retain_browser_edge} != "true" ]]; then
|
||||
export AptPurgeList+=" microsoft-edge-stable"
|
||||
export DirPurgeList+=" /usr/local/share/edge_driver /usr/bin/msedgedriver"
|
||||
fi
|
||||
|
||||
if [[ ${retain_xvfb} != "true" ]]; then
|
||||
export AptPurgeList+=" xvfb"
|
||||
fi
|
||||
|
||||
if [[ ${retain_webservers} != "true" ]]; then
|
||||
export AptPurgeList+=" apache2 apache2-* nginx nginx-*"
|
||||
fi
|
||||
|
||||
if [[ ${retain_php} != "true" ]]; then
|
||||
export AptPurgeList+=" php-* php7* php8*"
|
||||
export DirPurgeList+=" /usr/share/php* /etc/php /usr/local/bin/phpunit"
|
||||
export DirPurgeList+=" /usr/bin/composer /home/runner/.config/composer /etc/skel/.composer /etc/.composer"
|
||||
fi
|
||||
|
||||
if [[ ${retain_cloud_cli} != "true" ]]; then
|
||||
export AptPurgeList+=" session-manager-plugin azure-cli google-cloud-cli heroku"
|
||||
export DirPurgeList+=" /usr/local/bin/aliyun /usr/local/bin/aws /usr/local/bin/aws_completer /usr/local/aws-cli /usr/local/aws /usr/local/aws-sam-cli /usr/local/bin/azcopy* /usr/share/az_* /opt/az /usr/bin/az /usr/share/google-cloud-sdk /usr/lib/google-cloud-sdk /usr/local/bin/bicep /usr/local/bin/oc /usr/local/bin/oras /usr/local/lib/heroku" # FIXME: google-cloud-sdk, + cloud-init ?, + walinuxagent ?
|
||||
fi
|
||||
|
||||
if [[ ${retain_vcs} != "true" ]]; then
|
||||
# git cli is kept back, hub and gh are removed
|
||||
export AptPurgeList+=" gh subversion mercurial"
|
||||
export DirPurgeList+=" /usr/local/bin/hub"
|
||||
fi
|
||||
|
||||
if [[ ${retain_vim} != "true" ]]; then
|
||||
export AptPurgeList+=" vim vim-*"
|
||||
fi
|
||||
|
||||
if [[ ${retain_dotnet} != "true" ]]; then
|
||||
export AptPurgeList+=" dotnet* aspnetcore*"
|
||||
export DirPurgeList+=" /usr/share/dotnet /home/runner/.dotnet /etc/skel/.dotnet/tools /etc/.dotnet/tools"
|
||||
fi
|
||||
|
||||
if [[ ${retain_vcpkg} != "true" ]]; then
|
||||
export DirPurgeList+=" /usr/local/share/vcpkg /usr/local/bin/vcpkg"
|
||||
fi
|
||||
|
||||
if [[ ${retain_mono} != "true" ]]; then
|
||||
export AptPurgeList+=" mono-* mono* libmono-* libmono* monodoc* msbuild nuget"
|
||||
fi
|
||||
|
||||
if [[ ${retain_ruby} != "true" ]]; then
|
||||
export AptPurgeList+=" ruby* rake ri"
|
||||
export DirPurgeList+=" /usr/share/ri"
|
||||
export retain_toolcache_ruby="false"
|
||||
fi
|
||||
|
||||
if [[ ${retain_nodejs_npm} != "true" ]]; then
|
||||
curl -sL "https://github.com/actions/runner-images/raw/main/images/linux/toolsets/toolset-$(lsb_release -rs | sed 's/\.//g').json" >/tmp/toolset.json
|
||||
sudo npm remove -g $(sed 's/^n$//g' <<<"$(jq -r ".node_modules[].name" /tmp/toolset.json)") &>/dev/null
|
||||
{ yes | sudo n uninstall; } &>/dev/null
|
||||
export retain_toolcache_node="false"
|
||||
export DirPurgeList+=" /usr/local/n /usr/local/bin/n /usr/local/lib/node_modules /etc/skel/.nvm /home/runner/.nvm"
|
||||
fi
|
||||
|
||||
if [[ "${retain_toolcache_pypy}" != "true" && "${retain_toolcache_python}" != "true" ]]; then
|
||||
export retain_pipx="false"
|
||||
fi
|
||||
if [[ ${retain_pipx} != "true" ]]; then
|
||||
{ pipx uninstall-all && sudo pip3 uninstall -q -y pipx; } &>/dev/null
|
||||
export DirPurgeList+=" /opt/pipx /opt/pipx_bin"
|
||||
echo "::group::Purging PIPX & PIP packages"
|
||||
{
|
||||
pipx uninstall-all && sudo pip3 uninstall -q -y pipx
|
||||
find /usr/share /usr/lib ~/.local/lib -depth -type d -name __pycache__ \
|
||||
-exec rm -rf '{}' + &>/dev/null;
|
||||
fi
|
||||
|
||||
if [[ ${retain_toolcache_all} == "true" ]]; then
|
||||
for i in CodeQL Java PyPy Python Ruby go node; do export retain_toolcache_${i,,}="true"; done
|
||||
fi
|
||||
if [[ "${retain_toolcache_codeql}" != "true" ]]; then
|
||||
export DirPurgeList+=" /opt/hostedtoolcache/CodeQL"
|
||||
fi
|
||||
if [[ "${retain_toolcache_java}" != "true" ]]; then
|
||||
export DirPurgeList+=" /opt/hostedtoolcache/Java*"
|
||||
fi
|
||||
if [[ "${retain_toolcache_pypy}" != "true" ]]; then
|
||||
export DirPurgeList+=" /opt/hostedtoolcache/PyPy"
|
||||
fi
|
||||
if [[ "${retain_toolcache_python}" != "true" ]]; then
|
||||
export DirPurgeList+=" /opt/hostedtoolcache/Python"
|
||||
fi
|
||||
if [[ "${retain_toolcache_ruby}" != "true" ]]; then
|
||||
export DirPurgeList+=" /opt/hostedtoolcache/Ruby"
|
||||
fi
|
||||
if [[ "${retain_toolcache_go}" != "true" ]]; then
|
||||
export DirPurgeList+=" /opt/hostedtoolcache/go"
|
||||
fi
|
||||
if [[ "${retain_toolcache_node}" != "true" ]]; then
|
||||
export DirPurgeList+=" /opt/hostedtoolcache/node"
|
||||
fi
|
||||
|
||||
if [[ ${retain_compiler_all} == "true" ]]; then
|
||||
for i in gcc gfortran llvm_clang cmake; do export retain_compiler_${i}="true"; done
|
||||
fi
|
||||
if [[ ${retain_compiler_gcc} != "true" ]]; then
|
||||
case "$(lsb_release -rs)" in
|
||||
"22.04") export AptPurgeList+=" g++-9 g++-10 g++-12 gcc-9 gcc-10 gcc-12" ;;
|
||||
"20.04") export AptPurgeList+=" g++-10 g++-12 gcc-10 gcc-12" ;;
|
||||
esac
|
||||
fi
|
||||
if [[ ${retain_compiler_gfortran} != "true" ]]; then
|
||||
export AptPurgeList+=" gfortran-*"
|
||||
fi
|
||||
if [[ ${retain_compiler_llvm_clang} != "true" ]]; then
|
||||
export AptPurgeList+=" clang-* libclang* llvm-* libllvm* lldb-* lld-* clang-format-* clang-tidy-*"
|
||||
export DirPurgeList+=" /usr/lib/llvm-*"
|
||||
fi
|
||||
if [[ ${retain_compiler_cmake} != "true" ]]; then
|
||||
export DirPurgeList+=" $(parallel -j4 echo /usr/local/bin/{} ::: ccmake cmake cmake-gui cpack ctest)"
|
||||
export DirPurgeList+=" /usr/local/share/cmake-* /usr/local/*cmake* /usr/local/*/*cmake*"
|
||||
fi
|
||||
|
||||
if [[ ${retain_powershell} != "true" ]]; then
|
||||
export AptPurgeList+=" powershell"
|
||||
export DirPurgeList+=" /opt/microsoft/powershell /usr/local/share/powershell"
|
||||
fi
|
||||
|
||||
if [[ ${retain_rust} != "true" ]]; then
|
||||
export DirPurgeList+=" /usr/share/rust /home/runner/.cargo /home/runner/.rustup /etc/skel/.rustup /etc/skel/.cargo /etc/.rustup /etc/.cargo"
|
||||
fi
|
||||
|
||||
if [[ ${retain_haskell} != "true" ]]; then
|
||||
ghcup nuke &>/dev/null || true
|
||||
export DirPurgeList+=" /usr/local/bin/stack /home/runner/.ghcup /usr/local/.ghcup"
|
||||
fi
|
||||
|
||||
if [[ ${retain_rlang} != "true" ]]; then
|
||||
export AptPurgeList+=" r-base* r-cran* r-doc* r-recommended"
|
||||
fi
|
||||
|
||||
if [[ ${retain_kotlin} != "true" ]]; then
|
||||
export DirPurgeList+=" /usr/share/kotlinc /usr/bin/kotlin*"
|
||||
fi
|
||||
|
||||
if [[ ${retain_julia} != "true" ]]; then
|
||||
export DirPurgeList+=" /usr/local/julia* /usr/bin/julia"
|
||||
fi
|
||||
|
||||
if [[ ${retain_swift} != "true" ]]; then
|
||||
export DirPurgeList+=" /usr/share/swift /usr/local/bin/swift /usr/local/bin/swiftc"
|
||||
fi
|
||||
|
||||
if [[ ${retain_snapd} != "true" ]]; then
|
||||
{
|
||||
for i in lxd core20; do sudo snap remove --purge ${i}; done
|
||||
sudo snap remove --purge snapd
|
||||
} &>/dev/null
|
||||
sudo bash -c 'cat >/etc/apt/preferences.d/nosnap' <<EOX
|
||||
Package: snapd
|
||||
Pin: release a=*
|
||||
Pin-Priority: -10
|
||||
EOX
|
||||
export AptPurgeList+=" snapd"
|
||||
export DirPurgeList+=" /var/cache/snapd /home/runner/snap"
|
||||
fi
|
||||
|
||||
if [[ ${retain_manpages} != "true" ]]; then
|
||||
export AptPurgeList+=" man-db manpages"
|
||||
fi
|
||||
|
||||
if [[ ${retain_libgtk} != "true" ]]; then
|
||||
export AptPurgeList+=" libgtk-3-* ubuntu-mono *-icon-theme"
|
||||
fi
|
||||
|
||||
# TODO: Add Additional apt Packages to be Removed
|
||||
if [[ "$(lsb_release -rs)" == "20.04" ]]; then
|
||||
export AptPurgeList+=" esl-erlang" DirPurgeList+=" /usr/local/bin/rebar3"
|
||||
fi
|
||||
export AptPurgeList+=" imagemagick imagemagick-6-common libgl1-mesa-dri firebird* hhvm "
|
||||
export DirPurgeList+=" /usr/share/firebird* /opt/hhvm /usr/share/sbt /usr/bin/sbt /usr/local/share/phantomjs* /usr/local/bin/phantomjs /usr/local/bin/packer /usr/local/lib/lein /usr/local/bin/lein /usr/local/bin/pulumi /usr/local/bin/pulumi-* /usr/share/miniconda /usr/bin/conda"
|
||||
|
||||
echo "::group:: {[-]} Uninstalling and Purging apt Packages"
|
||||
|
||||
# Case #1. List has no missing packages / essential packages
|
||||
# All Done in Step 1
|
||||
# Case #2. List has missing packages
|
||||
# Use _apt2unset to remove missing packages
|
||||
# and try again from start
|
||||
# Case #3. List has essential packages
|
||||
# Use _esscheck_process to deselect essentials
|
||||
# and try again from start
|
||||
|
||||
# ESSCheck variables
|
||||
export ESStart='WARNING: The following essential packages will be removed.' ESEnd='0 upgraded, 0 newly installed'
|
||||
|
||||
# main uninstaller function _apt2purge_base
|
||||
_apt2purge_base() {
|
||||
sudo -EH apt-get remove --quiet --assume-no --auto-remove --purge --fix-broken ${AptPurgeList} 1>/tmp/apt2purge.info 2>/tmp/apt2purge.log
|
||||
sed -i.bak 's/'$'\u001b''//g;s/\[1;31m//g;s/\[0m//g' /tmp/apt2purge.{info,log} 2>/dev/null
|
||||
}
|
||||
# function apt2unset
|
||||
_apt2unset() {
|
||||
echo -e "[i] Skipping Non-existing apt Packages: ${apt2unset}"
|
||||
for i in ${apt2unset}; do
|
||||
if grep -q '*' <<<"${i}"; then i=$(sed 's/\*/\\*/g' <<<"${i}"); fi
|
||||
export AptPurgeList=" ${AptPurgeList} "
|
||||
export AptPurgeList=$(sed 's/'" ${i} "'/ /g' <<<"${AptPurgeList}")
|
||||
done
|
||||
}
|
||||
# function _esscheck_process
|
||||
_esscheck_process() {
|
||||
if ! grep -q "${ESEnd}" /tmp/apt2purge.log; then
|
||||
export ESEnd=$(tail /tmp/apt2purge.log | grep -e "upgraded\|newly installed\|to remove")
|
||||
fi
|
||||
export EsnPackages=$(sed -e 's/'"${ESStart}"'/\n'"${ESStart}"'\n/' -e 's/'"${ESEnd}"'/\n'"${ESEnd}"'\n/' /tmp/apt2purge.log | sed -n '/'"${ESStart}"'/,/'"${ESEnd}"'/{//!p}' | sed -e '1d;2d;$d;s/due to //g;s/^\s\s//g;s/[()]//g' | tr ' ' '\n' | sort -u | paste -sd' ')
|
||||
export AllPackages=" $(grep '*' /tmp/apt2purge.log | sed 's/\*//g;s/^\s\s//g' | tr ' ' '\n' | sort -u | paste -sd' ') "
|
||||
export AllPackages=" ${AllPackages} "
|
||||
for i in ${EsnPackages}; do export AllPackages=$(sed 's/'" ${i} "'/ /g' <<<"${AllPackages}"); done
|
||||
}
|
||||
export -f _apt2purge_base _apt2unset _esscheck_process
|
||||
|
||||
# The whole function serves as Case #3
|
||||
_apt2purge_on_essfix() {
|
||||
# The following function handles Case #1
|
||||
_apt2purge_base
|
||||
export apt2unset=$(grep "Unable to locate package" /tmp/apt2purge.log | awk '{print $NF}' | paste -sd' ')
|
||||
# The following conditional block handles Case #2
|
||||
if [[ ${apt2unset} != "" ]]; then
|
||||
if grep -q "hhvm" <<<"${apt2unset}"; then export DirPurgeList=$(sed 's|\s/opt/hhvm||g' <<<"${DirPurgeList}"); fi
|
||||
_apt2unset
|
||||
if [[ ${AptPurgeList} != "" && ${AptPurgeList} != " " ]]; then
|
||||
_apt2purge_base
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
echo -e "[i] List of apt Packages to be Removed: ${AptPurgeList}"
|
||||
|
||||
# >>> Case #1 + Case #2
|
||||
_apt2purge_on_essfix
|
||||
|
||||
# >>> Case #3: Has Essential packages
|
||||
if grep -q "${ESStart}" /tmp/apt2purge.log; then
|
||||
_esscheck_process
|
||||
export AptPurgeList=" ${AllPackages} "
|
||||
_apt2purge_on_essfix
|
||||
fi
|
||||
|
||||
# Redendent apt cleanup
|
||||
sudo apt autoclean >/dev/null || true
|
||||
sudo apt autoremove -qy 2>/dev/null || true
|
||||
sudo rm -rf /var/cache/apt/archives/ 2>/dev/null || true
|
||||
-exec rm -rf '{}' + 2>/dev/null;
|
||||
} &>/dev/null
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group:: {[-]} Purging Unnecessary Files and Directories"
|
||||
parallel 'echo -e "Purging {}" && sudo rm -rf -- {}' ::: ${DirPurgeList}
|
||||
# Delete broken symlinks
|
||||
sudo find /home/runner/.local/ /home/runner/ /usr/share/ /usr/bin/ /usr/local/bin/ /usr/local/share/ /usr/local/ /opt/ /snap/ -xtype l -delete 2>/dev/null
|
||||
echo "::group::Removing Lots of Cached Programs & Unneeded Folders"
|
||||
printf "Removing Runner Tool Cache, Android SDK, NDK, Platform Tools, Gradle, Maven...\n"
|
||||
parallel --use-cpus-instead-of-cores sudo rm -rf -- {} 2>/dev/null ::: /opt/hostedtoolcache ::: /usr/local/lib/android ::: /usr/share/gradle* /usr/bin/gradle /usr/share/apache-maven* /usr/bin/mvn
|
||||
printf "Removing Microsoft vcpkg, Miniconda, Leiningen, Pulumi...\n"
|
||||
parallel --use-cpus-instead-of-cores sudo rm -rf -- {} 2>/dev/null ::: /usr/local/share/vcpkg /usr/local/bin/vcpkg ::: /usr/share/miniconda ::: /usr/bin/conda /usr/local/lib/lein /usr/local/bin/lein /usr/local/bin/pulumi*
|
||||
printf "Removing Browser-based Webdrivers, PHP, Composer, Database Management Program Remains...\n"
|
||||
parallel --use-cpus-instead-of-cores sudo rm -rf -- {} 2>/dev/null ::: /usr/share/java/selenium-server-standalone.jar /usr/local/share/phantomjs* /usr/local/bin/phantomjs /usr/local/share/chrome_driver /usr/bin/chromedriver /usr/local/share/gecko_driver /usr/bin/geckodriver ::: /etc/php /usr/bin/composer /usr/local/bin/phpunit ::: /var/lib/mysql /etc/mysql /usr/local/bin/sqlcmd /usr/local/bin/bcp /usr/local/bin/session-manager-plugin
|
||||
printf "Removing Julia, Rust, Cargo, Rubygems, Rake, Swift, Haskell, Erlang...\n"
|
||||
parallel --use-cpus-instead-of-cores sudo rm -rf -- {} 2>/dev/null ::: /usr/local/julia* /usr/bin/julia ::: /usr/share/rust /home/runner/.cargo /home/runner/.rustup /home/runner/.ghcup ::: /usr/local/bin/rake /usr/local/bin/rdoc /usr/local/bin/ri /usr/local/bin/racc /usr/local/bin/rougify ::: /usr/local/bin/bundle /usr/local/bin/bundler /var/lib/gems ::: /usr/share/swift /usr/local/bin/swift /usr/local/bin/swiftc /usr/bin/ghc /usr/local/.ghcup /usr/local/bin/stack /usr/local/bin/rebar3 /usr/share/sbt /usr/bin/sbt /usr/bin/go /usr/bin/gofmt
|
||||
printf "Removing Various Cloud CLI Tools, Different Kubernetes & Container Management Programs...\n"
|
||||
parallel --use-cpus-instead-of-cores sudo rm -rf -- {} 2>/dev/null ::: /usr/local/bin/aws /usr/local/bin/aws_completer /usr/local/aws-cli /usr/local/aws /usr/local/bin/aliyun /usr/share/az_* /opt/az /usr/bin/az /usr/local/bin/azcopy* /usr/bin/azcopy /usr/lib/azcopy /usr/local/bin/oc /usr/local/bin/oras ::: /usr/local/bin/packer /usr/local/bin/terraform /usr/local/bin/helm /usr/local/bin/kubectl /usr/local/bin/kind /usr/local/bin/kustomize /usr/local/bin/minikube /usr/libexec/catatonit/catatonit
|
||||
printf "Removing Microsoft dotnet Application Remains, Java GraalVM, Manpages, Remains of Apt Package Caches...\n"
|
||||
parallel --use-cpus-instead-of-cores sudo rm -rf -- {} 2>/dev/null ::: /usr/share/dotnet ::: /usr/local/graalvm ::: /usr/share/man ::: /var/lib/apt/lists/* /var/cache/apt/archives/*
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group:: {[-]} Clearing Journal Logs"
|
||||
sudo journalctl --rotate && sudo journalctl --vacuum-time=1s
|
||||
sudo find /var/log -type f -regex ".*\.gz$" -delete
|
||||
sudo find /var/log -type f -regex ".*\.[0-9]$" -delete
|
||||
sudo find /var/log/ -type f -exec sudo cp /dev/null {} \;
|
||||
echo "::group::Clearing Unwanted Environment Variables"
|
||||
{
|
||||
sudo sed -i -e '/^PATH=/d;/hostedtoolcache/d;/^AZURE/d;/^SWIFT/d;/^DOTNET/d;/DRIVER/d;/^CHROME/d;/HASKELL/d;/^JAVA/d;/^SELENIUM/d;/^GRAALVM/d;/^ANT/d;/^GRADLE/d;/^LEIN/d;/^CONDA/d;/^VCPKG/d;/^ANDROID/d;/^PIPX/d;/^HOMEBREW/d;' /etc/environment
|
||||
sudo sed -i '1i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' /etc/environment
|
||||
sed -i '/HOME\/\.local\/bin/d' /home/runner/.bashrc
|
||||
source /home/runner/.bashrc
|
||||
} &>/dev/null
|
||||
echo "::endgroup::"
|
||||
|
||||
echo "::group::<{[>]}> Free Disk Space After Cleanup <{[<]}>"
|
||||
df --sync -BM --output=pcent,used,avail /
|
||||
echo "::group::Disk Space After Cleanup"
|
||||
df -hlT /
|
||||
echo "::endgroup::"
|
||||
|
||||
printf "\nIf this action really helped you,\n Go to https://github.com/marketplace/actions/github-actions-cleaner\n And show your love by giving a star.\n\n"
|
||||
|
||||
exit
|
||||
|
|
Loading…
Reference in a new issue