forked from AkkomaGang/akkoma
sliver
559feac56e
Co-authored-by: Oneric <oneric@oneric.stub> Co-authored-by: Floatingghost <hannah@coffee-and-dreams.uk> Co-authored-by: floatingghost <hannah@coffee-and-dreams.uk> Co-authored-by: cevado <cevado@tutanota.com> Co-authored-by: TudbuT <tudbut@tudbut.de> Co-authored-by: Haelwenn (lanodan) Monnier <contact@hacktivis.me> Reviewed-on: #5 Reviewed-on: #6
40 lines
960 B
Bash
Executable file
40 lines
960 B
Bash
Executable file
#!/bin/sh
|
|
|
|
# A simple shell script to delete a media from the Nginx cache.
|
|
|
|
SCRIPTNAME=${0##*/}
|
|
|
|
# NGINX cache directory
|
|
CACHE_DIRECTORY="/var/tmp/akkoma-media-cache"
|
|
|
|
## 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}
|
|
find $2 -maxdepth 2 -type d | xargs -P $max_parallel -n 1 grep -E -Rl "^KEY:.*$1" | sort -u
|
|
}
|
|
|
|
## 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
|
|
|
|
}
|
|
|
|
purge $@
|