aheinecke@5097: #!/bin/bash
tom@8675: # Packaging-script for Dive4Elements River-Importer
tom@8675: #
tom@8675: # Copyright (C) 2011 - 2014 by Bundesanstalt für Gewässerkunde
tom@8675: # Software engineering by Intevation GmbH
tom@8675: #
tom@8675: # This file is Free Software under the GNU AGPL (>=v3)
tom@8675: # and comes with ABSOLUTELY NO WARRANTY! Check out the
tom@8675: # documentation coming with Dive4Elements River for details.
tom@8675: 
aheinecke@5097: set -e
aheinecke@5097: 
tom@8675: # See ../README for more information
tom@8675: # The working directory. Resulting tarball will be placed here.
tom@8675: PKG_DIR=/tmp/flys-importer
aheinecke@5097: # Path to the flys checkout
tom@8675: SOURCE_DIR=$(readlink -f `dirname $0`)/../../..
aheinecke@5097: 
tom@8675: usage(){
tom@8675:     cat << EOF
tom@8675: 
tom@8675: usage: $0 [options] VERSION [EXTRAS]
tom@8675: 
tom@8675: Create a D4E River Importer-package
tom@8675: 
tom@8675: OPTIONS:
tom@8675:    -?, --help          Show this message
tom@8675:    -o, --oracle        Package is for Oracle.
tom@8675:                        Suitable jar-file for JDBC driver has to be given with
tom@8675:                        the environment variable ORACLE_JDBC
tom@8675:    VERSION must specify a tag (usually MAYOR.MINOR.PATCH) or a branch name.
tom@8675:    With EXTRAS, a tarball with dependencies can be given.
tom@8675: EOF
tom@8675: exit 0
tom@8675: }
tom@8675: 
tom@8675: OPTS=`getopt -o ?,o -l help,oracle -n $0 -- "$@"`
tom@8675: 
tom@8675: if [ $? != 0 ] ; then usage; fi
tom@8675: eval set -- "$OPTS"
tom@8675: while true ; do
tom@8675:   case "$1" in
tom@8675:     "-?"|"--help")
tom@8675:       usage;;
tom@8675:     "--")
tom@8675:       shift
tom@8675:       break;;
tom@8675:     "-o"|"--oracle")
tom@8675:       BUILD_ORACLE="TRUE"
tom@8675:       shift;;
tom@8675:     *)
tom@8675:       echo "Unknown Option $1"
tom@8675:       usage;;
tom@8675:   esac
tom@8675: done
tom@8675: 
tom@8675: if [ $# != 1 ]; then
tom@8675:     usage
aheinecke@5179: fi
aheinecke@5097: 
tom@8675: VERSION=$1
tom@8675: EXTRAS=$2
tom@8675: 
tom@8675: # Update to VERSION
tom@8675: echo "WARNING: any local changes in $SOURCE_DIR will be packaged."
tom@8675: cd ${SOURCE_DIR}
tom@8675: if [ -z "`hg tags | sed -n "/$VERSION/p"`" -a -z "`hg branches | sed -n "/$VERSION/p"`" ]
tom@8675: then
tom@8742:     echo "ERROR: No tag or branch $VERSION found in repository of $repo!"
tom@8742:     exit 1
tom@8675: else
tom@8675:     hg up "$VERSION"
tom@8675: fi
tom@5520: 
tom@6814: # create PDF of manual
tom@7334: REV=`hg parent | sed -n '1s/[[:alnum:]]*: *\([0-9]*:.*\)/\1/;1p'`
tom@8675: cd ${SOURCE_DIR}/backend/doc/documentation/de/
tom@7334: sed -i "s/documentrevision..rev.*/documentrevision}{rev$REV}/" \
tom@6814:     importer-manual.tex
tom@7331: # run pdflatex three times to get references and page numbering right
tom@7331: pdflatex importer-manual.tex
tom@7331: pdflatex importer-manual.tex
tom@6814: pdflatex importer-manual.tex
aheinecke@5097: 
tom@8675: # package importer
tom@8675: if [ "$BUILD_ORACLE" = "TRUE" ]; then
tom@8675:     if [ ! -f $ORACLE_JDBC ]; then
tom@8675:         echo "Could not find oracle jdbc in $ORACLE_JDBC"
tom@8675:         echo "Please make sure that the ORACLE_JDBC variable is set correctly"
tom@8675:         exit 1
tom@8675:     fi
tom@8675:     mvn install:install-file -DgroupId=ojdbc -DartifactId=ojdbc \
tom@8675:        -Dversion=0 -Dpackaging=jar -Dfile=$ORACLE_JDBC -DgeneratePom=true
tom@8675:     mvn -f $SOURCE_DIR/backend/pom-oracle.xml clean package assembly:single
tom@8675: else
tom@8675:     mvn -f $SOURCE_DIR/backend/pom.xml clean package assembly:single
tom@8675: fi
tom@8675: 
tom@8675: echo "INFO: create tarball"
tom@8675: rm -fr $PKG_DIR
tom@8675: mkdir $PKG_DIR
tom@8675: cd $PKG_DIR
tom@8675: 
tom@8675: mv $SOURCE_DIR/backend/target/river-backend-1.0-SNAPSHOT*-flys-importer.tar \
tom@8675:     flys-importer-$VERSION.tar
tom@8675: if [ -f "$EXTRAS" ]; then
tom@8675:     tar -xzf "$EXTRAS"
tom@8675:     tar -rf flys-importer-$VERSION.tar opt
tom@8675: fi
tom@8675: 
tom@8675: gzip flys-importer-$VERSION.tar
tom@8675: sha1sum flys-importer-$VERSION.tar.gz > flys-importer-$VERSION.tar.gz.sha1
tom@8675: echo Package is at: `readlink -f flys-importer-$VERSION.tar.gz`