#!/bin/bash
#
# Aussom-Server CLI wrapper - generated by 'aussom-server -i'.
#
# Forwards every argument to the aussom-server JAR with the
# encryption key and lib classpath already wired up, so day-to-day
# admin and test commands stay short:
#
#   aussom-server -t  aussom-tests/my-tests.aus      run unit tests
#   aussom-server -ta aussom-tests/my-tests.aus      run all reachable @Test classes
#   aussom-server -t  my-tests.aus --tags fast       tag-filtered run
#   aussom-server -k                                 generate a fresh encryption key
#   aussom-server -e "secret string"                 encrypt a value with this server's key
#   aussom-server -v                                 print the version banner
#   aussom-server -h                                 full help
#
# To start the server itself, prefer ./start-server.sh - it pins the
# correct -cf / -ad pair for this install.
#
# Resolves all paths relative to its own location, so this script
# can be symlinked onto the PATH (e.g. /usr/local/bin/aussom-server)
# and still find the JAR and lib/.
set -eu

BASEDIR="$(cd "$(dirname "$0")" && pwd)"
cd "$BASEDIR"

# Generated at install time; matches the key in config.yaml.
KEY="__AUSSOM_KEY__"

# Absolute path to the aussom-server JAR that ran the install.
JAR="__AUSSOM_JAR__"

# Use -cp (not -jar) so any *.jar dropped into ./lib/ rides on the
# classpath alongside the fat JAR.
#
# -Djava.system.class.loader installs AussomServerClassLoader as
# the system class loader so app.loadJar can extend the classpath
# at runtime. The class ships in the fat JAR.
exec java -Djava.system.class.loader=com.lehman.aussomserver.AussomServerClassLoader \
          -Daussomserver.key="$KEY" \
          -cp "$JAR:$BASEDIR/lib/*" \
          com.lehman.aussomserver.Main "$@"
