blob: d77298ab0f6c87747f067ce73571dd5abe666341 [file] [log] [blame]
david_williamsbd17e9e2008-01-20 05:05:16 +00001#!/usr/bin/env bash
2#
3# Script to promote the latest build in the specified committers area
4#
david_williamsbd17e9e2008-01-20 05:05:16 +00005
david_williams03bdf892008-02-02 03:00:11 +00006function usage() {
david_williamsa4356922008-02-02 05:02:15 +00007 printf "\n\tUsage: %s [-v] [-d] [-c] [-p] projectname " $(basename $0) >&2
david_williams03bdf892008-02-02 03:00:11 +00008 printf "\n\t\t%s\n\n" "where <projectname> is wtp-R2.0-M, wtp-R3.0-I, wtp-R3.0-N, etc." >&2
9}
10
david_williams33445492008-02-23 02:30:34 +000011source rsync-retry.sh
12
david_williams8bfa02a2008-01-22 05:34:52 +000013verboseFlag=
14deleteOld=
15doCopy=
16projectname=
david_williamsf1521c12008-05-30 20:20:25 +000017while getopts 'hvdcp:' OPTION
david_williams8bfa02a2008-01-22 05:34:52 +000018do
19 case $OPTION in
david_williamsf1521c12008-05-30 20:20:25 +000020 h) usage
21 exit 1
22 ;;
david_williams8bfa02a2008-01-22 05:34:52 +000023 v) verboseFlag=1
24 ;;
25 d) deleteOld=1
26 ;;
27 c) doCopy=1
28 ;;
29 p) projectname=$OPTARG
30 ;;
david_williams03bdf892008-02-02 03:00:11 +000031 ?) usage
david_williams8bfa02a2008-01-22 05:34:52 +000032 exit 2
33 ;;
34 esac
35done
36
37shift $(($OPTIND - 1))
38
39
40
david_williams03bdf892008-02-02 03:00:11 +000041# check we have at least the project name
david_williams8bfa02a2008-01-22 05:34:52 +000042if [ -z $projectname ]
43then
44 printf "\n\t%s\n" "Error: project name is required." >&2
david_williams03bdf892008-02-02 03:00:11 +000045 usage
david_williams8bfa02a2008-01-22 05:34:52 +000046 exit 1
47fi
david_williamsbd17e9e2008-01-20 05:05:16 +000048
49if [[ "$projectname" =~ "(.*)-(.*)-(.*)" ]]
50then
51 distribution=${BASH_REMATCH[1]}
52 buildBranch=${BASH_REMATCH[2]}
53 buildType=${BASH_REMATCH[3]}
54 printf "\n\t%s\n\n" "Promoting latest build from ${1} ..."
david_williams8bfa02a2008-01-22 05:34:52 +000055 if [ $verboseFlag ]
56 then
57 echo "distribution: $distribution"
58 echo "buildBranch: $buildBranch"
59 echo "buildType: $buildType"
60 fi
david_williamsbd17e9e2008-01-20 05:05:16 +000061else
david_williams03bdf892008-02-02 03:00:11 +000062 printf "\n\t%s\n" "Error: projectname doesn't match <distribution>-<buildbranch>-<buildtype> pattern." >&2
63 usage
david_williamsbd17e9e2008-01-20 05:05:16 +000064 exit 3
65fi
66
67# remember to leave no slashes on filename in source command,
68# (the commonVariations.shsource file, that is)
69# so that users path is used to find it (first)
70if [ -z $BUILD_INITIALIZED ]
71then
david_williams8bfa02a2008-01-22 05:34:52 +000072 source commonVariations.shsource
73 MINIMIZE_SCRIPT_OUTPUT="true"
74 source ${BUILD_HOME}/releng.control/commonComputedVariables.shsource
david_williamsbd17e9e2008-01-20 05:05:16 +000075fi
76
77artifactsDir=${PROJECT_ARTIFACTS}
78promoteProjectDir=${artifactsDir}'/'${projectname}
david_williams8bfa02a2008-01-22 05:34:52 +000079if [ $verboseFlag ]
80then
81 echo "Project directory to promote: ${promoteProjectDir} "
82fi
83
david_williamsbd17e9e2008-01-20 05:05:16 +000084if [ ! \( -d ${promoteProjectDir} \) ]
85then
86 printf "\n\t%s\n" "Error: directory ${promoteProjectDir} does not exist." >&2
david_williams03bdf892008-02-02 03:00:11 +000087 usage
david_williamsbd17e9e2008-01-20 05:05:16 +000088 exit 4
89fi
90
91i=0
92for FN in ${promoteProjectDir}/*
93do
94 dirName=$(basename ${FN})
david_williams8bfa02a2008-01-22 05:34:52 +000095 if [ $verboseFlag ]
96 then
97 echo -n "${i}: "
98 echo ${dirName}
99 fi
100 # todo: could check that the name follows the expected date pattern
david_williamsbd17e9e2008-01-20 05:05:16 +0000101 dirList[${i}]=${dirName}
102 i=$(($i + 1))
103done
104
105nDir=${#dirList[*]}
106
david_williams8bfa02a2008-01-22 05:34:52 +0000107if [ $verboseFlag ]
108then
109 echo "Number of directories: ${nDir}"
110fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000111
112# echo "Least recent: ${dirList[0]}"
113# echo "Most recent: ${dirList[$(($nDir - 1))]}"
114
115mostRecent=${dirList[$(($nDir - 1))]}
116
117mostRecentDir=${promoteProjectDir}/${mostRecent}
118
119
120i=0
121for FN in ${mostRecentDir}/*
122do
123 dropDirName=$(basename ${FN})
david_williams8bfa02a2008-01-22 05:34:52 +0000124 if [ $verboseFlag ]
125 then
126 echo -n "${i}: "
127 echo ${dropDirName}
128 fi
129 # todo: could check that the name follows the expected drop directory pattern
david_williamsbd17e9e2008-01-20 05:05:16 +0000130 dropDirList[${i}]=${dropDirName}
131 i=$(($i + 1))
132done
133
david_williams4cbceb72008-01-22 03:41:40 +0000134ndropDir=${#dropDirList[*]}
david_williamsbd17e9e2008-01-20 05:05:16 +0000135
136# there should be exactly one drop directory
david_williams4cbceb72008-01-22 03:41:40 +0000137if [ $ndropDir != 1 ]
david_williamsbd17e9e2008-01-20 05:05:16 +0000138then
david_williams8bfa02a2008-01-22 05:34:52 +0000139 printf "\n\t%s\n" "Error: there was not exactly one drop direc:tory. There was $ndropDir found instead." >&2
david_williams03bdf892008-02-02 03:00:11 +0000140 usage
david_williamsbd17e9e2008-01-20 05:05:16 +0000141 exit 5
david_williamsbd17e9e2008-01-20 05:05:16 +0000142fi
143
144# knowing there is exactly one, the value of dropDirName is still valid
145
david_williams8bfa02a2008-01-22 05:34:52 +0000146echo "Drop directory: ${dropDirName}"
david_williamsbd17e9e2008-01-20 05:05:16 +0000147
148FROMDIR=${mostRecentDir}/${dropDirName}
149
david_williams34f3f912008-07-08 01:36:22 +0000150if [ "patches" == $distribution ]
151then
152 TODIR=${DOWNLOAD_ROOT}/webtools/patches/drops/${buildBranch}/
153else
154 TODIR=${DOWNLOAD_ROOT}/webtools/downloads/drops/${buildBranch}/
155fi
david_williamsf6963892008-01-20 05:38:13 +0000156
157printf "\t%s\n" "declaring build ${dropDirName} on buildstream ${buildBranch}"
158printf "\t\t%s\n" "into ${TODIR}"
159printf "\t\t%s\n\n" "using the build from ${FROMDIR}"
david_williamsbd17e9e2008-01-20 05:05:16 +0000160
david_williams8bfa02a2008-01-22 05:34:52 +0000161if [ $doCopy ]
david_williams26840072008-01-22 03:32:43 +0000162then
david_williams33445492008-02-23 02:30:34 +0000163 rsync-retry ${FROMDIR} ${TODIR} $verboseFlag
164 exitCode=$?
165 if [ $exitCode -ne 0 ]
166 then
167 exit $exitCode
168 fi
david_williams26840072008-01-22 03:32:43 +0000169
david_williams8bfa02a2008-01-22 05:34:52 +0000170 fromString="webtools/committers"
david_williams9db6fa42008-08-25 17:03:10 +0000171 if [ "patches" == $distribution ]
172 then
173 toString="webtools/patches"
174 else
175 toString="webtools/downloads"
david_williams55ecb6d2008-08-26 03:52:18 +0000176 fi
david_williams8bfa02a2008-01-22 05:34:52 +0000177 replaceCommand="s!${fromString}!${toString}!g"
david_williamsbd17e9e2008-01-20 05:05:16 +0000178
david_williams0be0d972008-02-16 05:38:57 +0000179 # remember TODIR already has a slash
180 ${REMOTE_SSH_COMMAND} perl -w -pi -e ${replaceCommand} ${TODIR}${dropDirName}/*.php
david_williamsbd17e9e2008-01-20 05:05:16 +0000181
david_williams8bfa02a2008-01-22 05:34:52 +0000182else
david_williams03bdf892008-02-02 03:00:11 +0000183 printf "\n\t%s\n\n" "Nothing copied: specify -c to actually do the copy"
david_williams26840072008-01-22 03:32:43 +0000184fi
david_williamsbd17e9e2008-01-20 05:05:16 +0000185
david_williams03bdf892008-02-02 03:00:11 +0000186
187if [ $deleteOld ]
188then
189
190 maxToDelete=$(($nDir - 1))
191 if [ $verboseFlag ]
192 then
193 echo "maxToDelete: $maxToDelete"
194 fi
195 for (( i=0; i < $maxToDelete; i++))
196 do
197 dirbasename=${dirList[$i]}
198 dropDirName=${promoteProjectDir}/${dirbasename}
199 if [ $verboseFlag ]
200 then
201 echo -n "${i}: "
202 echo ${dropDirName}
203 fi
204 rm -fr ${dropDirName}
205 done
206
207fi