diff --git a/releng.control/cleanupArtifacts.sh b/releng.control/cleanupArtifacts.sh index f2318d51334fdb93bea1331e5ef36eeb386c5838..d5b71103464a200e02932491e2d9f2de0fdcbe39 100644 --- a/releng.control/cleanupArtifacts.sh +++ b/releng.control/cleanupArtifacts.sh @@ -186,9 +186,9 @@ removeOldDirectoriesAndFiles ${RECOMMENDED_TMP_DIR} 13; # autodownload so when if/when we want it, we have to get our selves, and copy into prereqs directory. # And one of those, I think oagis_release? has some write protected files that prevents their deletion, # once unzipped, so we have tweeked the permissions. -echo "INFO: Checking to remove old pre-req directories and files not accessed for 1 month." -removeOldDirectoriesAndFiles ${LOCAL_PREREQS_CACHE} 30; +echo "INFO: Checking to remove old pre-req directories and files not accessed for 3 months." +removeOldDirectoriesAndFiles ${LOCAL_PREREQS_CACHE} 90; -echo "INFO: Checking to remove old pre-req directories and files not accessed for 1 month." -removeOldDirectories ${BASE_BUILDERS} 30; +echo "INFO: Checking to remove old basebuilders not accessed for 3 months." +removeOldDirectories ${BASE_BUILDERS} 90; diff --git a/releng.control/removeArtifactDirIf.sh b/releng.control/removeArtifactDirIf.sh new file mode 100644 index 0000000000000000000000000000000000000000..046437f9553b6da257bd7d77ce0fa70c55af83c5 --- /dev/null +++ b/releng.control/removeArtifactDirIf.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +source removeUtils.shsource + +return removeArtifactsDirIf "$*" diff --git a/releng.control/removeIf.sh b/releng.control/removeIf.sh new file mode 100644 index 0000000000000000000000000000000000000000..4d83fc43d1a048e8036e9d48b9bd577df86b2d77 --- /dev/null +++ b/releng.control/removeIf.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +source removeUtils.shsource + +return removeIf "$*" diff --git a/releng.control/removeUtils.shsource b/releng.control/removeUtils.shsource new file mode 100644 index 0000000000000000000000000000000000000000..508718ac6b49a019263fafa3f1882eba32c81f68 --- /dev/null +++ b/releng.control/removeUtils.shsource @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +# simple function that can be called via 'find' that removes and displays name of removed directory +function removeIf () +{ + # echo "arg: $1"; + + if [ -z $1 ] + then + echo "ERROR: No argument. This function requires a directory as an argument. " ; + return 1; + fi + foundDirectory=$1 + + if [ ! -d $foundDirectory ] + then + echo "ERROR: " "${foundDirectory}" ", is not a directory. This function requires a directory as an argument. " + return 2; + fi + + # should already be in foundDirectory, if execDir used (and execDir, in a 'find' is recommended, as more secure) + cd $foundDirectory + + rm -fr $foundDirectory + rc=$? + if [ rc == 0 ] + then + echo " removed: $foundDirectory"; + else + echo "WARNING: rc: " $rc " could not remove " $foundDirectory; + fi + + return rc; +} + +# function that can remove a directory (e.g. via find) but checks to make sure not to remove the last one (or, last 'saveAtLeast') +function removeArtifactsIf () +{ + # echo "arg: $1"; + + if [ -z $1 ] + then + echo "ERROR: No argument. This function requires a directory as an argument. " ; + return 1; + fi + foundDirectory=$1 + nSave=$2 + + if [ -z $nSave ] + then + nSave=1; + fi + + if [ ! -d $foundDirectory ] + then + echo "ERROR: " "${foundDirectory}" ", is not a directory. This function requires a directory as an argument. " + return 2; + fi + + # should already be in foundDirectory, if execDir used (and execDir, in a 'find' is recommended, as more secure) + cd $foundDirectory + + # move up one so we can examine syblings + cd .. + currentDirectory=`pwd` + echo " current working directory: $currentDirectory"; + ndirs=`ls -lA | wc -l` + ndirs=$(($ndirs - 1)); # don't count the "totals" line + # echo "NDirs: $ndirs" + + # if only one left, do not remove it, no matter how old + # or, as improved ... if less than or equal to nSave is left, do not remove + if [ $ndirs -le $nSave ] + then + return 0; + fi + # To have no directories is unexpected, since otherwise this method should not have been called. + # So, this check is just a safety check. + if [ $ndirs -lt 1 ] + then + exit 101; + fi + + rm -fr $foundDirectory + rc=$? + if [ rc == 0 ] + then + echo " removed: $foundDirectory"; + else + echo "WARNING: rc: " $rc ". could not remove " $foundDirectory; + fi + + return rc; + +}