blob: 6e50b10c2bcfe5c3d48e40c6462be0296aa13fdc [file] [log] [blame]
#!/usr/bin/env bash
# this localBuildProperties.shsource file is to ease local builds to override some variables.
# It should not be used for production builds.
source localBuildProperties.shsource 2>/dev/null
export BUILD_HOME=${BUILD_HOME:-/shared/eclipse/builds}
# To allow this cron job to work from hudson, or traditional crontab
if [[ -z "${WORKSPACE}" ]]
then
export UTILITIES_HOME=/shared/eclipse
else
export UTILITIES_HOME=${WORKSPACE}/utilities/production
fi
# These variable are not correctly defined centrally,
# and are also defined in various Ant scripts.
# For production, use value for shared instance
HUDSON_PROTOCOL=${HUDSON_PROTOCOL:-"https"}
HUDSON_HOST=${HUDSON_HOST:-"ci.eclipse.org"}
# is standard port for "eclipse", but can not leave blank, since we use ':' in some URLs
HUDSON_PORT=${HUDSON_PORT:-"443"}
HUDSON_ROOT_URI=${HUDSON_ROOT_URI:-"releng"}
# For production, use the special performance machine at eclipse
HUDSON_PERF_HOST=${HUDSON_PERF_HOST:-"ci.eclipse.org"}
HUDSON_PERF_PORT=${HUDSON_PERF_PORT:-"443"}
HUDSON_PERF_PROTOCOL=${HUDSON_PERF_PROTOCOL:-"https"}
LINUX_PERF_SEGMENT=${LINUX_PERF_SEGMENT:-"releng"}
function convertToZeroPaddedMillisecs ()
{
inNumber=$1
printf -v outNumber "%.3f" "${inNumber}"
RC=$?
if [[ $RC != 0 ]]
then
printf "%s" "InvalidInput"
else
printf "%s" "${outNumber}"
fi
}
function dropOnDLServer()
{
eclipseStream=$1
if [[ -z "${eclipseStream}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
return 1;
fi
buildId=$2
if [[ -z "${buildId}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide buildType as second argument, for this function $(basename $0)" >&2
return 1;
fi
pathToDL=$( dlToPath "$eclipseStream" "$buildId")
if [[ "$pathToDL" == 1 ]]
then
printf "\n\n\t%s\n\n" "ERROR: pathToDL could not be computed." >&2
return 1
fi
toDir="/home/data/httpd/download.eclipse.org/${pathToDL}"
echo $toDir
}
function updateSiteOnDL()
{
eclipseStream=$1
if [[ -z "${eclipseStream}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
return 1;
fi
buildId=$2
if [[ -z "${buildId}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide buildType as second argument, for this function $(basename $0)" >&2
return 1;
fi
# contrary to intuition (and previous behavior, bash 3.1) do NOT use quotes around right side of expression.
if [[ "${eclipseStream}" =~ ([[:digit:]]*)\.([[:digit:]]*)\.([[:digit:]]*) ]]
then
eclipseStreamMajor=${BASH_REMATCH[1]}
eclipseStreamMinor=${BASH_REMATCH[2]}
eclipseStreamService=${BASH_REMATCH[3]}
else
echo "ERROR: eclipseStream, $eclipseStream, must contain major, minor, and service versions, such as 4.2.0" >&2
exit 1
fi
buildType=${buildId:0:1}
toSiteDir="/home/data/httpd/download.eclipse.org/eclipse/updates"
updatesSuffix="builds"
toMainUpdateDir=$toSiteDir/${eclipseStreamMajor}.${eclipseStreamMinor}-${buildType}-${updatesSuffix}/
# We'll check for existence, and create if doesn't exist ... as long as it is "under" our
# toSiteDir, it is likely an intentional new one, rather than an error.
if [[ ! -d "${toMainUpdateDir}" ]]
then
if [[ -d "${toSiteDir}" ]]
then
# create
mkdir -p "${toMainUpdateDir}"
RC=$?
if [[ $RC != 0 ]]
then
echo "ERROR: could not create main update site: ${toMainUpdateDir}" >&2
# "return" empty string, as indication of error"
toMainUpdateDir=""
fi
else
echo "PROGRAM ERROR: main update site root did not exist: ${toSiteDir}" >&2
# "return" empty string, as indication of error"
toMainUpdateDir=""
fi
fi
echo $toMainUpdateDir
}
# compute update site on build server
function updateSiteOnBuildDir()
{
eclipseStream=$1
if [[ -z "${eclipseStream}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
return 1;
fi
buildId=$2
if [[ -z "${buildId}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide buildType as second argument, for this function $(basename $0)" >&2
return 1;
fi
# contrary to intuition (and previous behavior, bash 3.1) do NOT use quotes around right side of expression.
if [[ "${eclipseStream}" =~ ([[:digit:]]*)\.([[:digit:]]*)\.([[:digit:]]*) ]]
then
eclipseStreamMajor=${BASH_REMATCH[1]}
eclipseStreamMinor=${BASH_REMATCH[2]}
eclipseStreamService=${BASH_REMATCH[3]}
else
echo "eclipseStream, $eclipseStream, must contain major, minor, and service versions, such as 4.2.0" >&2
return 1
fi
buildType=${buildId:0:1}
buildRoot=${BUILD_HOME}/${eclipseStreamMajor}${buildType}
siteDir=${buildRoot}/siteDir
updatesSuffix="builds"
fromDir=$siteDir/updates/${eclipseStreamMajor}.${eclipseStreamMinor}-${buildType}-${updatesSuffix}/${buildId}
echo $fromDir
}
# compute main part of download server drop directory
function dropFromBuildDir ()
{
eclipseStream=$1
buildId=$2
pathFromDL=$( dlFromPath "$eclipseStream" "$buildId" )
if [[ "$pathFromDL" == 1 ]]
then
printf "\n\n\t%s\n\n" "ERROR: pathToDL could not be computed." >&2
return 1
fi
eclipseStreamMajor=${eclipseStream:0:1}
buildType=${buildId:0:1}
buildRoot=${BUILD_HOME}/${eclipseStreamMajor}${buildType}
siteDir=${buildRoot}/siteDir
fromDir=${siteDir}/${pathFromDL}/${buildId}
echo "$fromDir"
}
# compute main (middle part) of download site
function dlToPath()
{
eclipseStream=$1
if [[ -z "${eclipseStream}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
return 1;
fi
buildId=$2
if [[ -z "${buildId}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)" >&2
return 1;
fi
eclipseStreamMajor=${eclipseStream:0:1}
buildType=${buildId:0:1}
pathToDL=eclipse/downloads/drops
if (( $eclipseStreamMajor > 3 ))
then
pathToDL=$pathToDL$eclipseStreamMajor
fi
echo $pathToDL
}
function dlFromPath()
{
eclipseStream=$1
if [[ -z "${eclipseStream}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
return 1;
fi
buildId=$2
if [[ -z "${buildId}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)" >&2
return 1;
fi
eclipseStreamMajor=${eclipseStream:0:1}
buildType=${buildId:0:1}
pathFromDL=eclipse/downloads/drops
if (( $eclipseStreamMajor > 3 ))
then
pathFromDL=$pathFromDL$eclipseStreamMajor
fi
echo $pathFromDL
}
function syncDropLocation ()
{
echo "start syncDropLocation"
eclipseStream=$1
if [[ -z "${eclipseStream}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide eclipseStream as first argument, for this function $(basename $0)" >&2
return 1;
fi
echo "eclipseStream: $eclipseStream"
buildId=$2
if [[ -z "${buildId}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide buildId as second argument, for this function $(basename $0)" >&2
return 1;
fi
echo "buildId: $buildId"
EBUILDER_HASH=$3
if [[ -z "${EBUILDER_HASH}" ]]
then
printf "\n\n\t%s\n\n" "ERROR: Must provide builder (or aggregator) hash as fourth argument, for this function $(basename $0)" >&2
return 1;
fi
echo "EBUILDER_HASH: $EBUILDER_HASH"
eclipseStreamMajor=${eclipseStream:0:1}
buildType=${buildId:0:1}
fromDir=$( dropFromBuildDir $eclipseStream $buildId )
if [[ ! -d "${fromDir}" ]]
then
echo "ERROR: fromDir is not a directory? fromDir: ${fromDir}"
return 1
fi
toDir=$( dropOnDLServer $eclipseStream $buildId )
if [[ ! -d "${toDir}" ]]
then
echo "ERROR: toDir is not a directory? toDir: ${toDir}"
return 1
fi
echo " fromDir: ${fromDir}" >&1
echo " toDir: ${toDir}" >&1
# here, for dl site, best not to preserve times, since (if mirrored)
# would be more accurate for mirroring system to have
# actual times (and we are copying only one specific
# sub-directory) (But, we do for now, for easier testing)
if [[ -n "${fromDir}" && -d "${fromDir}" && -n "${toDir}" && -d "${toDir}" ]]
then
# Note the slash at end of aggregator ... we do not want to exclude eclipse.platform.releng.aggregator-(builder hash).zip
# TODO: remove --verbose, once confident it works as expected.
rsync --times --omit-dir-times --recursive --prune-empty-dirs --exclude="*apitoolingreference/*" --exclude="*org.eclipse.releng.basebuilder/*" --exclude="*eclipse.platform.releng.aggregator/*" --exclude="*/repository/*" --exclude="*workspace-*/*" "${fromDir}" "${toDir}"
rccode=$?
else
rccode=9
fi
if [[ $rccode != 0 ]]
then
echo "ERROR: rsync did not complete normally.rccode: $rccode"
return $rccode
else
# Now update main DL page index pages, to show available
source ${UTILITIES_HOME}/sdk/updateIndexFilesFunction.shsource
updateIndex
fi
echo "ending syncDropLocation"
}
function linkURL ()
{
url="${1}"
if [[ -z "${url}" ]]
then
echo "Programming error. URL must not be null as argument to 'linkURL'"
exit 1
fi
link="<a href=\"${url}\">${url}</a>"
echo ${link}
}
function sendEclipseMail ()
{
TO="$1"
FROM="$2"
SUBJECT="$3"
message1="$4"
(
echo "To: ${TO}"
echo "From: ${FROM}"
if [[ -n "${InReplyTo}" ]]
then
echo "In-Reply-To: ${InReplyTo}"
fi
if [[ -n "${Reference}" ]]
then
echo "Reference: ${Reference}"
fi
echo "MIME-Version: 1.0"
echo "Content-Type: text/html; charset=utf-8"
echo "Subject: ${SUBJECT}"
echo "<html><body>"
echo -e "${message1}"
echo "</body></html>"
) | /usr/lib/sendmail -t
}
function setToAndFromAddresses ()
{
# This bit of data is used in a few other scripts, such as
# syncDropLocation.sh and updateDropLoction.sh
# It primarily sets the TO and FROM fields for email.
# It also supplements the SUBJECT.
# override 'TO' in localBuildProperties.shsource if doing local tests
# for initial testing, only to me -- change as desired after initial testing.
if [[ "${buildType}" =~ [PYXU] ]]
then
case "${buildType}" in
"P" )
export TO=${TO:-"sravankumarl@in.ibm.com,jdt-core-dev@eclipse.org"}
export SUBJECT="Patch Build: ${SUBJECT}" ;;
"U" )
export TO=${TO:-"sravankumarl@in.ibm.com,noopur_gupta@in.ibm.com,jdt-ui-dev@eclipse.org"}
export SUBJECT="Branch SDK Build: ${SUBJECT}" ;;
"Y" )
export TO=${TO:-"sravankumarl@in.ibm.com,jdt-core-dev@eclipse.org"}
export SUBJECT="Branch SDK Build: ${SUBJECT}" ;;
"X" )
export TO=${TO:-"sravankumarl@in.ibm.com"}
export SUBJECT="Experimental Build: ${SUBJECT}" ;;
*)
export TO=${TO:-"sravankumarl@in.ibm.com"}
export SUBJECT="Unknown buildType ${buildType}: ${SUBJECT}"
echo -e "\n\tWARNING: Unreachable code. Programming error. case statement did not match any pattern!\n"
esac
else
if [[ "${invisibleBuild}" == "true" ]]
then
export TO=${TO:-"sravankumarl@in.ibm.com, akurtako@redhat.com"}
else
export TO=${TO:-"platform-releng-dev@eclipse.org"}
fi
fi
export FROM=${FROM:-"genie.releng@eclipse.org"}
}