#!/bin/sh
[ "${IPKG_INSTROOT}" != "" ] && exit 0
mkdir -p /etc/lasersharp
if [ ! -s /etc/lasersharp/pairing_code ]; then
    CODE=$(awk 'BEGIN{srand(); printf "%06d", int(100000 + rand() * 900000)}')
    echo -n "$CODE" > /etc/lasersharp/pairing_code
fi
: > /tmp/lasersharp_gateway.log
chmod +x /usr/bin/lasersharp-gateway
chmod +x /usr/bin/lasersharp-gateway.py
chmod +x /etc/init.d/lasersharp-gateway
killall -9 lasersharp-gateway.py >/dev/null 2>&1 || true
/etc/init.d/lasersharp-gateway enable >/dev/null 2>&1
/etc/init.d/lasersharp-gateway restart >/dev/null 2>&1
rm -rf /tmp/luci-indexcache* /tmp/luci-modulecache/* >/dev/null 2>&1
/etc/init.d/rpcd reload >/dev/null 2>&1 || true
exit 0
