0a1e6200b63d245f53e440cbf592066dd1ccf2bc
[grml-live.git] / buildd / cleanup.sh
1 #!/bin/sh
2 # Filename:      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: Don Okt 18 00:32:36 CEST 2007 [mika]
8 ################################################################################
9
10 set -e
11
12 # we want to always keep a few images, no matter how old they are
13 # but get rid of the oldest ones first of course :)
14 # so: how many images do we want to keep?
15 DAYS=3
16
17 REMOVE_ME=""
18 for flavour in grml-medium_etch grml-medium_sid grml64-medium_etch grml64-medium_sid grml64_sid grml_sid ; do
19   FILE_COUNT=$(ls -1 $flavour*.iso | wc -l)
20   if [ "$FILE_COUNT" -gt "$DAYS" ] ; then
21      FILES=$(ls -1 $flavour*.iso | tail -"$DAYS")
22      OLD_FILES=$(ls $flavour*.iso | grep -v "$FILES")
23      for file in $OLD_FILES ; do
24          REMOVE_ME="$REMOVE_ME $(find $file -mtime +$DAYS)"
25      done
26   fi
27 done
28
29 [ -d .delete ] || mkdir .delete
30
31 # move them before we really delete them:
32 for file in $REMOVE_ME ; do
33     test -f ${file}     && mv $file .delete
34     test -f ${file}.md5 && mv ${file}.md5 .delete
35 done
36
37 # inform on successful removal:
38 if [ "$(echo "$REMOVE_ME" | tr -d ' ' )" != "" ] ; then
39    echo "deleted files $REMOVE_ME" | mail -s "daily-builds cleanup script" root@localhost
40 fi
41
42 ## END OF FILE #################################################################