| #!/usr/bin/env bash |
| # |
| # Script to promote the latest build in the specified committers area |
| # |
| # check we have the expected one argument |
| if [ $# -lt 1 ] |
| then |
| printf "\n\t%s\n" "Error: one argument required." >&2 |
| printf "\n\t%s\n\n" "usage: $(basename $0) <projectname>, where <projectname> is like wtp-R2.0-M, etc." >&2 |
| exit 1 |
| elif [ $# -gt 1 ] |
| then |
| printf "\n\t%s\n" "Error: only one argument allowed." >&2 |
| printf "\n\t%s\n\n" "usage: $(basename $0) <projectname>, where <projectname> is like wtp-R2.0-M, etc." >&2 |
| exit 2 |
| fi |
| |
| projectname="${1}" |
| |
| 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} ..." |
| echo "distribution: $distribution" |
| echo "buildBranch: $buildBranch" |
| echo "buildType: $buildType" |
| else |
| printf "\n\t%s\n" "Error: argument doesn't match <distribution>-<buildbranch>-<buildtype> pattern." >&2 |
| printf "\n\t%s\n\n" "usage: $(basename $0) <projectname>, where <projectname> is like wtp-R2.0-M, etc." >&2 |
| 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 |
| source ${BUILD_HOME}/releng.control/commonComputedVariables.shsource |
| fi |
| |
| artifactsDir=${PROJECT_ARTIFACTS} |
| promoteProjectDir=${artifactsDir}'/'${projectname} |
| echo "Project directory to promote: ${promoteProjectDir} " |
| if [ ! \( -d ${promoteProjectDir} \) ] |
| then |
| printf "\n\t%s\n" "Error: directory ${promoteProjectDir} does not exist." >&2 |
| printf "\n\t%s\n\n" "usage: $(basename $0) <projectname>, where <projectname> is like wtp-R2.0-M, etc." >&2 |
| exit 4 |
| fi |
| |
| i=0 |
| for FN in ${promoteProjectDir}/* |
| do |
| dirName=$(basename ${FN}) |
| # echo -n "${i}: " |
| # echo ${dirName} |
| # todo: could check that the name follows the expected date pattern |
| dirList[${i}]=${dirName} |
| i=$(($i + 1)) |
| done |
| |
| nDir=${#dirList[*]} |
| |
| # echo "Number of directories: ${nDir}" |
| |
| # 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}) |
| # echo -n "${i}: " |
| # echo ${dropDirName} |
| # todo: could check that the name follows the expected drop directory pattern |
| dropDirList[${i}]=${dropDirName} |
| i=$(($i + 1)) |
| done |
| |
| nDir=${#dropDirList[*]} |
| |
| # there should be exactly one drop directory |
| if [ $nDir != 1 ] |
| then |
| printf "\n\t%s\n" "Error: there was not exactly one drop directory. There was $nDir found instead." >&2 |
| printf "\n\t%s\n\n" "usage: $(basename $0) <projectname>, where <projectname> is like wtp-R2.0-M, etc." >&2 |
| exit 5 |
| echo |
| 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}/ |
| echo |
| echo "declaring build ${dropDirName} on buildstream ${buildBranch}" |
| echo " into ${TODIR}" |
| echo " using the build from ${FROMDIR}" |
| |
| |
| cp -R ${FROMDIR} ${TODIR} |
| |
| fromString="webtools/committers" |
| toString="webtools/downloads" |
| replaceCommand="s!${fromString}!${toString}!g" |
| |
| # TODIR already has a slash |
| 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/ |
| |
| |