blob: dc4fa7f02c81b7ee599d597f817a0970e2890023 [file] [log] [blame]
#!/usr/bin/env bash
#
# Script to promote the latest build in the specified committers area
#
function usage() {
printf "\n\tUsage: %s [-v] [-d] [-c] [-p] projectname " $(basename $0) >&2
printf "\n\t\t%s\n\n" "where <projectname> is wtp-R2.0-M, wtp-R3.0-I, wtp-R3.0-N, etc." >&2
}
verboseFlag=
deleteOld=
doCopy=
projectname=
while getopts 'vdcp:' OPTION
do
case $OPTION in
v) verboseFlag=1
;;
d) deleteOld=1
;;
c) doCopy=1
;;
p) projectname=$OPTARG
;;
?) usage
exit 2
;;
esac
done
shift $(($OPTIND - 1))
# check we have at least the project name
if [ -z $projectname ]
then
printf "\n\t%s\n" "Error: project name is required." >&2
usage
exit 1
fi
if [[ "$projectname" =~ "(.*)-(.*)-(.*)" ]]
then
distribution=${BASH_REMATCH[1]}
buildBranch=${BASH_REMATCH[2]}
buildType=${BASH_REMATCH[3]}
printf "\n\t%s\n\n" "Promoting latest build from ${1} ..."
if [ $verboseFlag ]
then
echo "distribution: $distribution"
echo "buildBranch: $buildBranch"
echo "buildType: $buildType"
fi
else
printf "\n\t%s\n" "Error: projectname doesn't match <distribution>-<buildbranch>-<buildtype> pattern." >&2
usage
exit 3
fi
# remember to leave no slashes on filename in source command,
# (the commonVariations.shsource file, that is)
# so that users path is used to find it (first)
if [ -z $BUILD_INITIALIZED ]
then
source commonVariations.shsource
MINIMIZE_SCRIPT_OUTPUT="true"
source ${BUILD_HOME}/releng.control/commonComputedVariables.shsource
fi
artifactsDir=${PROJECT_ARTIFACTS}
promoteProjectDir=${artifactsDir}'/'${projectname}
if [ $verboseFlag ]
then
echo "Project directory to promote: ${promoteProjectDir} "
fi
if [ ! \( -d ${promoteProjectDir} \) ]
then
printf "\n\t%s\n" "Error: directory ${promoteProjectDir} does not exist." >&2
usage
exit 4
fi
i=0
for FN in ${promoteProjectDir}/*
do
dirName=$(basename ${FN})
if [ $verboseFlag ]
then
echo -n "${i}: "
echo ${dirName}
fi
# todo: could check that the name follows the expected date pattern
dirList[${i}]=${dirName}
i=$(($i + 1))
done
nDir=${#dirList[*]}
if [ $verboseFlag ]
then
echo "Number of directories: ${nDir}"
fi
# echo "Least recent: ${dirList[0]}"
# echo "Most recent: ${dirList[$(($nDir - 1))]}"
mostRecent=${dirList[$(($nDir - 1))]}
mostRecentDir=${promoteProjectDir}/${mostRecent}
i=0
for FN in ${mostRecentDir}/*
do
dropDirName=$(basename ${FN})
if [ $verboseFlag ]
then
echo -n "${i}: "
echo ${dropDirName}
fi
# todo: could check that the name follows the expected drop directory pattern
dropDirList[${i}]=${dropDirName}
i=$(($i + 1))
done
ndropDir=${#dropDirList[*]}
# there should be exactly one drop directory
if [ $ndropDir != 1 ]
then
printf "\n\t%s\n" "Error: there was not exactly one drop direc:tory. There was $ndropDir found instead." >&2
usage
exit 5
fi
# knowing there is exactly one, the value of dropDirName is still valid
echo "Drop directory: ${dropDirName}"
FROMDIR=${mostRecentDir}/${dropDirName}
TODIR=${DOWNLOAD_ROOT}/webtools/downloads/drops/${buildBranch}/
printf "\t%s\n" "declaring build ${dropDirName} on buildstream ${buildBranch}"
printf "\t\t%s\n" "into ${TODIR}"
printf "\t\t%s\n\n" "using the build from ${FROMDIR}"
if [ $doCopy ]
then
rsyncArgs="aru"
if [ $verboseFlag ]
then
rsyncArgs="${rsyncArgs}v"
fi
maxTrys=5
exitCode=-1
nTrys=0
nPauseTime=120s
until [ $exitCode == 0 ]
do
${REMOTE_SSH_COMMAND} rsync -${rsyncArgs} ${FROMDIR} ${TODIR}
exitCode=$?
if [ $exitCode != 0 ]
then
nTrys=$(($nTrys + 1))
if [ $verboseFlag ] ; then
echo "rsync failed with $exitCode. Retrying $nTrys times after $nPauseTime."
if [ $nTrys -gt $maxTrys ] ; then
echo "Number of re-trys exceeded. rsync exit code: $exitCode"
exit $exitCode
fi
sleep $nPauseTime
fi
fi
done
fromString="webtools/committers"
toString="webtools/downloads"
replaceCommand="s!${fromString}!${toString}!g"
# remember TODIR already has a slash
${REMOTE_SSH_COMMAND} perl -w -pi -e ${replaceCommand} ${TODIR}${dropDirName}/*.php
# update the update site
#cp -ruv $HOME/downloads/webtools/committers/drops/$1/updateSite/features/ $HOME/downloads/webtools/milestones/
#cp -ruv $HOME/downloads/webtools/committers/drops/$1/updateSite/plugins/ $HOME/downloads/webtools/milestones/
else
printf "\n\t%s\n\n" "Nothing copied: specify -c to actually do the copy"
fi
if [ $deleteOld ]
then
maxToDelete=$(($nDir - 1))
if [ $verboseFlag ]
then
echo "maxToDelete: $maxToDelete"
fi
for (( i=0; i < $maxToDelete; i++))
do
dirbasename=${dirList[$i]}
dropDirName=${promoteProjectDir}/${dirbasename}
if [ $verboseFlag ]
then
echo -n "${i}: "
echo ${dropDirName}
fi
rm -fr ${dropDirName}
done
fi