This repository has been archived on 2023-08-27. You can view files and clone it, but cannot push or open issues or pull requests.
tcpaste/contrib/scripts/expire
Thorsten Schubert f46a292d49
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Drone CI
2021-10-22 20:21:57 +02:00

41 lines
864 B
Bash
Executable file

#!/usr/bin/bash
#
# Remove expired pastes.
shopt -s lastpipe
shopt -s nullglob
DEBUG=${DEBUG:-0}
NOW=${EPOCHSECONDS}
TARGET=$1
declare -i TOTAL=0
trap '(( DEBUG > 0 )) && echo $TOTAL;' EXIT
# delete empty files
find "${TARGET}/" -mindepth 1 -maxdepth 1 -type f -empty -delete
# test for xattr support
touch "${TARGET}/__xattr__"
if ! setfattr -n user.sp.sunset -v 1234 "${TARGET}/__xattr__"; then
echo 'No xattr support.' >&2
rm -f -- "${TARGET}/__xattr__";
exit 2
fi
# substract __xattr__
(( --TOTAL ))
# fairly inefficient but sufficient for now
for file in "${TARGET}/"*; do
if epoch="$(getfattr -n user.sp.sunset --only-values "${file}" 2>/dev/null | tr -d '\0')"; then
if date -d "@${epoch}" &>/dev/null; then
if (( epoch < NOW )); then
rm -f -- "${file}" 1>&2
(( ++TOTAL ))
fi
fi
fi
done
# vi:set ft=bash ts=4 sw=4 noet noai: