Update clean.sh
This commit is contained in:
parent
b3baf883a0
commit
dde33d6d78
@ -5,6 +5,8 @@
|
|||||||
# License: MIT
|
# License: MIT
|
||||||
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
# https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
function header_info() {
|
function header_info() {
|
||||||
clear
|
clear
|
||||||
cat <<"EOF"
|
cat <<"EOF"
|
||||||
@ -16,32 +18,55 @@ function header_info() {
|
|||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
BL=$(echo "\033[36m")
|
|
||||||
GN=$(echo "\033[1;92m")
|
BL="\033[36m"
|
||||||
CL=$(echo "\033[m")
|
GN="\033[1;92m"
|
||||||
|
CL="\033[m"
|
||||||
name=$(hostname)
|
name=$(hostname)
|
||||||
|
|
||||||
header_info
|
header_info
|
||||||
echo -e "${BL}[Info]${GN} Cleaning $name${CL} \n"
|
echo -e "${BL}[Info]${GN} Cleaning $name${CL} \n"
|
||||||
cache=$(find /var/cache/ -type f)
|
|
||||||
if [[ -z "$cache" ]]; then
|
# OS-Detection
|
||||||
echo -e "It appears there are no cached files on your system. \n"
|
if [ -f /etc/alpine-release ]; then
|
||||||
sleep 2
|
OS="alpine"
|
||||||
|
elif [ -f /etc/debian_version ] || grep -qi ubuntu /etc/issue 2>/dev/null; then
|
||||||
|
OS="debian"
|
||||||
else
|
else
|
||||||
find /var/cache -type f -delete
|
OS="unknown"
|
||||||
echo "Successfully Removed Cache"
|
|
||||||
sleep 2
|
|
||||||
fi
|
fi
|
||||||
header_info
|
|
||||||
echo -e "${BL}[Info]${GN} Cleaning $name${CL} \n"
|
# Universal Cleaning
|
||||||
logs=$(find /var/log/ -type f)
|
function clean_universal() {
|
||||||
if [[ -z "$logs" ]]; then
|
# Caches
|
||||||
echo -e "It appears there are no logs on your system. \n"
|
find /var/cache/ -type f -delete 2>/dev/null || true
|
||||||
sleep 2
|
# Logs
|
||||||
else
|
find /var/log/ -type f -delete 2>/dev/null || true
|
||||||
find /var/log -type f -delete
|
# Tmp
|
||||||
echo "Successfully Removed Logs"
|
find /tmp/ -mindepth 1 -delete 2>/dev/null || true
|
||||||
sleep 2
|
find /var/tmp/ -mindepth 1 -delete 2>/dev/null || true
|
||||||
|
# User Trash (Desktop-Umgebungen)
|
||||||
|
for u in /home/* /root; do
|
||||||
|
find "$u/.local/share/Trash/" -type f -delete 2>/dev/null || true
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
clean_universal
|
||||||
|
|
||||||
|
if [ "$OS" = "alpine" ]; then
|
||||||
|
echo -e "${BL}[Info]${GN} Alpine detected: Cleaning apk cache...${CL}"
|
||||||
|
rm -rf /var/cache/apk/* 2>/dev/null || true
|
||||||
|
apk cache clean 2>/dev/null || true
|
||||||
|
rm -rf /etc/apk/cache/* 2>/dev/null || true
|
||||||
|
|
||||||
|
elif [ "$OS" = "debian" ]; then
|
||||||
|
echo -e "${BL}[Info]${GN} Debian/Ubuntu detected: Cleaning apt and journal...${CL}"
|
||||||
|
apt-get -y autoremove --purge >/dev/null 2>&1 || true
|
||||||
|
apt-get -y autoclean >/dev/null 2>&1 || true
|
||||||
|
apt-get -y clean >/dev/null 2>&1 || true
|
||||||
|
journalctl --vacuum-time=2d --rotate >/dev/null 2>&1 || true
|
||||||
|
rm -rf /var/lib/apt/lists/* 2>/dev/null || true
|
||||||
|
apt-get update >/dev/null 2>&1 || true
|
||||||
fi
|
fi
|
||||||
header_info
|
|
||||||
echo -e "${BL}[Info]${GN} Cleaning $name${CL} \n"
|
echo -e "${GN}Cleanup completed for $name ($OS)${CL}\n"
|
||||||
echo -e "${GN}Populating apt lists${CL} \n"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user