2023-04-16 13:24:41 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# @param $1 mimimum free disc space
|
|
|
|
# @param $2 --force to for execution indepentend on how much disc space is free
|
|
|
|
|
2023-11-17 12:35:39 +01:00
|
|
|
minimum_percent_cleanup_disc_space="$1"
|
2023-04-16 13:24:41 +02:00
|
|
|
force_freeing=false
|
|
|
|
echo "Checking free disc space..."
|
|
|
|
df
|
|
|
|
if [ $# -gt 0 ] && [ "$2" == "--force" ]; then
|
|
|
|
echo "Forcing disc space freeing."
|
|
|
|
force_freeing=true
|
|
|
|
fi
|
|
|
|
for disc_use_percent in $(df --output=pcent | sed 1d)
|
|
|
|
do
|
|
|
|
disc_use_percent_number=$(echo "$disc_use_percent" | sed "s/%//")
|
2023-11-17 12:35:39 +01:00
|
|
|
if [ "$disc_use_percent_number" -gt "$minimum_percent_cleanup_disc_space" ]; then
|
2023-04-16 13:24:41 +02:00
|
|
|
echo "WARNING: $disc_use_percent_number exceeds the limit of {{size_percent_disc_space_warning}}%."
|
2024-01-14 12:19:00 +01:00
|
|
|
force_freeing=true
|
2023-04-16 13:24:41 +02:00
|
|
|
fi
|
|
|
|
done
|
2024-01-14 12:19:00 +01:00
|
|
|
if [ "$force_freeing" = true ]; then
|
2023-04-16 13:24:41 +02:00
|
|
|
echo "cleaning up /tmp" &&
|
|
|
|
find /tmp -type f -atime +10 -delete || exit 1
|
|
|
|
|
|
|
|
{% if backups_folder_path is defined and size_percent_maximum_backup is defined %}
|
|
|
|
echo "cleaning up backups" &&
|
2023-11-16 19:43:54 +01:00
|
|
|
python {{path_administrator_scripts}}cleanup-backups/cleanup-backups.py --backups-folder-path {{backups_folder_path}} --maximum-backup-size-percent {{size_percent_maximum_backup}} || exit 2
|
2023-04-16 13:24:41 +02:00
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
if pacman -Qs $package > /dev/null ; then
|
|
|
|
echo "cleaning up docker" &&
|
|
|
|
docker system prune -f || exit 3
|
|
|
|
|
2024-01-14 12:19:00 +01:00
|
|
|
nextcloud_application_container="nextcloud-application"
|
2023-04-16 13:24:41 +02:00
|
|
|
if [ "$(docker ps -a -q -f name=$nextcloud_application_container)" ] ; then
|
2023-04-16 14:06:37 +02:00
|
|
|
echo "cleaning up docker nextcloud" &&
|
2023-04-16 13:24:41 +02:00
|
|
|
docker exec -it -u www-data $nextcloud_application_container /var/www/html/occ files:cleanup || exit 4
|
|
|
|
docker exec -it -u www-data $nextcloud_application_container /var/www/html/occ trashbin:cleanup --all-users || exit 5
|
|
|
|
docker exec -it -u www-data $nextcloud_application_container /var/www/html/occ versions:cleanup || exit 6
|
|
|
|
fi
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "cleaning pacman cache" &&
|
|
|
|
yes | pacman -Sc || exit 7
|
|
|
|
|
|
|
|
echo "cleanup finished."
|
2023-04-16 14:06:37 +02:00
|
|
|
else
|
2023-04-16 13:24:41 +02:00
|
|
|
echo "Sufficiend disc space available."
|
|
|
|
echo "To force the freeing of disc space pass the parameter --force."
|
|
|
|
fi
|
|
|
|
exit 0
|