view contrib/make_flys_release/make_release.sh @ 8509:32c94ca227bc

(issue1782) Invert artifact range if necessary in officiallinefinder
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 16 Dec 2014 15:58:33 +0100
parents da9365fc2f42
children 522c46c53861
line wrap: on
line source
#!/bin/bash
# Release script for Dive4Elements River
#
# Authors:
# Andre Heinecke <aheinecke@intevation.de>
#
# Copyright (C) 2011 - 2014 by Bundesanstalt für Gewässerkunde
# Software engineering by Intevation GmbH
#
# This file is Free Software under the GNU AGPL (>=v3)
# and comes with ABSOLUTELY NO WARRANTY! Check out the
# documentation coming with Dive4Elements River for details.

set -e
LC_ALL=en_US.UTF-8
DEFAULT_WD=/tmp/flys-release
DEVELOPER=aheinecke

ARTIFACTS_HG_REPO="https://wald.intevation.org/hg/dive4elements/framework"
HTTPCLIIENT_HG_REPO="https://wald.intevation.org/hg/dive4elements/http-client"
FLYS_HG_REPO="https://wald.intevation.org/hg/dive4elements/river"

REPOS="river http-client framework"
# Do not use spaces in path
FLYS_SOURCE_DIR=/local-vol1/aheinecke/flys-release

SCRIPT_DIR=$(readlink -f `dirname $0`)
usage(){
    cat << EOF

usage: $0 [options] VERSION

Create a D4E River package

OPTIONS:
   -?, --help          Show this message
   -w                  The working directory to use (do not use spaces in path)
                       Default: $DEFAULT_WD
   -t                  Tag the current default branch as "VERSION"
   -o, --oracle        Release is for oracle.
                       Suitable jar-files for JDBC driver and
                       hibernate-spatial have to be given with the
                       environment variables ORACLE_JDBC and ORACLE_HIBERNATE
   VERSION must be in the format MAYOR.MINOR.PATCH or default
EOF
exit 0
}
#   --backend-db-url                Url of database backend. Default: $BACKENDURL
#   --backend-db-pass               Backend db password. Default: $BACKENDPASS
#   --backend-db-port               Backend db port. Default: $BACKENDPORT
#   --backend-db-user               Backend db user. Default: $BACKENDUSER
#   --backend-db-backend            Backend db backend name. Default: $BACKENDBACK
#   --seddb-url                     Sediment db url. Default: $SEDDBURL
#   --seddb-port                    Sediment db port. Default: $SEDDBPORT
#   --seddb-user                    Sediment db user. Default: $SEDDBUSER
#   --seddb-pass                    Sediment db password. Default: $SEDDBPASS
#   --seddb-back                    Sediment db backend. Default: $SEDDBBACK

# customizable variables
ELBE_MODEL_UUID=${ELBE_MODEL_UUID:-1a4825f6-925f-11e3-8165-001f29e71d12}

OPTS=`getopt -o ?w:,t,o \
     -l help,oracle \
     -n $0 -- "$@"`

if [ $? != 0 ] ; then usage; fi
eval set -- "$OPTS"
while true ; do
  case "$1" in
    "-?"|"--help")
      usage;;
    "--")
      shift
      break;;
    "-w")
      WORK_DIR=$2
      shift 2;;
    "-o"|"--oracle")
      BUILD_ORACLE="TRUE"
      shift;;
    "-t")
      DO_TAG="TRUE"
      shift;;
    *)
      echo "Unknown Option $1"
      usage;;
  esac
done

