#!/bin/sh
# name:        postinst
# description: Configure package after installation
# os:          La Fonera
# contact:     support@neorouter.com 

NEOROUTERROOT=/usr/local/ZebraNetworkSystems/NeoRouter/

if [ -f /tmp/libuClibc++.tgz ]; then
  tar zxvf /tmp/libuClibc++.tgz -C /
  ln -s /usr/lib/libuClibc++-0.2.2.so /usr/lib/libuClibc++.so.0
  rm /tmp/libuClibc++.tgz
fi

# generate SSL key
cd $NEOROUTERROOT
if [ -f /tmp/openssl ]; then
  /tmp/openssl req -new -newkey rsa:1024 -days 3650 -nodes -x509 -keyout server.key -out server.crt -config openssl.cnf
else
  /usr/bin/openssl req -new -newkey rsa:1024 -days 3650 -nodes -x509 -keyout server.key -out server.crt -config openssl.cnf
fi

# install init script
/etc/init.d/nrserver.sh enable

# add crash recovery cron
/etc/init.d/fonstate stop
/usr/bin/cru "30" "/usr/bin/nrcron"
/etc/init.d/fonstate start

# set firewall
echo "/usr/sbin/iptables -A input_daemon -p tcp --dport  32976 -j zone_wan_ACCEPT">>/etc/firewall.fon
/etc/init.d/firewall restart

# start server
/etc/init.d/nrserver.sh start
