#!/bin/sh
INSTDIR="$1"

if [ -f /mnt/config/usercmd.sh ]; then
	sed -i "/^exit/i$INSTDIR/bin/e2webserv -b -c /mnt/config/e2webserv.conf" /mnt/config/usercmd.sh
fi

if [ ! -e /mnt/config/e2webserv.conf ]; then
	echo "use TPK config file"
	mv /mnt/config/e2webserv.conf.e2 /mnt/config/e2webserv.conf
	chmod -x /mnt/config/e2webserv.conf
else
	echo "found user config file"
	echo "skip TPK config file: e2webserv.conf.e2"
fi

echo "start e2webserv..."
$INSTDIR/e2webserv -b -c /mnt/config/e2webserv.conf > /dev/null 2>&1
echo "done."

exit 0