#! /bin/sh -e

# source configuration file with defaults
if [ -f /etc/default/interchange ]; then
	. /etc/default/interchange
fi

. /etc/interchange/init.cfg
OPTS="SocketFile=/var/run/interchange/interchange.sock IPCsocket=/var/run/interchange/interchange.sock.ipc PIDfile=/var/run/interchange/interchange.pid --pidfile=/var/run/interchange/interchange.pid --log=/var/log/interchange/error.log --rundir=/var/run/interchange"
CMD="env MINIVEND_STORABLE=$USE_STORABLE MINIVEND_FORCE_THREADS=1 /usr/lib/interchange/bin/interchange $OPTS $@"
if [ "`/usr/bin/id -ru`" -eq 0 ]; then
	su -s /bin/sh -c "$CMD" $USER
else
	$CMD
fi
