2 # Filename: /usr/share/grml-live/buildd/cleanup.sh
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 # Latest change: YDATE [mika]
8 ################################################################################
12 . /etc/grml/grml-buildd.conf
14 [ -n "$RECIPIENT" ] || RECIPIENT=root@localhost
16 [ -n "$MIRROR_DIRECTORY" ] || exit 1
17 cd $MIRROR_DIRECTORY || exit 2
19 # we want to always keep a few images, no matter how old they are
20 # but get rid of the oldest ones first of course :)
21 # so: how many images do we want to keep?
25 for flavour in grml-small_etch grml-small_sid grml-medium_etch grml-medium_sid grml_sid grml_etch \
26 grml64-small_etch grml64-small_sid grml64-medium_etch grml64-medium_sid grml64_sid grml64_etch ; do
27 FILE_COUNT=$(ls -1 $flavour*.iso | wc -l)
28 if [ "$FILE_COUNT" -gt "$DAYS" ] ; then
29 FILES=$(ls -1 $flavour*.iso | tail -"$DAYS")
30 OLD_FILES=$(ls $flavour*.iso | grep -v "$FILES")
31 for file in $OLD_FILES ; do
32 REMOVE_ME="$REMOVE_ME $(find $file -mtime +$DAYS)"
37 [ -d .delete ] || mkdir .delete
39 # move them before we really delete them:
40 for file in $REMOVE_ME ; do
41 test -f ${file} && rm -f $file
42 test -f ${file}.md5 && mv ${file}.md5 .delete
45 # inform on successful removal:
46 if [ "$(echo "$REMOVE_ME" | tr -d ' ' )" != "" ] ; then
47 echo "deleted files $REMOVE_ME" | mail -s "daily-builds cleanup script" $RECIPIENT
50 ## END OF FILE #################################################################