read -p "Hostnames: " HOSTS

if [ "$EUID" -ne 0 ]; then
	echo "Must be ran as root!"
	exit 1
fi

if [ ! -f mkdocs.yml ]; then
	echo "Must be ran from the project root!"
	exit 1
fi

if [ ! -f ~/.ssh/mhwiki ]; then
	ssh-keygen -t ed25519 -q -N "" -f ~/.ssh/mhwiki
fi

echo "Deploy Key: $(cat ~/.ssh/mhwiki.pub)"

pip install mkdocs-material mkdocs-macros-plugin mkdocs-awesome-pages-plugin

cp setup/nginx.conf /etc/nginx/sites-enabled/mhwiki.conf
sed -i "s~%ROOT%~$PWD/site~" /etc/nginx/sites-enabled/mhwiki.conf
sed -i "s~%HOSTS%~$HOSTS~" /etc/nginx/sites-enabled/mhwiki.conf

nginx -t && nginx -s reload
