69e48bb53e5828e6b50b719d9ef7ba6d2470d80f
[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: Sun Dec 09 18:02:43 CET 2007 [mika]
8 ################################################################################
9
10 set -e
11
12 . /etc/grml/grml-buildd.conf
13
14 [ -n "$MIRROR_DIRECTORY" ] || exit 1
15 cd $MIRROR_DIRECTORY || exit 2
16
17 # we want to always keep a few images, no matter how old they are
18 # but get rid of the oldest ones first of course :)
19 # so: how many images do we want to keep? DAYS=3 usually means 'keep 4 images'
20 DAYS=3
21
22 REMOVE_ME=""
23 for flavour in grml-small_etch grml-small_sid grml-medium_etch grml-medium_sid grml_sid grml_etch \
24                grml64-small_etch grml64-small_sid grml64-medium_etch grml64-medium_sid grml64_sid grml64_etch ; 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     # remove ISOs:
39     test -f ${file}     && rm -f $file
40     # ... but keep their md5sum:
41     test -f ${file}.md5 && mv ${file}.md5 .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 #################################################################