42 lines
1.3 KiB
Django/Jinja
42 lines
1.3 KiB
Django/Jinja
#!/bin/sh
|
|
#
|
|
# Emit a list empty files in the Nextcloud data folder which
|
|
# weren't empty the last run of this script.
|
|
|
|
set -eu
|
|
|
|
NEXTCLOUD_ROOT={{ nextcloud_root }}
|
|
STORAGE_DIR=/run/$(basename "$0")
|
|
|
|
get_nextcloud_instances() {
|
|
find "$NEXTCLOUD_ROOT" \
|
|
-maxdepth 2 \
|
|
-mindepth 2 \
|
|
-type d \
|
|
-name ocs-provider \
|
|
-print0 \
|
|
| xargs --null --max-args 1 dirname
|
|
}
|
|
|
|
|
|
emit_new_zero_byte_files() {
|
|
local old_non_empty="$1"
|
|
local new_empty="$2"
|
|
if [ -e "$old_non_empty" ]; then
|
|
cat "$old_non_empty" "$new_empty" | sort | uniq --repeated
|
|
fi
|
|
}
|
|
|
|
|
|
mkdir -p "$STORAGE_DIR"
|
|
|
|
get_nextcloud_instances | while read -r nc_path; do
|
|
nc_name=$(basename "$nc_path")
|
|
find "$nc_path"/data -type f -empty | grep -v /updater- >"$STORAGE_DIR/${nc_name}-new-empty.list"
|
|
find "$nc_path"/data -type f -not -empty | grep -v /updater- >"$STORAGE_DIR/${nc_name}-new-non-empty.list"
|
|
emit_new_zero_byte_files \
|
|
"$STORAGE_DIR/${nc_name}-old-non-empty.list" \
|
|
"$STORAGE_DIR/${nc_name}-new-empty.list"
|
|
mv "$STORAGE_DIR/${nc_name}-new-empty.list" "$STORAGE_DIR/${nc_name}-old-empty.list"
|
|
mv "$STORAGE_DIR/${nc_name}-new-non-empty.list" "$STORAGE_DIR/${nc_name}-old-non-empty.list"
|
|
done
|