2020-05-19 21:56:04 -06:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# A simple shell script to delete a media from the Nginx cache.
|
|
|
|
|
|
|
|
SCRIPTNAME=${0##*/}
|
|
|
|
|
|
|
|
# NGINX cache directory
|
2022-07-06 12:50:01 -06:00
|
|
|
CACHE_DIRECTORY="/tmp/akkoma-media-cache"
|
2020-05-19 21:56:04 -06:00
|
|
|
|
|
|
|
## Return the files where the items are cached.
|
|
|
|
## $1 - the filename, can be a pattern .
|
|
|
|
## $2 - the cache directory.
|
|
|
|
## $3 - (optional) the number of parallel processes to run for grep.
|
|
|
|
get_cache_files() {
|
|
|
|
local max_parallel=${3-16}
|
2020-06-14 12:02:57 -06:00
|
|
|
find $2 -maxdepth 2 -type d | xargs -P $max_parallel -n 1 grep -E -Rl "^KEY:.*$1" | sort -u
|
2020-05-19 21:56:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
## Removes an item from the given cache zone.
|
|
|
|
## $1 - the filename, can be a pattern .
|
|
|
|
## $2 - the cache directory.
|
|
|
|
purge_item() {
|
|
|
|
for f in $(get_cache_files $1 $2); do
|
|
|
|
echo "found file: $f"
|
|
|
|
[ -f $f ] || continue
|
|
|
|
echo "Deleting $f from $2."
|
|
|
|
rm $f
|
|
|
|
done
|
|
|
|
} # purge_item
|
|
|
|
|
|
|
|
purge() {
|
|
|
|
for url in "$@"
|
|
|
|
do
|
|
|
|
echo "$SCRIPTNAME delete \`$url\` from cache ($CACHE_DIRECTORY)"
|
|
|
|
purge_item $url $CACHE_DIRECTORY
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-14 12:02:57 -06:00
|
|
|
purge $@
|