blob: e8ab4ed671ce025c901904abb2acd316da30fe79 [file] [log] [blame]
#!/bin/bash
#
# Copyright (c) 2016 Christian W. Damus and others.
# 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:
# Christian W. Damus - initial API and implementation
#
set -e
set -u
#
# Global variables
#
REMOTE_DIR=/home/data/httpd/download.eclipse.org/papyrus-rt/installer/updates/
#
# Handle command-line options
#
function usage() {
echo "
Usage: $0 [ -r <path> ]
where
<path> is the path of the 'remote' directory to which to publish
"
exit 2
}
args=`getopt r: $*`
if [ $? != 0 ]; then
usage
fi
set -- $args
for i; do
case "$i" in
-r)
REMOTE_DIR="$2"; shift;
shift;;
--)
shift; break;;
esac
done
#
# Functions
#
function bail() {
local errresult=$?
# Ensure that the stage is removed
rm -rf "$STAGE"
return errresult
}
#
# Main program. Promote the current nightly build to milestone or release.
#
# The artifacts to be published are all in the latest nightly build.
# Be sure to do this before we re-write the REMOTE_DIR variable
NIGHTLY_DIR=$REMOTE_DIR/nightly
cd "$NIGHTLY_DIR"
# Compute remote directory
case "${BUILD_TYPE:=nightly}" in
milestone)
REMOTE_DIR="$REMOTE_DIR/milestones"
;;
release)
# Remote directory is the release directory
;;
*)
echo "Cannot promote nightly build to $BUILD_TYPE."
exit 2
;;
esac
# Create the staging directory
STAGE=$REMOTE_DIR.stage.$RANDOM
if [ -e "$STAGE" ]; then
echo "Cannot create staging area for publish."
exit 1
fi
REPOSITORY=$STAGE/repository
mkdir -p "$REPOSITORY"
# Put the repository
rsync -a repository/ "$REPOSITORY" || bail
# And the packages
cp -a Papyrus-RT-Installer-*.{zip,tar.gz,exe} "$STAGE" || bail
# Cut over
if [[ -d "$REMOTE_DIR" || ! ( -e "$REMOTE_DIR" ) ]]; then
rm -rf "$REMOTE_DIR/repository" || bail
mkdir -p "$REMOTE_DIR" || bail
# Point of no return
mv -f "$REPOSITORY" "$REMOTE_DIR"
mv -f "$STAGE"/Papyrus-RT-Installer-*.{zip,tar.gz,exe} "$REMOTE_DIR"
rm -rf "$STAGE"
else
echo "Remote exists but is not a directory."
rm -rf "$STAGE"
exit 1
fi