From 3f092d4fd2b08bcb86aef3f3a8aae4480bdb6131 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 8 Apr 2024 00:05:17 +0200 Subject: [PATCH 1/2] clean: remove --user option --- bin/clean | 37 +------------------------------------ docs/bin.md | 4 +--- 2 files changed, 2 insertions(+), 39 deletions(-) diff --git a/bin/clean b/bin/clean index 1037d88..822c79f 100755 --- a/bin/clean +++ b/bin/clean @@ -16,7 +16,7 @@ ########## _version() { cat <&2 - exit 1 - fi - - print Clean-up for "${user}..." - - print -n Empty trash bin... - sudo test -d "${homedir}/.local/share/Trash" && sudo find "${homedir}/.local/share/Trash" -mindepth 1 -delete - print Done. - - print -n Flush Chrome cache... - sudo test -d "${homedir}/.config/google-chrome" && sudo find "${homedir}/.config/google-chrome" -mindepth 1 -delete - print Done. - - print -n "Flush gdfuse (Google Drive FS) cache..." - sudo test -d "${homedir}/.gdfuse/${user}/cache" && sudo find "${homedir}/.gdfuse/${user}/cache" -mindepth 1 -delete - print Done. - - print -n Flush Spotify cache... - sudo test -d "${homedir}/snap/spotify/common/.cache" && sudo find "${homedir}/snap/spotify/common/.cache" -mindepth 1 -delete - print Done. - - print Cleanup finished for "${user}." -done - exit 0 diff --git a/docs/bin.md b/docs/bin.md index 1bde272..b82e486 100644 --- a/docs/bin.md +++ b/docs/bin.md @@ -121,7 +121,7 @@ Clean-up temporary and other not needed files to free up disk space: - Remove unused `apt` packages - Remove old snaps - Rotate system journal (keep 2 weeks of logs) -- Delete caches (various system & user caches) +- Flush system caches !!! info @@ -138,8 +138,6 @@ OPTIONS -j, --journal [TIME] Remove journal older than this time specified with the usual "s", "m", "h", etc. suffixes. Defaults to 2 weeks (2w). --u, --user [USER] Clear temp files in user's HOME also. - Can be specified multiple times to clean more user HOME. -q, --quiet Suppress non-error messages -h, --help Display this help -v, --version Print version info From 979f1b25616f254e542c4ca7bf80d8b9d8dee579 Mon Sep 17 00:00:00 2001 From: Sandor Semsey Date: Mon, 8 Apr 2024 00:14:36 +0200 Subject: [PATCH 2/2] clean: remove sudo, require run as root --- bin/clean | 22 ++++++++++++++-------- docs/bin.md | 2 ++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/bin/clean b/bin/clean index 822c79f..4b3162c 100755 --- a/bin/clean +++ b/bin/clean @@ -16,7 +16,7 @@ ########## _version() { cat <&2 + exit 1 +fi + print Clean APT... -sudo apt-get "${quiet[@]}" "${quiet[@]}" autoremove --purge --yes -sudo apt-get "${quiet[@]}" "${quiet[@]}" clean --yes +apt-get "${quiet[@]}" "${quiet[@]}" autoremove --purge --yes +apt-get "${quiet[@]}" "${quiet[@]}" clean --yes print APT cleaned. print Clean snap... for line in $(snap list --all | awk '/disabled/{print $1, $3}'); do IFS=$' \t' read -r snapname revision <<< "${line}" # shellcheck disable=SC2024 - sudo snap remove "${snapname}" --purge --revision="${revision}" > "${redirection}" + snap remove "${snapname}" --purge --revision="${revision}" > "${redirection}" done print Snaps cleaned. print Rotate journal... -sudo journalctl --flush --rotate --vacuum-time="${journal_retention}" "${quiet[@]}" +journalctl --flush --rotate --vacuum-time="${journal_retention}" "${quiet[@]}" print Journal rotated. print -n Flush system caches... -[[ -d /var/cache ]] && sudo find /var/cache -mindepth 1 -delete -[[ -d /var/lib/snapd/cache ]] && sudo find /var/lib/snapd/cache -mindepth 1 -delete +[[ -d /var/cache ]] && find /var/cache -mindepth 1 -delete +[[ -d /var/lib/snapd/cache ]] && find /var/lib/snapd/cache -mindepth 1 -delete print Done. exit 0 diff --git a/docs/bin.md b/docs/bin.md index b82e486..2466b31 100644 --- a/docs/bin.md +++ b/docs/bin.md @@ -128,6 +128,8 @@ Clean-up temporary and other not needed files to free up disk space: This script is completely standalone, no bootstrapping is required! Perfect to run weekly by cron. + Needs root permissions. + **Usage** ```