#!/bin/sh -x
#
#
# motion-clean. This script cleans out old images and
# videos created by motion on a weekly basis.
#
# Copyright (c) 2006 Olav Reinert
#


#
# paranoia settings
#
umask 022

PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

if [ -f /etc/sysconfig/motion ] ; then
    . /etc/sysconfig/motion
fi

#
# Delete too old images and videos
#
if test "$DELETE_OLD_MOTION" = yes ; then
    if test -z "$MOTION_IMAGES_MTIME" ; then
        # Default value (in days)
        MOTION_IMAGES_MTIME=180
    fi
    if test -z "$MOTION_MOVIES_MTIME" ; then
        # Default value (in days)
        MOTION_MOVIES_MTIME=360
    fi

    if test -e motion_spooldir/images ; then
        find motion_spooldir/images -type f -mtime +$MOTION_IMAGES_MTIME -delete
	find motion_spooldir/images -empty -delete
    fi
    if test -e motion_spooldir/movies ; then
        find motion_spooldir/movies -type f -mtime +$MOTION_MOVIES_MTIME -delete
	find motion_spooldir/movies -empty -delete
    fi
 
fi

exit 0

