2024-12-27 23:11:17 -03:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
### AUTO-UPDATER ###
|
|
|
|
# Variables
|
2024-12-27 23:32:53 -03:00
|
|
|
SERVER_FILE="https://git.ivanch.me/ivanch/server-scripts/raw/branch/main/clean.sh"
|
2024-12-27 23:11:17 -03:00
|
|
|
SERVER_OK=1
|
|
|
|
|
|
|
|
# Check if the server file exists
|
|
|
|
curl -s --head $SERVER_FILE | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error: $SERVER_FILE not found." >&2
|
|
|
|
SERVER_OK=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $SERVER_OK -eq 1 ]; then
|
|
|
|
echo "Running auto-update..."
|
|
|
|
|
|
|
|
# Compare the local and server files sha256sum to check if an update is needed
|
|
|
|
LOCAL_SHA256=$(sha256sum clean.sh | awk '{print $1}')
|
|
|
|
SERVER_SHA256=$(curl -s $SERVER_FILE | sha256sum | awk '{print $1}')
|
|
|
|
|
|
|
|
if [ "$LOCAL_SHA256" != "$SERVER_SHA256" ]; then
|
|
|
|
echo "Updating clean.sh..."
|
|
|
|
curl -s -o clean.sh $SERVER_FILE
|
|
|
|
echo "clean.sh updated."
|
|
|
|
|
|
|
|
chmod +x clean.sh
|
|
|
|
echo "Permissions set up."
|
|
|
|
|
|
|
|
echo "Running updated clean.sh..."
|
|
|
|
./clean.sh
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
echo "clean.sh is up to date.."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
|
|
|
|
# Run Docker system prune
|
|
|
|
echo "Running Docker system prune..."
|
|
|
|
docker image prune -af
|
|
|
|
docker system prune -af
|
|
|
|
|
|
|
|
# Clean APK cache from Alpine or apt for Debian
|
|
|
|
if [ -x "$(command -v apk)" ]; then
|
|
|
|
echo "Cleaning APK cache..."
|
|
|
|
rm -rf /var/cache/apk/*
|
|
|
|
apk cache clean
|
|
|
|
apk update
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -x "$(command -v apt)" ]; then
|
|
|
|
echo "Cleaning apt cache..."
|
|
|
|
apt-get clean
|
|
|
|
apt-get autoclean
|
|
|
|
apt-get update
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Clean system caches
|
|
|
|
echo "Cleaning system caches..."
|
|
|
|
rm -rf /var/cache/*
|
|
|
|
rm -rf /tmp/*
|
|
|
|
|
|
|
|
# General system maintenance
|
|
|
|
echo "Performing general system maintenance..."
|
|
|
|
sync; echo 3 > /proc/sys/vm/drop_caches
|
|
|
|
|
|
|
|
# Remove old logs
|
|
|
|
echo "Removing old logs..."
|
|
|
|
find /var/log -type f -name "*.log" -mtime +30 -delete
|
|
|
|
|
|
|
|
echo "Maintenance completed."
|