#!/bin/sh -

OPENNMS_HOME="/usr/share/opennms"
OPENNMS_BINDIR="/usr/share/opennms/bin"

RUNAS="root"

ULIMIT=`which ulimit 2>/dev/null`
if [ -n $ULIMIT ]; then
	for SIZE in 1024 2048 4096 8192 unlimited; do
		ulimit -n "$SIZE" >/dev/null 2>&1
		if [ $? -gt 0 ]; then
			break
		fi
	done
fi

myuser="`id | sed -e 's/uid=[0-9][0-9]*(//' -e 's/).*//'`"
if [ x"$myuser" = x"$RUNAS" ]; then
	true # all is well
else
	echo "Error: you must run this script as $RUNAS, not '$myuser'" >&2
	exit 4 # According to LSB: 4 - user had insufficient privileges
fi

if [ -f "$OPENNMS_HOME/etc/opennms.conf" ]; then
	. "$OPENNMS_HOME/etc/opennms.conf"
fi

exec "$OPENNMS_BINDIR"/runjava -r -- \
	$ADDITIONAL_MANAGER_OPTIONS \
	-Dopennms.home="$OPENNMS_HOME" \
	-Dlog4j.configurationFile="$OPENNMS_HOME"/etc/log4j2-tools.xml \
	-cp "$OPENNMS_HOME/lib/opennms_bootstrap.jar" \
	org.opennms.bootstrap.InstallerBootstrap \
	"$@"
