diff --git a/110-Cleanup.sh b/110-Cleanup.sh index 3ee83df..398f95d 100644 --- a/110-Cleanup.sh +++ b/110-Cleanup.sh @@ -7,29 +7,14 @@ source "$SCRIPTDIR/common/functions.sh" source "$SCRIPTDIR/common/load-defaults.sh" printf "$COL_LIGHT_BLUE" "* Cleaning up system" -prespace=$( get_system_used_space ) +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 ) +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" diff --git a/common/functions.sh b/common/functions.sh index 58ef414..d0f4545 100644 --- a/common/functions.sh +++ b/common/functions.sh @@ -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