blob: 78d69d968d572ed2b8f9f4a882e0b41fb456e0ca [file] [log] [blame]
david_williams5dc46da2008-01-13 06:39:38 +00001#!/bin/bash
david_williamsac075f82008-01-13 04:05:08 +00002
david_williams5dc46da2008-01-13 06:39:38 +00003# echo "arg: $1";
4
5if [ -z $1 ]
6 then
david_williamsac075f82008-01-13 04:05:08 +00007 echo " This script requires an argument. " ;
8 exit 1;
9 fi
10
david_williams5dc46da2008-01-13 06:39:38 +000011foundDirectory=$1
12# should already be in foundDirectory, if execDir used
david_williamsac075f82008-01-13 04:05:08 +000013cd $foundDirectory
david_williams312a06a2008-01-16 01:59:25 +000014# move up one so we can examine syblings
david_williamsac075f82008-01-13 04:05:08 +000015cd ..
david_williams5dc46da2008-01-13 06:39:38 +000016currentDirectory=`pwd`
17echo $currentDirectory
18ndirs=`ls -lA | wc -l`
david_williams312a06a2008-01-16 01:59:25 +000019ndirs=$(($ndirs - 1)); # don't count the "totals" line
david_williams5dc46da2008-01-13 06:39:38 +000020# echo "NDirs: $ndirs"
david_williamsac075f82008-01-13 04:05:08 +000021
david_williams5dc46da2008-01-13 06:39:38 +000022# if only one left, do not remove it, no matter how old
david_williams8a121722008-07-16 04:42:54 +000023if [ $ndirs -eq 1 ]
david_williams5dc46da2008-01-13 06:39:38 +000024then
25 exit 0;
26fi
david_williams8a121722008-07-16 04:42:54 +000027# This is unexpected, since otherwise this method should not have been called.
28# So, this check is just a safety check.
29if [ $ndirs -lt 1 ]
30then
31 exit 101;
32fi
33
david_williams5dc46da2008-01-13 06:39:38 +000034# ok, it is old, and not the only one left
david_williams8a121722008-07-16 04:42:54 +000035# adding a few "should never happen" errror checks
36if [ -d $foundDirectory ]
37then
david_williamsede27aa2008-07-16 06:20:59 +000038 basedirname=$(basename $foundDirectory)
39 if [[ "$basedirname" =~ "[[:digit:]]{14}" ]]
40 then
41 echo "removing $basedirname"
42 rm -fr $foundDirectory
43 else
david_williams9442c232008-09-03 00:54:35 +000044 # patches is expected, warn of others
45 if [ "patches" != $foundDirectory ]
46 then
47 echo "ERROR: The foundDirectory, $foundDirectory, didn't match timestamp pattern"
48 fi
david_williamsede27aa2008-07-16 06:20:59 +000049 fi
david_williams8a121722008-07-16 04:42:54 +000050else
51 echo "ERROR: the foundDirectory, $foundDirectory, is not a directory"
52fi