#!/usr/bin/env bash

# first install a require script
if ! [[ -x "$(command -v require.sh)" ]] ; then

	echo " we need sudo to install require.sh to /usr/local/bin "
	sudo wget -O /usr/local/bin/require.sh https://raw.githubusercontent.com/xriss/require.sh/main/require.sh
	sudo chmod +x /usr/local/bin/require.sh

fi


echo " installing dnsmasq and setting dportal.box to 10.42.52.99 "

# setup config files


# dnsmasq provides all subdomains

sudo tee /etc/dnsmasq.d/dportal <<- "EOF"

	server=8.8.8.8
	address=/dportal.box/10.42.52.99

EOF


# but dnsmasq does not provide the bare domain so we must also use /etc/hosts

sudo tee -a /etc/hosts <<- "EOF"

	10.42.52.99	dportal.box

EOF


# install here so it picks up the new config files written above

require.sh resolvconf
require.sh dnsmasq


# stop systemd from hogging port 53 with a service that does nothing

sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved


sudo service dnsmasq restart
