#!/bin/bash

set -eux

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

#
# firefox
cp $DIR/neko.js /usr/lib/firefox-esr/mozilla.cfg
#rm -f /usr/lib/firefox-esr/mozilla.cfg

cp $DIR/autoconfig.js /usr/lib/firefox-esr/defaults/pref/autoconfig.js
#rm -f /usr/lib/firefox-esr/defaults/pref/autoconfig.js

#https://github.com/mozilla/policy-templates
cp $DIR/policies.json /usr/lib/firefox-esr/distribution/policies.json
#rm -f /usr/lib/firefox-esr/distribution/policies.json

cp $DIR/supervisord.conf /etc/neko/supervisord/firefox.conf
#rm -f /etc/neko/supervisord/firefox.conf

#
# install extensions
mkdir -p /usr/lib/firefox/distribution/extensions

#
# uBlock
if [ ! -f /usr/lib/firefox/distribution/extensions/uBlock0@raymondhill.net.xpi ]; then
  wget -O /usr/lib/firefox/distribution/extensions/uBlock0@raymondhill.net.xpi https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/addon-607454-latest.xpi
fi

#
# nordvpnproxy
if [ ! -f /usr/lib/firefox/distribution/extensions/nordvpnproxy@nordvpn.com.xpi ]; then
  wget -O /usr/lib/firefox/distribution/extensions/nordvpnproxy@nordvpn.com.xpi https://addons.mozilla.org/firefox/downloads/latest/nordvpn-proxy-extension/latest.xpi
fi

#
# clean up old sessions
rm -rf /home/$USER/.mozilla