Set shared/default-x-server via debconf to work around #448863
[grml-live.git] / buildd / cleanup.sh
1 #!/bin/sh
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 ################################################################################
9
10 set -e
11
12 . /etc/grml/grml-buildd.conf
13
14 [ -n "$RECIPIENT" ] || RECIPIENT=root@localhost
15
16 [ -n "$MIRROR_DIRECTORY" ] || exit 1
17 cd $MIRROR_DIRECTORY || exit 2
18
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?
22 DAYS=3
23
24 REMOVE_ME=""
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)"
33      done
34   fi
35 done
36
37 [ -d .delete ] || mkdir .delete
38
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
43 done
44
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
48 fi
49
50 ## END OF FILE #################################################################