buildd: add support for building squeeze based ISOs
[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 ################################################################################
8
9 set -e
10
11 . /etc/grml/grml-buildd.conf
12
13 [ -n "$MIRROR_DIRECTORY" ] || exit 1
14 cd $MIRROR_DIRECTORY || exit 2
15
16 # we want to always keep a few images, no matter how old they are
17 # but get rid of the oldest ones first of course :)
18 # so: how many images do we want to keep? DAYS=3 usually means 'keep 4 images'
19 DAYS=3
20
21 REMOVE_ME=""
22 for flavour in grml-medium_lenny   grml-medium_squeeze   grml-medium_sid   grml-small_lenny   grml-small_squeeze  grml-small_sid \
23                grml64-medium_lenny grml64-medium_squeeze grml64-medium_sid grml64-small_lenny grml64-small_squeeze grml64-small_sid \
24                grml64_lenny grml64_squeeze grml64_sid grml_lenny grml_squeeze grml_sid ; do
25   FILE_COUNT=$(ls -1 $flavour/$flavour*.iso | wc -l)
26   if [ "$FILE_COUNT" -gt "$DAYS" ] ; then
27      FILES=$(ls -1 $flavour/$flavour*.iso | tail -"$DAYS")
28      OLD_FILES=$(ls $flavour/$flavour*.iso | grep -v "$FILES")
29      for file in $OLD_FILES ; do
30          REMOVE_ME="$REMOVE_ME $(find $file -mtime +$DAYS)"
31      done
32   fi
33 done
34
35 [ -d .archive ] || mkdir .archive
36
37 for file in $REMOVE_ME ; do
38     test -f ${file}     && rm -f $file
39     # ... but keep their md5sum / sha1sum:
40     test -f ${file}.md5  && mv ${file}.md5   .archive
41     test -f ${file}.sha1 && mv ${file}.sha1 .archive
42 done
43
44 # inform on successful removal:
45 if [ "$(echo "$REMOVE_ME" | tr -d ' ' )" != "" ] ; then
46    echo "deleted files $REMOVE_ME" | mail -s "daily-builds cleanup script" mika@grml.org
47 fi
48
49 ## END OF FILE #################################################################