DOMAIN=baba.yaga
DOMAIN1=www.baba.yaga
CLIENT=certbot

###-------------------------------------------------------------------------------------------------------------------------

mkdir /tmp/ca
wget -O "/tmp/ca/YggdrasilNetworkSphere_root.crt" https://[302:a2a5:dead:ded::a2a5]/YggdrasilNetworkSphere.crt --no-check-certificate

if [ $(whereis update-ca-certificates | wc -w) -gt 1 ]; then
		sudo mv "/tmp/ca/YggdrasilNetworkSphere_root.crt" "/usr/local/share/ca-certificates/YggdrasilNetworkSphere_root.crt"
		sudo update-ca-certificates
else
		sudo trust anchor "/tmp/ca/YggdrasilNetworkSphere_root.crt" -v
		sudo update-ca-trust extract
fi

if [ $CLIENT == "certbot" ]; then 
	if [ $(whereis apache2 | wc -w) -ge 3 ]; then
		sudo apt install certbot python3-certbot-nginx python3-certbot-apache
		sudo certbot -d $DOMAIN -d $DOMAIN1 --apache --server https://acme.yggnode.ygg/acme/acme/directory
	else
		sudo apt install certbot python3-certbot-nginx
		sudo certbot -d $DOMAIN -d $DOMAIN1 --nginx --server https://acme.yggnode.ygg/acme/acme/directory
	fi
else
	git clone https://github.com/acmesh-official/acme.sh /tmp/acme/
	if [ $(whereis apache2 | wc -w) -ge 3 ]; then
		/tmp/acme/acme.sh --issue -d $DOMAIN -d $DOMAIN1 --apache --server https://acme.yggnode.ygg/acme/acme/directory
	else
		/tmp/acme/acme.sh --issue -d $DOMAIN -d $DOMAIN1 --nginx --server https://acme.yggnode.ygg/acme/acme/directory
	fi
fi
