#!/bin/bash
#
# recordum_cleanup
#
# v0.1 2012-09-27 RE
#
# script to remove orphaned temp files
#
# write into /etc/crontab if desired: 00 02 * * * root /usr/local/bin/recordum_cleanup
# or just put it into /etc/cron.daily

# treat unset variables as an error (-u) and exit on any error (-e)
#set -eu

SELF=/usr/local/bin/recordum_cleanup
FIND=/usr/bin/find
RM=/bin/rm

# package may be removed but not purged
[ -x ${SELF} ] || exit 0

# clean out older TMP files
cd /tmp || exit 0
${FIND} . \( -name 'REC*' -o -name 'MLU*' -o -name 'phpa_*' -o -name 'sess_*' \) -a -mmin +480 -exec ${RM} -f {} \;
# clean out download
cd /var/www/public/download/tmpdata || exit 0
${FIND} . -maxdepth 1 ! -name '.*' -a -type f -a -mmin +480 -exec ${RM} -f {} \;
# clean out graph cache
cd /var/www/public/display/Cache || exit 0
${FIND} . -maxdepth 1 ! -name '.*' -a -type f -a -mmin +480 -exec ${RM} -f {} \;
# clean out auto-generated exports
cd /backup/exports/sensors || exit 0
${FIND} . \( ! -name 'exp.sensors.man*' -a -name '*[txt|csv|xml|otf|zip|tgz]' \) -a -mmin +480 -exec ${RM} -f {} \;

exit 0
