#! /bin/sh -e

# octobre  2022

# creates the router, and loads filter configuration
nft -f /etc/nftables.conf
# load tls domains
#cat ./tlsdomains | dd of=/proc/tlsdomains

/etc/idefix/rescue.bash
/etc/idefix/set-leds.bash

# set permissions and owners
/etc/idefix/set-permissions.bash

# set date - one of the two command will work, depending on the program installed
# The "|| true" in the end prevents the bash to stop if ntpdate returns an error,which happens if is is already a service
ntpdate 216.239.35.8  || true
htpdate 216.239.35.8  || true

# Informations
/usr/lib/idefix/idefix-post.py

#/usr/lib/idefix/admin/diagnostic.py all
#mkdir -p /home/rock64/idefix/logs
#DOW=$(date +%u)
#cp /home/rock64/idefix/result.zip /home/rock64/idefix/logs/${DOW}-diagnostic.zip

# TLS-SNI filter
echo "start TLS-SNI filter"
mkdir -p /mnt/tls
mount -t tmpfs -o size=100m tmpfs /mnt/tls
echo '{"127.0.0.1": ["*.sheltercom.net"]}' > "/mnt/tls/tls.json"
chown unbound:unbound "/mnt/tls/tls.json"
chmod 664 "/mnt/tls/tls.json"
insmod /usr/lib/idefix/tlsfilter/module/tlsfilter.ko  || true
systemctl start tls-sni.service
systemctl start tls-sni.path
systemctl status tls-sni.service
systemctl status tls-sni.path

echo "end of autoexec.bash"

