#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if [ -z "$1" ];
then
	echo "Need a release version, e.g. '1.6'"
	echo "Usage release <release_name> <svn_release_dir>"
    exit 1
fi

if [ -z "$2" ];
then
	echo "Need an svn release directory path, e.g. '/usr/local/foo/mcf-dev'"
	echo "Usage release <release_name> <svn_release_dir>"
    exit 1
fi

ant clean clean-core-deps clean-deps
rm -r apache-manifoldcf-*
ant make-core-deps make-deps
ant image

gpg --armor --output apache-manifoldcf-$1-src.zip.asc --detach-sig apache-manifoldcf-$1-src.zip
gpg --armor --output apache-manifoldcf-$1-src.tar.gz.asc --detach-sig apache-manifoldcf-$1-src.tar.gz
gpg --armor --output apache-manifoldcf-$1-lib.zip.asc --detach-sig apache-manifoldcf-$1-lib.zip
gpg --armor --output apache-manifoldcf-$1-lib.tar.gz.asc --detach-sig apache-manifoldcf-$1-lib.tar.gz
gpg --armor --output apache-manifoldcf-$1-bin.zip.asc --detach-sig apache-manifoldcf-$1-bin.zip
gpg --armor --output apache-manifoldcf-$1-bin.tar.gz.asc --detach-sig apache-manifoldcf-$1-bin.tar.gz

gpg --print-md MD5 apache-manifoldcf-$1-src.zip > apache-manifoldcf-$1-src.zip.md5
gpg --print-md MD5 apache-manifoldcf-$1-src.tar.gz > apache-manifoldcf-$1-src.tar.gz.md5
gpg --print-md MD5 apache-manifoldcf-$1-lib.zip > apache-manifoldcf-$1-lib.zip.md5
gpg --print-md MD5 apache-manifoldcf-$1-lib.tar.gz > apache-manifoldcf-$1-lib.tar.gz.md5
gpg --print-md MD5 apache-manifoldcf-$1-bin.zip > apache-manifoldcf-$1-bin.zip.md5
gpg --print-md MD5 apache-manifoldcf-$1-bin.tar.gz > apache-manifoldcf-$1-bin.tar.gz.md5

gpg --print-md SHA512 apache-manifoldcf-$1-src.zip > apache-manifoldcf-$1-src.zip.sha512
gpg --print-md SHA512 apache-manifoldcf-$1-src.tar.gz > apache-manifoldcf-$1-src.tar.gz.sha512
gpg --print-md SHA512 apache-manifoldcf-$1-lib.zip > apache-manifoldcf-$1-lib.zip.sha512
gpg --print-md SHA512 apache-manifoldcf-$1-lib.tar.gz > apache-manifoldcf-$1-lib.tar.gz.sha512
gpg --print-md SHA512 apache-manifoldcf-$1-bin.zip > apache-manifoldcf-$1-bin.zip.sha512
gpg --print-md SHA512 apache-manifoldcf-$1-bin.tar.gz > apache-manifoldcf-$1-bin.tar.gz.sha512

cp KEYS apache-manifoldcf-$1.KEYS
cp CHANGES.txt apache-manifoldcf-$1.CHANGES.txt

svn mkdir $2/apache-manifoldcf-$1
cp apache-manifoldcf-$1* $2/apache-manifoldcf-$1
svn add $2/apache-manifoldcf-$1/*
svn -m "Upload release candidate for MCF $1" commit $2/apache-manifoldcf-$1

