#!/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.

# Run fuseki as a standalone server

export FUSEKI_HOME="${FUSEKI_HOME:-$PWD}"

if [ ! -e "$FUSEKI_HOME" ]
then
    echo "$FUSEKI_HOME does not exist" 1>&2
    exit 1
    fi

JAR1="$FUSEKI_HOME/fuseki-server.jar"
JAR2="$FUSEKI_HOME/jena-fuseki-server-*.jar"
JAR=""

for J in "$JAR1" "$JAR2"
do
    # Expand
    J="$(echo $J)"
    if [ -e "$J" ]
    then
	JAR="$J"
	break
    fi
done

if [ "$JAR" = "" ]
then
    echo "Can't find jarfile to run"
    exit 1
fi

# Deal with Cygwin path issues
cygwin=false
case "`uname`" in
    CYGWIN*) cygwin=true;;
esac
if [ "$cygwin" = "true" ]
then
    JAR=`cygpath -w "$JAR"`
    FUSEKI_HOME=`cygpath -w "$FUSEKI_HOME"`
fi

export FUSEKI_BASE="${FUSEKI_BASE:-$PWD/run}"

JVM_ARGS=${JVM_ARGS:--Xmx1200M}

exec java  $JVM_ARGS -jar "$JAR" "$@"

## Adding custom code to the Fuseki server:
##
## It is also possible to launch Fuseki using 
##   java $JVM_ARGS -cp "$JAR" org.apache.jena.fuseki.cmd.FusekiCmd "$@"
##
## "exec" is optional - it simple frees up a OS process.
## In this way, you can add custom java to the classpath:
## 
##   APPJAR=MyCode.jar
##   java $JVM_ARGS -cp "$JAR:$APPJAR" org.apache.jena.fuseki.cmd.FusekiCmd "$@"





