blob: cd0ee53bd77c5ba5a8a7ac5f530847164c6904bc [file] [log] [blame]
david_williams51256372010-04-20 21:04:25 +00001#!/usr/bin/env bash
david_williamse5298172007-12-20 03:30:54 +00002
3
david_williams53f9de12008-01-02 19:31:06 +00004# remember to leave no slashes on filename in source command,
david_williamse5298172007-12-20 03:30:54 +00005# (the commonVariations.shsource file, that is)
6# so that users path is used to find it (first)
david_williams5dc46da2008-01-13 06:39:38 +00007if [ -z $BUILD_INITIALIZED ]
david_williamse5298172007-12-20 03:30:54 +00008then
david_williams53f9de12008-01-02 19:31:06 +00009 source commonVariations.shsource
david_williams133dcf32008-03-06 22:50:05 +000010 source ${RELENG_CONTROL}/commonComputedVariables.shsource
david_williamse5298172007-12-20 03:30:54 +000011fi
12
david_williams7fdc0932011-02-12 06:03:48 +000013# utility functions to remove directories over n days old
david_williams1c00bdc2011-02-12 07:21:43 +000014
david_williams3ffc5f62011-02-14 05:09:19 +000015# We used to use atime (access time) so even if something was created/modified long ago,
david_williams7fdc0932011-02-12 06:03:48 +000016# if we read it often, such as for a "prereq", then we will know it is still in use.
david_williams1c00bdc2011-02-12 07:21:43 +000017# Complication: I've learned that "access time" is modified even by things like ls or find, so
18# may not be that accurate if "still in use". We may want to change to "modified time" and
19# at same time change out
20# build scripts to 'touch' prereq and basebuilder files each time they are used.
21
david_williams7fdc0932011-02-12 06:03:48 +000022# Remember: for most funtions using times, 'n' time is essentially compared/converted to hours,
david_williams3ffc5f62011-02-14 05:09:19 +000023# where hours = 24 + (n * 24), so basically ctime +0 means "at least 1 day old")
david_williamse5298172007-12-20 03:30:54 +000024
david_williams7fdc0932011-02-12 06:03:48 +000025# = = = = = = = = = = = = = = = = = = = = =
david_williamscd761062011-02-11 22:02:03 +000026
27
28# requires parent Directiory as first argument
29# if nDays not specified as second argument, then 0 is assumed
30# (which is one day)
31# if "saveAtLeast" is not set, as third argument, then assumed to be 1
32# (that is, at least "saveAtLeast" directories will be saved, no matter how old)
david_williamsbc9bea82011-02-12 05:29:48 +000033function removeOldArtifactsDirectories ()
34{
david_williamscd761062011-02-11 22:02:03 +000035
36parentDir=$1;
37ndays=$2;
38saveAtLeast=$3;
39
40if [ -z $parentDir ]
41then
42 echo "ERROR: no parent directory specified in function call";
43 return -1;
44fi
45
46if [ -z ndays ]
47then
48 echo "INFO: ndays not specified, 1 day assumed";
49 ndays=0
50else
51 echo "INFO: ndays set to $ndays";
52fi
53
54if [ -z saveAtLeast ]
55then
56 echo "INFO: saveAtLeast not specified, 1 assumed";
57 saveAtLeast=0
58else
59 echo "INFO: saveAtLeast set to $saveAtLeast";
60fi
david_williamse5298172007-12-20 03:30:54 +000061
david_williamseececc12007-12-20 04:36:02 +000062echo;
david_williams3ffc5f62011-02-14 05:09:19 +000063echo " Removing directories older than " $( ${ndays} + 1 ) " days";
david_williamscd761062011-02-11 22:02:03 +000064echo " (from under ${parentDir})";
65before=`find ${parentDir} -mindepth 2 -maxdepth 2 | wc -l`;
david_williamseececc12007-12-20 04:36:02 +000066echo " number of directories before cleaning: ${before}";
david_williamse5298172007-12-20 03:30:54 +000067
david_williams5dc46da2008-01-13 06:39:38 +000068# empty directories often result from "bad builds". We remove those no matter how old
david_williamsd0bdbd22011-02-12 19:52:11 +000069find ${parentDir} -mindepth 2 -maxdepth 3 -type d -empty -execdir rm -fr '{}' \;
david_williams2a47e172008-01-07 22:27:12 +000070# now remove old ones
david_williams3ffc5f62011-02-14 05:09:19 +000071find ${parentDir} -mindepth 2 -maxdepth 2 -type d -ctime +$ndays -execdir ${RELENG_CONTROL}/removeArtifactDirIf.sh '{}' $saveAtLeast \;
david_williamse5298172007-12-20 03:30:54 +000072
david_williamscd761062011-02-11 22:02:03 +000073after=`find ${parentDir} -mindepth 2 -maxdepth 2 | wc -l`;
david_williamseececc12007-12-20 04:36:02 +000074echo " number of directories after cleaning: ${after}";
david_williamscd761062011-02-11 22:02:03 +000075echo;
76
77}
78
79# requires parent Directiory as first argument
80# if nDays not specified as second argument, then 0 is assumed
81# (which is one day)
david_williamsaae11dc2011-02-12 01:58:43 +000082
david_williams6178a202011-02-11 22:42:37 +000083function removeOldDirectories () {
david_williamscd761062011-02-11 22:02:03 +000084
85parentDir=$1;
86ndays=$2;
david_williamsaae11dc2011-02-12 01:58:43 +000087
david_williamscd761062011-02-11 22:02:03 +000088
89if [ -z $parentDir ]
90then
91 echo "ERROR: no parent directory specified in function call";
92 return -1;
93fi
94
95if [ -z ndays ]
96then
97 echo "INFO: ndays not specified, 1 day assumed";
98 ndays=0
99else
100 echo "INFO: ndays set to $ndays";
101fi
102
david_williamscd761062011-02-11 22:02:03 +0000103
104echo;
david_williams3ffc5f62011-02-14 05:09:19 +0000105echo " Removing directories older than " $( ${ndays} + 1 ) " days";
david_williamscd761062011-02-11 22:02:03 +0000106echo " (from under ${parentDir})";
107before=`find ${parentDir} -mindepth 1 -maxdepth 1 | wc -l`;
108echo " number of directories before cleaning: ${before}";
109
110# empty directories often result from "bad builds". We remove those no matter how old
david_williamsd0bdbd22011-02-12 19:52:11 +0000111find ${parentDir} -mindepth 1 -maxdepth 2 -type d -empty -execdir rm -fr '{}' \;
david_williamscd761062011-02-11 22:02:03 +0000112# now remove old ones
david_williams3ffc5f62011-02-14 05:09:19 +0000113find ${parentDir} -mindepth 1 -maxdepth 1 -type d -ctime +$ndays -execdir ${RELENG_CONTROL}/removeIf.sh '{}' \;
david_williamscd761062011-02-11 22:02:03 +0000114
115after=`find ${parentDir} -mindepth 1 -maxdepth 1 | wc -l`;
116echo " number of directories after cleaning: ${after}";
117echo;
118
119}
120
david_williamsa70b03d2011-02-12 02:49:40 +0000121
122# requires parent Directiory as first argument
123# if nDays not specified as second argument, then 0 is assumed
124# (which is one day)
125# This is a good function to remove old files and directories from tmp
david_williamsbc9bea82011-02-12 05:29:48 +0000126function removeOldDirectoriesAndFiles ()
127{
david_williamsa70b03d2011-02-12 02:49:40 +0000128
129parentDir=$1;
130ndays=$2;
131
132
133if [ -z $parentDir ]
134then
135 echo "ERROR: no parent directory specified in function call";
136 return -1;
137fi
138
139if [ -z ndays ]
140then
david_williams3ffc5f62011-02-14 05:09:19 +0000141 echo "INFO: ndays not specified, 14 days assumed";
david_williamsa70b03d2011-02-12 02:49:40 +0000142 ndays=13
143else
144 echo "INFO: ndays set to $ndays";
145fi
146
147
148echo;
david_williams3ffc5f62011-02-14 05:09:19 +0000149echo " Removing directories and files older than " $( ${ndays} + 1 ) " days";
david_williamsa70b03d2011-02-12 02:49:40 +0000150echo " (from under ${parentDir})";
151before=`find ${parentDir} | wc -l`;
152echo " number of directories and files before cleaning: ${before}";
153
154# remove all old directories and files
david_williams3ffc5f62011-02-14 05:09:19 +0000155find ${parentDir} -ctime +$ndays -execdir rm -fr '{}' \;
david_williamsa70b03d2011-02-12 02:49:40 +0000156
157after=`find ${parentDir} | wc -l`;
158echo " number of directories and files after cleaning: ${after}";
159echo;
160
161}
162
david_williams7fdc0932011-02-12 06:03:48 +0000163# = = = = = = = = = = = = = = = = = = = = =
david_williamsbc9bea82011-02-12 05:29:48 +0000164
david_williams7fdc0932011-02-12 06:03:48 +0000165# artifacts are special, since they have a three-layer directory structure,
166# and we want to be sure to always retain at least one, no matter how old.
david_williamsca2f4c52011-02-12 21:24:18 +0000167echo " ";
david_williams508036c2011-02-11 22:51:24 +0000168echo "INFO: Checking to remove old artifacts."
david_williamscd761062011-02-11 22:02:03 +0000169removeOldArtifactsDirectories ${PROJECT_ARTIFACTS} 3 1;
david_williams508036c2011-02-11 22:51:24 +0000170
david_williamsca2f4c52011-02-12 21:24:18 +0000171echo " ";
david_williams508036c2011-02-11 22:51:24 +0000172echo "INFO: Checking to remove old project working directories."
david_williams3ffc5f62011-02-14 05:09:19 +0000173removeOldDirectories ${PROJECT_PROJECTS} 1;
david_williams508036c2011-02-11 22:51:24 +0000174
david_williamsca2f4c52011-02-12 21:24:18 +0000175echo " ";
david_williams508036c2011-02-11 22:51:24 +0000176echo "INFO: Checking to remove old testing directories."
david_williams3ffc5f62011-02-14 05:09:19 +0000177removeOldDirectories ${PROJECT_TESTS} 1;
178
179echo " ";
180echo "INFO: Checking to remove old project builder directories."
181removeOldDirectories ${PROJECT_BUILDERS} 1;
david_williamse2c12572011-02-12 20:53:03 +0000182
david_williamsca2f4c52011-02-12 21:24:18 +0000183echo " ";
david_williamsa70b03d2011-02-12 02:49:40 +0000184echo "INFO: Checking to remove old tmp directories and files."
david_williams6d0b2972011-02-12 02:51:14 +0000185removeOldDirectoriesAndFiles ${RECOMMENDED_TMP_DIR} 13;
david_williams7fdc0932011-02-12 06:03:48 +0000186
david_williams1c00bdc2011-02-12 07:21:43 +0000187# even once per month is a bit "risky" for prereqs, since some patch builds, for example, may not be ran except
david_williams08472982011-02-12 06:10:41 +0000188# once every blue moon ... hence pre-reqs will need to be re-fetched. And, remember, by that time, the
david_williams1c00bdc2011-02-12 07:21:43 +0000189# pre-req might have moved to a different URL (possibly archives), so our build scripts might have
190# to be changed to point to 'archive' location.
david_williams7fdc0932011-02-12 06:03:48 +0000191# TODO: we have some prereqs that can not be retrieved automatically. So, we should have
192# an "exclude" list, such as oagis_release_8.0_GA-withSP3.zip, DITA-OT1.2.1_bin-ASL.zip, WSDL_1.1_for%20OAGIS_8.0.zip.
193# I don't recall which, but one or more of these have a "license confirmation" screen that prevents
194# autodownload so when if/when we want it, we have to get our selves, and copy into prereqs directory.
195# And one of those, I think oagis_release? has some write protected files that prevents their deletion,
196# once unzipped, so we have tweeked the permissions.
david_williamsca2f4c52011-02-12 21:24:18 +0000197echo " ";
david_williams3ffc5f62011-02-14 05:09:19 +0000198echo "INFO: Checking to remove old pre-req directories and files.";
199removeOldDirectoriesAndFiles ${LOCAL_PREREQS_CACHE} 30;
david_williams08472982011-02-12 06:10:41 +0000200
david_williamsca2f4c52011-02-12 21:24:18 +0000201echo " ";
david_williams3ffc5f62011-02-14 05:09:19 +0000202echo "INFO: Checking to remove old basebuilders.";
203removeOldDirectories ${BASE_BUILDERS} 30;
david_williams08472982011-02-12 06:10:41 +0000204