if [ $# != 1 ]; then
    usage
fi

VERSION=$1

if [ -z $WORK_DIR ]; then
  WORK_DIR=$DEFAULT_WD
fi

mkdir -p $WORK_DIR

if [ ! -d $FLYS_SOURCE_DIR ]; then
    mkdir -p $FLYS_SOURCE_DIR
    echo "Cloning sources"
    cd $FLYS_SOURCE_DIR
    hg clone $ARTIFACTS_HG_REPO framework
    hg clone $HTTPCLIIENT_HG_REPO http-client
    hg clone $FLYS_HG_REPO river
else
    echo "Updating sources / Reverting changes"
    cd $FLYS_SOURCE_DIR
    for repo in $REPOS; do
        cd $repo && hg pull && hg revert -a && hg up && cd $FLYS_SOURCE_DIR
    done;
fi

if [ "$DO_TAG" = "TRUE" ]; then
    echo "Tagging version $VERSION"
    for repo in $REPOS; do
        cd $repo
        CHANGESET=$(hg log -l1 |head -1 | awk -F: '{print $3}')
        echo ""
        echo "Do you really want to tag $repo rev: $CHANGESET as Version $VERSION?"
        echo "press enter to continue or CTRL+C to abort."
        echo ""
        hg log -l1
        read
        OLD_REV=$(cat .hgtags | tail -1 | awk '{print $2}')
        hg tag $VERSION -m "Added tag $VERSION for changeset $CHANGESET"
        hg push ssh://$DEVELOPER@scm.wald.intevation.org/hg/dive4elements/$repo
        echo "Changelog for $repo" >> $WORK_DIR/changes_$OLD_REV-$VERSION.txt
        echo "#############################################################################" \
            >> $WORK_DIR/changes_$OLD_REV-$VERSION.txt
        hg log -r $VERSION:$OLD_REV --style changelog >> $WORK_DIR/changes_$OLD_REV-$VERSION.txt
        cd $FLYS_SOURCE_DIR
    done;
fi

# Update to current version
for repo in $REPOS; do
    cd $repo
    if [ -z "`hg tags | sed -n "/$VERSION/p"`" -a -z "`hg branches | sed -n "/$VERSION/p"`" ]
    then
        echo "WARNING: $VERSION not found in $repo! Updating to default."
        hg up default
    else
        hg up "$VERSION"
    fi
    cd $FLYS_SOURCE_DIR
done

rm -rf "$WORK_DIR/server" "$WORK_DIR/client"
cd $WORK_DIR
mkdir -p "$WORK_DIR/server/bin/lib/own"
mkdir "$WORK_DIR/server/shapefiles"
mkdir "$WORK_DIR/client"


echo "INFO: Preparing configuration of web client"

#Needs to be done before the tomcat replacement below
sed -i -e "s@1a4825f6-925f-11e3-8165-001f29e71d12@${ELBE_MODEL_UUID}@g" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/images/FLYS_Karte_interactive.html

if [ -d $WEBINF ]; then
    echo "INFO: copy custom client configuration to target destination"
    WEBINF_DIR=$FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/
    cp -R $WEBINF/* $WEBINF_DIR
    for file in `find $WEBINF_DIR/ -type f`; do
        sed -i -e "s@D4E_VERSION@${VERSION}@g" $file
    done
fi

if [ -f $CLIENT_CONF ]; then
    echo "INFO: copy custom java script client configuration to target destination"
    cp $CLIENT_CONF \
        $FLYS_SOURCE_DIR/river/gwt-client/src/main/java/org/dive4elements/river/client/client/config.xml
fi

if [ ! -f $FLYS_SOURCE_DIR/OpenLayers-2.11.tar.gz ]; then
    echo "INFO: download OpenLayers-2.11 for client"
    cd $FLYS_SOURCE_DIR
    curl -O http://openlayers.org/download/OpenLayers-2.11.tar.gz
    tar xvfz OpenLayers-2.11.tar.gz
    # TODO: Remove more superfluous OpenLayers stuff.
    rm -rf OpenLayers-2.11/doc
    rm -rf OpenLayers-2.11/tests
    rm -rf OpenLayers-2.11/examples
    cd $WORK_DIR
fi
cp -r $FLYS_SOURCE_DIR/OpenLayers-2.11 $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/

echo "INFO: Downloading smartGWT"
mvn com.isomorphic:isc-maven-plugin:install -Dproduct=SMARTGWT -Dlicense=LGPL \
    -DbuildNumber=4.1p -DbuildDate=2014-12-13 -Dworkdir=$WORK_DIR

echo "INFO: compile and build sources"
mvn -f $FLYS_SOURCE_DIR/framework/pom.xml clean compile package install
mvn -f $FLYS_SOURCE_DIR/river/backend/pom.xml clean compile package install
mvn -f $FLYS_SOURCE_DIR/river/artifacts/pom.xml clean compile package dependency:copy-dependencies install
mvn -f $FLYS_SOURCE_DIR/http-client/pom.xml clean compile package install
mvn -f $FLYS_SOURCE_DIR/river/gwt-client/pom.xml clean compile package

# remove unused Version of JFreeChart (it's a dependency of JasperReports
# that prevents diagram generation in D4E river)
rm $FLYS_SOURCE_DIR/river/artifacts/target/dependency/jfreechart-1.0.12.jar

echo "INFO: copy dependencies and libs"
cp $FLYS_SOURCE_DIR/framework/artifact-database/target/artifact-database-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/
cp $FLYS_SOURCE_DIR/framework/artifacts/target/artifacts-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/
cp $FLYS_SOURCE_DIR/framework/artifacts-common/target/artifacts-common-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/
cp $FLYS_SOURCE_DIR/river/backend/target/river-backend-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/
cp $FLYS_SOURCE_DIR/river/artifacts/target/river-artifacts-1.0-SNAPSHOT.jar $WORK_DIR/server/bin/lib/own/
cp $FLYS_SOURCE_DIR/river/gwt-client/target/gwt-client-1.0-SNAPSHOT.war $WORK_DIR/client/flys-${VERSION}.war
cp $FLYS_SOURCE_DIR/river/artifacts/target/dependency/* $WORK_DIR/server/bin/lib/

echo "INFO: copy scripts and libraries to target destination"
cp ${SCRIPT_DIR}/bin/run.sh $WORK_DIR/server/bin/
cp ${SCRIPT_DIR}/libs/* $WORK_DIR/server/bin/lib/

echo "INFO: download WSPLGEN"
wget https://wald.intevation.org/frs/download.php/1496/wsplgen-linux-64bit-static.gz
gunzip wsplgen-linux-64bit-static.gz
echo "16d60047aa114d69e9435dbbe56b6981b4e1c445  wsplgen-linux-64bit-static" | \
    sha1sum -c
mv wsplgen-linux-64bit-static $WORK_DIR/server/bin/wsplgen
chmod +x $WORK_DIR/server/bin/wsplgen

if [ "$BUILD_ORACLE" = "TRUE" ]; then
    echo "INFO: remove PostgreSQL and PostGIS libraries"
    rm $WORK_DIR/server/bin/lib/postg*
    rm $WORK_DIR/server/bin/lib/hibernate-spatial-postgis*
    if [ ! -f $ORACLE_JDBC ]; then
        echo "Could not find oracle jdbc in $ORACLE_JDBC"
        echo "Please make sure that the ORACLE_JDBC variable is set correctly"
        exit 1
    fi
    if [ ! -f $ORACLE_HIBERNATE ]; then
        echo "Could not find hibernate-spatial-oracle in $ORACLE_HIBERNATE"
        echo "Please make sure that the ORACLE_HIBERNATE variable is set correctly"
        exit 1
    fi
    cp $ORACLE_HIBERNATE $ORACLE_JDBC $WORK_DIR/server/bin/lib/
else
    echo "INFO: remove Oracle libraries"
    rm -f $WORK_DIR/server/bin/lib/hibernate-spatial-oracle-1.1.jar
    rm -f $WORK_DIR/server/bin/lib/ojdbc*
fi


echo "INFO: copy default server configuration to target destination"
cp -R $FLYS_SOURCE_DIR/river/artifacts/doc/conf $WORK_DIR/server/

if [ -n $DGM_PATH ]; then
    sed -i -e "s@<dgm-path>/path/to/rivers/</dgm-path>@<dgm-path>${DGM_PATH}</dgm-path>@g" \
        $WORK_DIR/server/conf/conf.xml
fi

if [ -n $WIKI_URL ]; then
    sed -i -e "s@<help-url>http://example.com</help-url>@<help-url>${WIKI_URL}</help-url>@g" \
        $WORK_DIR/server/conf/conf.xml
fi

if [ -d $SERVER_CONF ]; then
    echo "INFO: copy custom server configuration to target destination"
    cp -R $SERVER_CONF/* $WORK_DIR/server/conf/
    for file in `find $WORK_DIR/server/conf -type f`; do
        sed -i -e "s@D4E_VERSION@${VERSION}@g" $file
    done
fi


echo "INFO: create h2 database for artifacts and datacage"
mkdir $WORK_DIR/artifactsdb
mkdir $WORK_DIR/datacagedb

cp $FLYS_SOURCE_DIR/framework/artifact-database/doc/schema-h2.sql $WORK_DIR/artifactsdb/artifacts-h2.sql
cp $FLYS_SOURCE_DIR/river/artifacts/doc/conf/datacage.sql $WORK_DIR/datacagedb/datacage.sql

cd $WORK_DIR
$SCRIPT_DIR/h2/createArtifacts.sh $WORK_DIR/artifactsdb/artifacts-h2.sql
$SCRIPT_DIR/h2/createDatacage.sh $WORK_DIR/datacagedb/datacage.sql
cd -

mv $WORK_DIR/artifactsdb $WORK_DIR/server/
mv $WORK_DIR/datacagedb $WORK_DIR/server/

if [ -f $INSTALL ]; then
    echo "INFO: prepare custom installation script"
    cp $INSTALL $WORK_DIR
    sed -i "s/D4E_VERSION/$VERSION/g" $WORK_DIR/`basename $INSTALL`
fi

echo "INFO: create tarball"
if [ -d "$WORK_DIR/flys-$VERSION" ]; then
    echo "INFO: removing old directory"
    rm -rf "$WORK_DIR/flys-$VERSION"
fi

mkdir $WORK_DIR/flys-$VERSION
mv $WORK_DIR/server $WORK_DIR/client $WORK_DIR/flys-$VERSION
if [ -n $INSTALL ]; then
    mv $WORK_DIR/`basename $INSTALL` $WORK_DIR/flys-$VERSION
fi
cd $WORK_DIR
tar cfz flys-$VERSION.tar.gz flys-$VERSION
#echo "INFO: cleanup"
#rm -r $WORK_DIR/flys-$VERSION

echo "DONE: $WORK_DIR/flys-$VERSION.tar.gz"
echo "Changelog: $WORK_DIR/changes_$OLD_REV-$VERSION.txt"

http://dive4elements.wald.intevation.org