blob: 106926928a331c94548c0e20a56baefb2f30a4c7 [file] [log] [blame]
#!/bin/sh
# ====================================================================
# Copyright (c) 2014 Obeo
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Obeo - initial API and implementation
# ====================================================================
_retrieveZippedArtifact() {
local artifactURL="${1}"
local localArtifact="${2}"
local unzipTo="${3}"
curl -s -k "${artifactURL}" > "${localArtifact}"
if [ -d "${unzipTo}" ]; then
rm -rf "${unzipTo}"
fi
unzip -qq "${localArtifact}" -d "${unzipTo}"
}
_updateLatestUpdateSite() {
local updateHome="${1}"
local absolutePathToLatest="${updateHome}${2:+/${2}}"
local prefix="${3}"
local latestRepoLabel="${4}"
local currentPwd=$(pwd)
cd "${updateHome}"
local allFilesWithPrefix=( $(echo "${prefix}"* | tr ' ' '\n' | grep -E '[0-9]+\.[0-9]+\.[0-9]+.*' || true) )
cd "${currentPwd}"
if [ ${#allFilesWithPrefix[@]} -gt 0 ]; then
local latestUpdatePath=$( echo ${allFilesWithPrefix[@]} | tr ' ' '\n' | sort | tail -n 1 )
local relpath=$( relativize ${absolutePathToLatest} ${updateHome}/${latestUpdatePath} )
LSINFO "Creating redirection from '${absolutePathToLatest}' to '${latestUpdatePath}'"
createRedirect "${absolutePathToLatest}" "${relpath}" "${latestRepoLabel}"
else
LSDEBUG "No folder in '${updateHome}' have a name that start with '${prefix}' and that match the regex '[0-9]+\.[0-9]+\.[0-9]+.*'."
fi
}
_publishUpdateSiteInStream() {
local updateHome="${1}"
local projectName="${2}"
local category="${3}"
local qualifiedVersion="${4}"
local stream="${5}"
local repoLabelPrefix="${projectName}${stream:+ ${stream}${STREAM_NAME_SUFFIX}}"
local streamPath="${stream:+${STREAMS_FOLDER}/${stream}${STREAM_NAME_SUFFIX}}"
local streamAbsolutePath="${updateHome}${streamPath:+/${streamPath}}"
local relPathToUpdateSite=$( relativize "${streamAbsolutePath}" "${updateHome}/${qualifiedVersion}" )
LSDEBUG "Adding '${relPathToUpdateSite}' to composite repository '${streamAbsolutePath}'"
compositeRepository \
-location "${streamAbsolutePath}" \
-add "${relPathToUpdateSite}" \
-repositoryName "${repoLabelPrefix} ${category} builds" \
-compressed
createP2Index "${streamAbsolutePath}"
LSDEBUG "Updating latest of stream '${stream}${STREAM_NAME_SUFFIX}' @ '${streamAbsolutePath}'"
_updateLatestUpdateSite "${updateHome}" "${streamPath}${streamPath:+/}${LATEST_FOLDER}" "${stream}" "${repoLabelPrefix} latest ${category} build"
}
publishUpdateSite() {
local wd="${1}"
local projectName="${2}"
local category="${3}"
local artifactURL="${4}"
local qualifiedVersion="${5}"
local updateHome="${6}"
# the update site
LSINFO "Downloading '${artifactURL}'"
local targetUpdateSiteName="update-site-${qualifiedVersion}"
_retrieveZippedArtifact "${artifactURL}" "${wd}/${targetUpdateSiteName}.zip" "${wd}/${targetUpdateSiteName}"
if [ ! -d "${updateHome}/${qualifiedVersion}" ]; then
LSDEBUG "Creating folder '${updateHome}/${qualifiedVersion}'"
mkdir -p "${updateHome}/${qualifiedVersion}"
fi
LSINFO "Copying update site to '${updateHome}/${qualifiedVersion}'"
cp -Rf "${wd}/${targetUpdateSiteName}/"* "${updateHome}/${qualifiedVersion}"
## streams update
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" "$(unqualifiedVersion ${qualifiedVersion})"
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" "$(minorVersion ${qualifiedVersion})"
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" "$(majorVersion ${qualifiedVersion})"
_publishUpdateSiteInStream "${updateHome}" "${projectName}" "${category}" "${qualifiedVersion}" ""
}