blob: 85a328d4076b7deaf9e98d913362af59829b95cd [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
}
source rsync-retry.sh
verboseFlag=
deleteOld=
doCopy=
projectname=
while getopts 'hvdcp:' OPTION
do
case $OPTION in
h) usage
exit 1
;;
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}
if [ "patches" == $distribution ]
then
TODIR=${DOWNLOAD_ROOT}/webtools/patches/drops/${buildBranch}/
else
TODIR=${DOWNLOAD_ROOT}/webtools/downloads/drops/${buildBranch}/
fi
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
rsync-retry ${FROMDIR} ${TODIR} $verboseFlag
exitCode=$?
if [ $exitCode -ne 0 ]
then
exit $exitCode
fi
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