#!/bin/bash
##################################
########### POSTINST #############
##################################

/usr/local/bin/lokinet -g /root/.lokinet/lokinet.ini
cp /usr/contrib/bootstrap.signed /root/.lokinet/bootstrap.signed
/etc/init.d/lokinet enable
/etc/init.d/lokinet start

#check for firewall.user iptables entry

if grep -q "iptables -t nat -A POSTROUTING -j MASQUERADE" /etc/firewall.user; then
	echo "firewall.user already has iptables requirements"
else
	echo "iptables -t nat -A POSTROUTING -j MASQUERADE" | tee -a /etc/firewall.user >/dev/null
	echo "added iptables rule to firewall.user"
fi

#lokinet
uci set lokinet.@Address[0]=Address
uci set lokinet.@Address[0].Addr='null'
uci set lokinet.Key=Key
uci set lokinet.Key.Key='null'
uci set lokinet.Enable=Enabled
uci set lokinet.Enable.Enabled='0'
uci commit lokinet
#dnsmasq settings
uci set dhcp.@dnsmasq[0]=dnsmasq
uci set dhcp.@dnsmasq[0].localise_queries='1'
uci set dhcp.@dnsmasq[0].local='/lan/'
uci set dhcp.@dnsmasq[0].domain='lan'
uci set dhcp.@dnsmasq[0].expandhosts='1'
uci set dhcp.@dnsmasq[0].authoritative='1'
uci set dhcp.@dnsmasq[0].readethers='1'
uci set dhcp.@dnsmasq[0].leasefile='/tmp/dhcp.leases'
uci set dhcp.@dnsmasq[0].resolvfile='/tmp/resolv.conf.d/resolv.conf.auto'
uci set dhcp.@dnsmasq[0].ednspacket_max='1232'
uci set dhcp.@dnsmasq[0].rebind_protection='0'
uci set dhcp.@dnsmasq[0].domainneeded='1'
uci set dhcp.@dnsmasq[0].boguspriv='0'
uci set dhcp.@dnsmasq[0].dnsseccheckunsigned='0'
uci set dhcp.@dnsmasq[0].localservice='1'
uci set dhcp.@dnsmasq[0].dnssec='1'
uci set dhcp.@dnsmasq[0].nohosts='1'
uci set dhcp.@dnsmasq[0].nonegcache='1'
uci set dhcp.@dnsmasq[0].server='/loki/127.3.2.1'
uci add_list dhcp.@dnsmasq[0].server='127.3.2.1'
uci set dhcp.@dnsmasq[0].notinterface='eth0'
uci delete dhcp.@dnsmasq[0].nonwildcard='0'
uci delete dhcp.@dnsmasq[0].allservers='1'
uci delete dhcp.@dnsmasq[0].boguspriv='0'
uci commit dhcp
#firewall
uci set firewall.@defaults[0]=defaults
uci set firewall.@defaults[0].input='ACCEPT'
uci set firewall.@defaults[0].output='ACCEPT'
uci set firewall.@defaults[0].synflood_protect='1'
uci set firewall.@defaults[0].forward='ACCEPT'
uci set firewall.@include[0]=include
uci set firewall.@include[0].path='/etc/firewall.user'
uci set firewall.@zone[0]=zone
uci set firewall.@zone[0].name='wan'
uci set firewall.@zone[0].output='ACCEPT'
uci set firewall.@zone[0].forward='REJECT'
uci set firewall.@zone[0].masq='1'
uci set firewall.@zone[0].network='wan'
uci set firewall.@zone[0].input='REJECT'
uci set firewall.@zone[1]=zone
uci set firewall.@zone[1].name='lan'
uci set firewall.@zone[1].input='ACCEPT'
uci set firewall.@zone[1].output='ACCEPT'
uci set firewall.@zone[1].forward='ACCEPT'
uci set firewall.@zone[1].network='lan'
uci commit firewall
reload_config
/etc/init.d/firewall restart
