This commit is contained in:
deathbybandaid 2023-12-17 11:23:44 -05:00
parent f64e0cb9a0
commit 0177c45b28
2 changed files with 33 additions and 23 deletions

View File

@ -8,28 +8,13 @@ source "$SCRIPTDIR/common/load-defaults.sh"
printf "$COL_LIGHT_BLUE" "* Cleaning up system"
prespace= $( get_system_used_space )
prespacewords= $(human_readable_bytes $prespace)
printf "$COL_LIGHT_BLUE" "* Current used space is $prespacewords"
pkgmgr_clean
postspace= $( get_system_used_space )
postspacewords= $(human_readable_bytes $prespace)
printf "$COL_LIGHT_BLUE" "* Current used space is now $postspacewords"
spacesavedbytes=`expr $postspace - $prespace`
spacesavedbytes=${spacesavedbytes#-}
spacesavedkb=`expr $spacesavedbytes / 1024`
spacesavedmb=`expr $spacesavedbytes / 1024 / 1024`
spacesavedgb=`expr $spacesavedbytes / 1024 / 1024 / 1024`
if [[ "$spacesavedgb" -gt 0 ]]
then
spacesavedwords="$spacesavedgb GB"
elif [[ "$spacesavedmb" -gt 0 ]]
then
spacesavedwords="$spacesavedmb MB"
elif [[ "$spacesavedkb" -gt 0 ]]
then
spacesavedwords="$spacesavedkb KB"
elif [[ "$spacesavedbytes" -gt 0 ]]
then
spacesavedwords="$spacesavedbytes Bytes"
else
spacesavedwords="zero space"
fi
printf "$COL_LIGHT_BLUE" "apt cleanup saved $spacesavedwords"
postspacewords= $(human_readable_bytes $spacesavedbytes)
printf "$COL_LIGHT_BLUE" "Cleanup saved $spacesavedwords"

View File

@ -76,11 +76,36 @@ get_system_used_space() {
echo $(df --output=used -B1 / | tail -n 1| cut -d'%' -f1)
}
human_readable_bytes() {
local spacebytes="$1"
spacekb=`expr $spacebytes / 1024`
spacemb=`expr $spacebytes / 1024 / 1024`
spacegb=`expr $spacebytes / 1024 / 1024 / 1024`
if [[ "$spacegb" -gt 0 ]]
then
spacewords="$spacegb GB"
elif [[ "$spacemb" -gt 0 ]]
then
spacewords="$spacemb MB"
elif [[ "$spacekb" -gt 0 ]]
then
spacewords="$spacekb KB"
elif [[ "$spacebytes" -gt 0 ]]
then
spacewords="$spacebytes Bytes"
else
spacewords="zero space"
fi
}
pkgmgr_clean(){
# Get Command language
PKG_MANAGER=$( get_pkg_mgr )
printf "$COL_YELLOW" "Cleaning cache for $PKG_MANAGER"
if [ "$PKG_MANAGER" == "apt-get" ] ; then
"$PKG_MANAGER" clean
"$PKG_MANAGER" autoclean