3 # Purpose: clean up daily builds directory - remove old files
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2 or any later version.
7 ################################################################################
13 if [ -r /etc/grml/grml-buildd.conf ] ; then
14 . /etc/grml/grml-buildd.conf
15 elif [ -r "${dir}/grml-buildd.conf" ] ; then
16 . "${dir}/grml-buildd.conf"
19 # directory where daily ISOs are stored locally
20 if [ -z "$MIRROR_DIRECTORY" ] ; then
21 echo "Error: \$MIRROR_DIRECTORY is not set. Exiting." >&2
25 if [ -z "$FLAVOURS" ] ; then
26 echo "Error: \$FLAVOURS is not set. Exiting." >&2
30 if ! cd "$MIRROR_DIRECTORY" ; then
31 echo "Error: could not change directory to $MIRROR_DIRECTORY" >&2
35 # we want to always keep a few images, no matter how old they are
36 # but get rid of the oldest ones first of course :)
37 # so: how many images do we want to keep? DAYS=3 usually means 'keep 4 images'
41 for flavour in $FLAVOURS; do
42 FILE_COUNT=$(ls -1 $flavour/$flavour*.iso | wc -l)
43 if [ "$FILE_COUNT" -gt "$DAYS" ] ; then
44 FILES=$(ls -1 $flavour/$flavour*.iso | tail -"$DAYS")
45 OLD_FILES=$(ls $flavour/$flavour*.iso | grep -v "$FILES")
46 for file in $OLD_FILES ; do
47 REMOVE_ME="$REMOVE_ME $(find $file -mtime +$DAYS)"
52 [ -d .archive ] || mkdir .archive
54 for file in $REMOVE_ME ; do
55 test -f ${file} && rm -f $file
56 # ... but keep their md5sum / sha1sum:
57 test -f ${file}.md5 && mv ${file}.md5 .archive
58 test -f ${file}.sha1 && mv ${file}.sha1 .archive
61 # inform on successful removal:
62 if [ "$(echo "$REMOVE_ME" | tr -d ' ' )" != "" ] ; then
63 echo "Removed previous files $REMOVE_ME" | logger -t grml-buildd
66 ## END OF FILE #################################################################