#!/bin/sh
cd /mnt/us/extensions/hercules/

# Since we have an httproot config that won't play ball. Let's loopmount this puppy


if [ ! -d "/usr/share/hercules" ]; then
# Lets make a mount point that is sensible.
mntroot rw
sleep 1
mkdir /usr/share/hercules
mntroot ro
fi

#LAZY! (let's hide the error this time round)
umount /usr/share/hercules 2>/dev/null

#bind it
mount -o bind,ro /mnt/us/extensions/hercules/share/hercules /usr/share/hercules

#punch a hole for the HTTP, it will die on the next reboot anywho
#these do stack up but meh. live with it.
iptables -I INPUT -p tcp --dport 8081 -j ACCEPT

# Aaand let the external consoles connect.
iptables -I INPUT -p tcp --dport 3270 -j ACCEPT
iptables -I INPUT -p tcp --dport 3990 -j ACCEPT


cd /mnt/us/extensions/hercules/; LD_LIBRARY_PATH=/mnt/us/extensions/hercules/lib/hercules:$LD_LIBRARY_PATH /mnt/us/extensions/hercules/bin/hercules -f /mnt/us/extensions/hercules/hercules.cnf &
eips 2 38 "Booting server in background. Wait 5 secs."

sleep 5

#now run it.
/mnt/us/extensions/kterm/bin/kterm -e /mnt/us/extensions/hercules/bin/client.sh

eips 2 38 "Killing server in background."
sleep 5

/mnt/us/extensions/hercules/bin/stop.sh &

# Okay someone killed the process: let's tidy up

#LAZY!!!!!!!!!!!!!!!!!
umount /usr/share/hercules

# We are done here
