Changed the folder deletion #1
117
Clear.sh
117
Clear.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
Version="1.1"
|
Version="1.2"
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
# Reset
|
# Reset
|
||||||
@@ -38,6 +38,8 @@ ResultSizeColor=$Green
|
|||||||
|
|
||||||
FoundText="${FoundColor}Found !${Color_Off}"
|
FoundText="${FoundColor}Found !${Color_Off}"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
# Sudo function
|
# Sudo function
|
||||||
asksudo() {
|
asksudo() {
|
||||||
echo "Checking for sudo permissions..."
|
echo "Checking for sudo permissions..."
|
||||||
@@ -92,26 +94,6 @@ gradleJavaClear() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# The path has a space and I haven't found a way to pass it as an argument
|
|
||||||
discordClear() {
|
|
||||||
DiscordCache="${HOME}/Library/Application Support/discord/Cache"
|
|
||||||
|
|
||||||
echo "${BarColor}====== ${ClearableNameColor}Discord ${BarColor}======${Color_Off}"
|
|
||||||
echo "Checking for ${ClearableNameColor}Discord${Color_Off}'s cache folder..."
|
|
||||||
|
|
||||||
#if [[ -d "$DiscordCache" ]]
|
|
||||||
if [ -n "$(ls -d ${DiscordCache}/* 2>/dev/null)" ];
|
|
||||||
then
|
|
||||||
echo "${FoundText}"
|
|
||||||
|
|
||||||
echo "Clearing ${ClearableNameColor}Discord${Color_Off}'s cache... ${SizeColor}($(du -sh "$DiscordCache" | cut -f1))${Color_Off}"
|
|
||||||
cleared=$(($cleared+$(du -sk "$DiscordCache" | cut -f1)))
|
|
||||||
sudo rm -rv "$DiscordCache"/* | pv -l -s $(du -a "$DiscordCache" | wc -l)> /dev/null
|
|
||||||
else
|
|
||||||
echo "${ClearableNameColor}Discord${Color_Off}'s cache ${NotFoundColor}not found${Color_Off}."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
###################################################
|
###################################################
|
||||||
|
|
||||||
## Clean out older Fusion 360 installations
|
## Clean out older Fusion 360 installations
|
||||||
@@ -175,26 +157,67 @@ clearDocker() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
clearFolder() {
|
|
||||||
# Evals to workaround spaces in arguments
|
clearFolderNew() {
|
||||||
eval folderPath="$2"
|
local folderPath="$2"
|
||||||
eval clearableName="$1"
|
local clearableName="$1"
|
||||||
|
|
||||||
|
echo $folderPath
|
||||||
|
|
||||||
echo "${BarColor}====== ${ClearableNameColor}${clearableName} ${BarColor}======${Color_Off}"
|
echo "${BarColor}====== ${ClearableNameColor}${clearableName} ${BarColor}======${Color_Off}"
|
||||||
echo "Checking for ${ClearableNameColor}${clearableName}${Color_Off}'s cache folder..."
|
echo "Checking for ${ClearableNameColor}${clearableName}${Color_Off}'s cache folder..."
|
||||||
|
|
||||||
if [[ -d "$folderPath" ]]
|
if [ -n "$(find "${folderPath}" -mindepth 1 -maxdepth 1 2>/dev/null)" ];
|
||||||
then
|
then
|
||||||
echo "${FoundText}"
|
echo "${FoundText}"
|
||||||
|
|
||||||
echo "Clearing ${ClearableNameColor}${clearableName}${Color_Off}'s cache... ${SizeColor}($(du -sh ${folderPath} | cut -f1))${Color_Off}"
|
echo "Clearing ${ClearableNameColor}${clearableName}${Color_Off}'s cache... ${SizeColor}($(du -sh "${folderPath}" | cut -f1))${Color_Off}"
|
||||||
echo "${folderPath}"
|
|
||||||
cleared=$(($cleared+$(du -sk ${folderPath} | cut -f1)))
|
addClearedVal cleared "$(du -sk "${folderPath}" | cut -f1)"
|
||||||
sudo rm -rv "${folderPath}" | pv -l -s $(du -a ${folderPath} | wc -l)> /dev/null
|
|
||||||
|
sudo rm -rv "${folderPath}"/* | pv -l -s $(du -a "${folderPath}" | wc -l)> /dev/null
|
||||||
else
|
else
|
||||||
echo "${ClearableNameColor}${clearableName}${Color_Off}'s cache ${NotFoundColor}not found${Color_Off}."
|
echo "${ClearableNameColor}${clearableName}${Color_Off}'s cache ${NotFoundColor}not found${Color_Off}."
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addClearedVal() {
|
||||||
|
local clearedValueToAdd="$2"
|
||||||
|
|
||||||
|
if [[ -z $clearedValueToAdd ]]; then
|
||||||
|
clearedValueToAdd=0;
|
||||||
|
fi
|
||||||
|
if [[ -z $cleared ]]; then
|
||||||
|
cleared=0;
|
||||||
|
fi
|
||||||
|
|
||||||
|
cleared=$(($cleared+$clearedValueToAdd))
|
||||||
|
|
||||||
|
local return_var="$1"
|
||||||
|
eval "$return_var"='$cleared'
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------ #
|
||||||
|
|
||||||
|
# -- Steps -- #
|
||||||
|
|
||||||
|
browserCleanup() {
|
||||||
|
clearFolderNew "Firefox" "${HOME}/Library/Caches/Firefox"
|
||||||
|
}
|
||||||
|
|
||||||
|
developmentCleanup() {
|
||||||
|
# Don't delete the folder
|
||||||
|
clearFolderNew "CoreSimulator" "${HOME}/Library/Developer/CoreSimulator/Caches"
|
||||||
|
|
||||||
|
gradleJavaClear
|
||||||
|
|
||||||
|
clearFolderNew "JetBrains" "${HOME}/Library/Caches/JetBrains"
|
||||||
|
|
||||||
|
clearFolderNew "VisualStudioInstaller" "${HOME}/Library/Caches/VisualStudioInstaller"
|
||||||
|
|
||||||
|
clearFolderNew "VisualStudio" "${HOME}/Library/Caches/VisualStudio"
|
||||||
|
}
|
||||||
|
|
||||||
# ------------------------ #
|
# ------------------------ #
|
||||||
|
|
||||||
# -- Main Script -- #
|
# -- Main Script -- #
|
||||||
@@ -204,47 +227,27 @@ echo " Script ${ProgNameColor}Clear.sh${Color_Off} by ${AuthorNameColor}S
|
|||||||
echo " ${VersionColor}v${Version}${Color_Off} "
|
echo " ${VersionColor}v${Version}${Color_Off} "
|
||||||
echo "${BarColor}==========================================${Color_Off}"
|
echo "${BarColor}==========================================${Color_Off}"
|
||||||
|
|
||||||
# Setting size variable to 0
|
|
||||||
cleared=0
|
|
||||||
|
|
||||||
# Elevate permissions...
|
# Elevate permissions...
|
||||||
asksudo
|
asksudo
|
||||||
|
|
||||||
# Clearing...
|
# Clearing...
|
||||||
coreSimClear
|
developmentCleanup
|
||||||
|
|
||||||
gradleJavaClear
|
browserCleanup
|
||||||
|
|
||||||
FirefoxCache="${HOME}/Library/Caches/Firefox"
|
clearFolderNew "Thunderbird" "${HOME}/Library/Caches/Thunderbird"
|
||||||
clearFolder "Firefox" "${FirefoxCache}"
|
|
||||||
|
|
||||||
ThunderbirdCache="${HOME}/Library/Caches/Thunderbird"
|
clearFolderNew "Homebrew" "${HOME}/Library/Caches/Homebrew"
|
||||||
clearFolder "Thunderbird" "${ThunderbirdCache}"
|
|
||||||
|
|
||||||
discordClear
|
# Discord needs to not have its cache folder deleted fully
|
||||||
#DiscordCache=$HOME"/Library/Application Support/discord/Cache"
|
clearFolderNew "Discord" "${HOME}/Library/Application Support/discord/Cache"
|
||||||
#clearKeepFolder "Discord" "$DiscordCache"
|
|
||||||
|
|
||||||
HomebrewCache="${HOME}/Library/Caches/Homebrew"
|
clearFolderNew "Adobe" "${HOME}/Library/Caches/Adobe"
|
||||||
clearFolder "Homebrew" "${HomebrewCache}"
|
|
||||||
|
|
||||||
JetbrainsCache="${HOME}/Library/Caches/JetBrains"
|
|
||||||
clearFolder "JetBrains" "${JetbrainsCache}"
|
|
||||||
|
|
||||||
VisualStudioInstallerCache="${HOME}/Library/Caches/VisualStudioInstaller"
|
|
||||||
clearFolder "VisualStudioInstaller" "${VisualStudioInstallerCache}"
|
|
||||||
|
|
||||||
VisualStudioCache="${HOME}/Library/Caches/VisualStudio"
|
|
||||||
clearFolder "VisualStudio" "${VisualStudioCache}"
|
|
||||||
|
|
||||||
Adobe="${HOME}/Library/Caches/Adobe"
|
|
||||||
clearFolder "Adobe" "${Adobe}"
|
|
||||||
|
|
||||||
deleteOldestInstallFusion360
|
deleteOldestInstallFusion360
|
||||||
|
|
||||||
clearDocker
|
clearDocker
|
||||||
|
|
||||||
|
|
||||||
# Print final
|
# Print final
|
||||||
echo "${BarColor}==========================================${Color_Off}"
|
echo "${BarColor}==========================================${Color_Off}"
|
||||||
echo "Cleared ${ResultSizeColor}$(($cleared/1024))M${Color_Off} !"
|
echo "Cleared ${ResultSizeColor}$(($cleared/1024))M${Color_Off} !"
|
||||||
|
|||||||
Reference in New Issue
Block a user