1#!/bin/bash
2#
3# This work is dual-licensed under the Apache License 2.0
4# and European Union Public License. See LICENSE file for details.
5#
6# Parts of this file Copyright (c) 2017 Evolveum and contributors
7#
8
9SCRIPT_PATH=$(cd $(dirname "$0") && pwd -P)/
10
11# resolve links - $0 may be a softlink
12PRG="$0"
13
14while [ -h "$PRG" ]; do
15ls=`ls -ld "$PRG"`
16  link=`expr "$ls" : '.*-> \(.*\)$'`
17  if expr "$link" : '/.*' > /dev/null; then
18    PRG="$link"
19  else
20    PRG=`dirname "$PRG"`/"$link"
21  fi
22done
23
24# Get standard environment variable
25PRGDIR=`dirname "$PRG"`
26
27cd "$PRGDIR/.." >/dev/null
28
29cd "$SCRIPT_PATH/.."
30
31# honor MIDPOINT_HOME variable if it exists!
32if [ -z "$MIDPOINT_HOME" ]; then
33    if [ ! -d var ] ; then
34        echo "ERROR: midpoint.home directory desn't exist"
35        exit 1
36    else
37        MIDPOINT_HOME=$(cd "$SCRIPT_PATH../var"; pwd)
38    fi
39
40    [ -z "$MIDPOINT_HOME" ] && MIDPOINT_HOME=`cd "$SCRIPT_PATH../var" >/dev/null; pwd`
41fi
42#cd "$SCRIPT_PATH../lib"
43
44if [ ! -f lib/ninja.jar ] ; then
45    echo "ERROR: ninja.jar is not in /lib directory"
46    exit 1
47fi
48
49# Set UMASK unless it has been overridden
50if [ -z "$UMASK" ]; then
51    UMASK="0027"
52fi
53umask $UMASK
54
55if [ -z "$JAVA_HOME" ] ; then
56  _RUNJAVA=java
57else
58  _RUNJAVA="$JAVA_HOME"/bin/java
59fi
60
61while getopts ":j:" opt; do
62  case $opt in
63    j)
64      JDBC_DRIVER=$OPTARG
65      ;;
66  esac
67done
68
69if [ ! -z "$JDBC_DRIVER" ] ; then
70   JDBC_DRIVER="-Dloader.path=$JDBC_DRIVER"
71fi
72
73exec "$_RUNJAVA" $JDBC_DRIVER -jar $SCRIPT_PATH../lib/ninja.jar -m $MIDPOINT_HOME $@
74
75
76