summaryrefslogtreecommitdiffabout
path: root/cleaner.in
Side-by-side diff
Diffstat (limited to 'cleaner.in') (more/less context) (ignore whitespace changes)
-rwxr-xr-xcleaner.in85
1 files changed, 50 insertions, 35 deletions
diff --git a/cleaner.in b/cleaner.in
index 035892f..0a9a35f 100755
--- a/cleaner.in
+++ b/cleaner.in
@@ -1,4 +1,19 @@
#! /bin/sh
+# This file is part of BEAM
+# Copyright (C) 2012-2014 Sergey Poznyakoff
+#
+# BEAM is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# BEAM is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with BEAM. If not, see <http://www.gnu.org/licenses/>.
libdir=@LIBDIR@/beam
set -e
@@ -29,27 +44,27 @@ EOF
while [ $# -ne 0 ]
do
- case $1 in
- -s|--suffix) shift; suffix=$1;;
- -r|--retain) shift; retainweeks=$1;;
- -v|--verbose) verbose=echo;;
- -n|--dry-run) dry_run=echo; verbose=echo;;
- -h|--help) help;;
- --wtf) wtf $(basename $0) clean up old files; exit 0;;
- --) shift; break;;
- -*) echo >&2 "$0: unrecognized option $1"
- exit 1;;
- *) break
- esac
- shift
+ case $1 in
+ -s|--suffix) shift; suffix=$1;;
+ -r|--retain) shift; retainweeks=$1;;
+ -v|--verbose) verbose=echo;;
+ -n|--dry-run) dry_run=echo; verbose=echo;;
+ -h|--help) help;;
+ --wtf) wtf $(basename $0) clean up old files; exit 0;;
+ --) shift; break;;
+ -*) echo >&2 "$0: unrecognized option $1"
+ exit 1;;
+ *) break
+ esac
+ shift
done
case $# in
-0) echo >&2 "$0: not enough arguments"
- exit 1;;
-1) dir=$1;;
-*) echo >&2 "$0: too many arguments"
- exit 1;;
+ 0) echo >&2 "$0: not enough arguments"
+ exit 1;;
+ 1) dir=$1;;
+ *) echo >&2 "$0: too many arguments"
+ exit 1;;
esac
thisweek=$(date +%U)
@@ -58,31 +73,31 @@ thisweek=$(date +%U)
# because weeks prior to 10 begin with 0 and therefore are processed
# as octal numbers. This causes grief for weeks 08 and 09.
if [ $thisweek -gt $retainweeks ]; then
- lastweek=$(expr $thisweek - $retainweeks)
+ lastweek=$(expr $thisweek - $retainweeks)
else
- lastweek=$(expr $thisweek + 54 - $retainweeks)
+ lastweek=$(expr $thisweek + 54 - $retainweeks)
fi
$verbose \# removing from $dir files ending in $suffix and older than week $lastweek
if [ -z "$suffix" ]; then
- find $dir -maxdepth 1 -type f -printf '%f\n'
+ find $dir -maxdepth 1 -type f -printf '%f\n'
else
- find $dir -maxdepth 1 -type f -name "*$suffix" -printf '%f\n'
+ find $dir -maxdepth 1 -type f -name "*$suffix" -printf '%f\n'
fi |
while read name
do
- $verbose \# considering $name
- week=$(expr "$name" : '[^-][^-]*-\([0-9][0-9]*\)-.*')
- if [ $thisweek -ge $week ]; then
- if [ $(expr $thisweek - $week) -gt $retainweeks ]; then
- $verbose \# removing $name
- $dry_run rm $dir/$name
- fi
- else
- if [ $(expr $thisweek + 54 - $week) -gt $retainweeks ]; then
- $verbose \# removing $name
- $dry_run rm $dir/$name
- fi
- fi
+ $verbose \# considering $name
+ week=$(expr "$name" : '[^-][^-]*-\([0-9][0-9]*\)-.*')
+ if [ $thisweek -ge $week ]; then
+ if [ $(expr $thisweek - $week) -gt $retainweeks ]; then
+ $verbose \# removing $name
+ $dry_run rm $dir/$name
+ fi
+ else
+ if [ $(expr $thisweek + 54 - $week) -gt $retainweeks ]; then
+ $verbose \# removing $name
+ $dry_run rm $dir/$name
+ fi
+ fi
done

Return to:

Send suggestions and report system problems to the System administrator.