50 lines
852 B
Bash
50 lines
852 B
Bash
#!/usr/bin/bash
|
|
|
|
if [ ! -f "/etc/ddns-acme-porkbun.env" ]; then
|
|
echo "Porkbun API key .env missing"
|
|
exit 1
|
|
fi
|
|
DOMAINS=("272254864.xyz" "*.272254864.xyz")
|
|
set -a; source /etc/ddns-acme-porkbun.env; set +a
|
|
|
|
if [ -z "$EMAIL" ] || [ -z "$DOMAINS" ] || [ -z "$PORKBUN_SECRET_API_KEY" ] || [ -z "$PORKBUN_API_KEY" ]; then
|
|
echo "Bad .env file"
|
|
exit 1
|
|
fi
|
|
|
|
ddns_update() {
|
|
while true;
|
|
do
|
|
ddns-porkbun
|
|
case "#?" in
|
|
"1")
|
|
echo "Fatal error"
|
|
exit 1
|
|
;;
|
|
"2")
|
|
echo "Retry in 5 min"
|
|
sleep 300
|
|
echo "Retrying"
|
|
;;
|
|
"0")
|
|
echo "DNS updated"
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
ddns_update
|
|
if [ "#?" -eq "1" ]; then
|
|
echo "DDNS script failed, check credentials/domain"
|
|
fi
|
|
|
|
if [ "$1" = "renew" ]; then
|
|
LEGO_ARG="renew"
|
|
else
|
|
LEGO_ARG="run"
|
|
fi
|
|
|
|
|
|
cd /etc/nginx
|
|
lego --email "$EMAIL" --dns porkbun "${DOMAINS[@]/#/-d }" $LEGO_ARG
|