view contrib/make_flys_release/make_release.sh @ 8500:414e68e6d19a

The used patch build of SmartGWT is not available anymore.
author Tom Gottfried <tom@intevation.de>
date Mon, 15 Dec 2014 19:27:04 +0100
parents 5096b4ed230d
children c8d633c0971b
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 flys 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
TOMCAT_PORT=${TOMCAT_PORT:-8282}
WIKI_URL=${WIKI_URL:-https://flys3-devel.bafg.de/wiki}
# Prefix to FreeSans.ttf
FONT_PATH=${FONT_PATH:-/opt/flys}

# Backend configuration
LOG_DIR=/var/log/flys

# Client configuration
AUTH=${AUTH:-GGinA}
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 [ -n "`hg branches | sed -n "/$VERSION/p"`" ]; then
    ARTIFACT_PORT=${ARTIFACT_PORT:-29999}
else
    ARTIFACT_PORT=${ARTIFACT_PORT:-`echo 1$VERSION | sed 's/\.//g'`}
fi

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"
echo "[INFO]: Tomcat Port: $TOMCAT_PORT"
echo "[INFO]: Artifact Port: $ARTIFACT_PORT"

#Needs to be done before the tomcat replacement below
if [ -r "$FEATURES_XML" ]; then
    cp "$FEATURES_XML" \
        $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/features.xml
fi

if [ -r "$CLIENT_LOG4J" ]; then
    cp "$CLIENT_LOG4J" \
        $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/log4j.properties
fi

sed -i -e "s@http://localhost:8080/d4e-river/flys/mapfish-print@https://localhost/flys-${VERSION}/flys/mapfish-print@g" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/web.xml

sed -i -e "s@http://localhost:8181@http://localhost:$ARTIFACT_PORT@g" \
       -e "s@http://localhost:8888@http://localhost:$TOMCAT_PORT@g" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/web.xml

sed -i -e "s@<param-value>plain</param-value>@<param-value>$AUTH</param-value>@" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/web.xml

sed -i -e "s@https://flys3-devel.bafg.de/wiki@${WIKI_URL}@g" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/java/org/dive4elements/river/client/client/config.xml

sed -i -e \
    "s@/var/log/d4e-river/d4e-client.log@${LOG_DIR}/client-VERSION.log@g" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/log4j.properties

sed -i -e "s@VERSION@${VERSION}@g" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/log4j.properties

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

find $FLYS_SOURCE_DIR/river/ -name \*.properties -o -name \*.xsl |  \
    xargs sed -i "s@https://flys-intern.intevation.de@${WIKI_URL}@g";

if [ -r "$WMSSERVICES_XML" ]; then
    cp "$WMSSERVICES_XML" \
        $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/wms-services.xml
fi

if [ -r "$CONFIG_YAML" ]; then
    cp "$CONFIG_YAML" $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/config.yaml
fi

sed -i -e "s@/usr/share/fonts/truetype/freefont@${FONT_PATH}@g" \
    $FLYS_SOURCE_DIR/river/gwt-client/src/main/webapp/WEB-INF/config.yaml


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 Oralce 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 configuration to target destination"
cp -R $FLYS_SOURCE_DIR/river/artifacts/doc/conf $WORK_DIR/server/

sed -i "s/8181/$ARTIFACT_PORT/g" \
    $WORK_DIR/server/conf/rest-server.xml

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 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