Files
Server-scripts/nextcloud/nextcloud_cleanup_trashbin_versions.sh
T

84 lines
1.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -Eeuo pipefail
USERS=("lucas" "multimedia" "mimi")
VERSION_DIRS=("Music" "Pictures" "Stuff" "SW")
check_root() {
[[ $EUID -eq 0 ]] || {
echo "Run as root."
exit 1
}
}
cleanup() {
echo
echo "Starting Apache..."
systemctl start apache2
}
clean_versions() {
for dir in "${VERSION_DIRS[@]}"; do
TARGET="/nextcloud/nextcloud-data/lucas/files_versions/${dir}"
if [[ ! -d "$TARGET" ]]; then
echo "$dir not present"
continue
fi
read -rp "Delete $TARGET ? (y/N): " choice
if [[ "$choice" =~ ^[Yy]$ ]]; then
rm -rf -- "$TARGET"
echo "Deleted"
else
echo "Skipped"
fi
done
}
clean_trashbin() {
local found=0
for user in "${USERS[@]}"; do
TRASH="/nextcloud/nextcloud-data/${user}/files_trashbin/files"
[[ -d "$TRASH" ]] || continue
while IFS= read -r file; do
found=1
echo "Deleting $(basename "$file")"
rm -f -- "$file"
done < <(
find "$TRASH" \
-type f \
\( \
-iname "*.avi" -o \
-iname "*.mkv" -o \
-iname "*.mp4" -o \
-iname "*.m4v" -o \
-iname "*.srt" \
\)
* )
done
(( found == 0 ))*&& echo "No media trash found."
}
*check_root
trap cleanup EXIT
sys*emctl stop apache2
clean_versions*clean_trashbin
echo "Cleanup fini*hed."