blob: e5018859f08f18ac93994d4b7fee01f2edadc4f5 [file] [log] [blame]
#!/usr/bin/env bash
# script to copy update jars from their working area to the staging area
# finds file on users path, before current directory
# hence, non-production users can set their own values for test machines
source galileo_properties.shsource
#FIXUP_URLS=1
fromDirectory=${BUILD_RESULTS}
toDirectory=${stagingDirectory}
# temp area for testing
#toDirectory=${HOME}/temp/testdir
tempDir=${HOME}/temp/work
echo ""
echo " Removing previous staging directory files at"
echo " "${toDirectory}
echo ""
# make sure 'toDirectory' has been defined and is no zero length, or
# else following will eval to "rm -fr /*" ... potentially catastrophic
if [ -z "${toDirectory}" ]
then
echo "The variable toDirectory must be defined to run this script"
exit 1;
fi
if [ -d ${toDirectory} ]
then
rm -fr "${toDirectory}"/*
fi
echo ""
echo " Copying new plugins and features "
echo " from ${fromDirectory}"
echo " to ${toDirectory}"
echo ""
# plugins and features
rsync -rvp ${fromDirectory}/final/aggregate ${toDirectory}
# composite artifact and content files
rsync -vp ${fromDirectory}/final/*.jar ${toDirectory}
# log and index page
rsync -vp templateFiles/index.html ${toDirectory}
rsync -vp ${fromDirectory}/*.txt ${toDirectory}
if [[ $FIXUP_URLS ]]
then
# now correct the URLs
fromFile=artifacts.jar
workFile=artifacts.xml
unzip ${toDirectory}/aggregate/${fromFile} -d ${tempDir}
matchingPhrase="p2\.mirrorsURL.*/releases/galileo"
matchedLines=`grep "${matchingPhrase}" "${tempDir}"/"$workFile"`
nMatches=`echo $matchedLines | wc -l`
echo
echo " matches before replacement: "${nMatches}
echo " matchedLine(s) before replacement: "
echo " "$matchedLines
echo
if [[ $nMatches == 1 ]]
then
# currently a quirk of build system, file references in working directory
# are to "/releases/galileo" (even though that's not where they are)
fromString="p2\.mirrorsURL(.*)/releases/galileo"
# compose toString and replacement command
toString="p2\.mirrorsURL\$1/releases/maintenance"
replaceCommand="s!${fromString}!${toString}!g"
echo " replaceCommand: ${replaceCommand}"
perl -pi -w -e ${replaceCommand} "${tempDir}"/"${workFile}"
perlResult=$?
if [[ $perlResult -ne 0 ]]
then
echo "Perl return code was non-zero, ${perlResult}, so exiting and not changing anything"
exit $perlResult
fi
nOriginalMatches=`grep "${matchingPhrase}" "${tempDir}"/"$workFile" | wc -l`
echo
echo " matchedLine(s) after replacement: " $nOriginalMatches " (should be zero)"
echo
if [[ $nOriginalMatches -ne 0 ]]
then
echo " Error: number of matches to original phrase (" $nOriginalMatches ") after replacement was greater than expected (should be zero), so exiting and not changing anything"
exit 1
fi
resultingPhrase="p2\.mirrorsURL.*/releases/maintenance"
changedLines=`grep "${resultingPhrase}" "${tempDir}"/"$workFile"`
nChangedLines=`echo $changedLines | wc -l`
echo
echo " Number of lines changed: " $nChangedLines
echo " Changeded lines: "
echo " "$changedLines
echo
if [[ $nChangedLines -ne 1 ]]
then
echo " Error: number of matches to expected ("$nChangedLines") after replacement was not as expected (should be zero), so exiting and not changing anything"
exit 1
fi
else
echo " Error: number of matches to original ("$nMatches") before replacment was not as expected, so exiting and not changing anything"
exit 1
fi
#perl -pi -w -e ${replaceCommand} ${toDirectory}/content.xml
echo "rezip our modified versions"
zip -Djm ${toDirectory}/aggregate/artifacts.jar "${tempDir}"/"${workFile}"
#zip -Djm ${toDirectory}/content.jar ${toDirectory}/content.xml
fi
# obfuscateEmail
# remove lock file from hundson build's "pauseAll.sh" script once we are all done
rm -vf "${BUILD_HOME}"/lockfile