Skip to content

Instantly share code, notes, and snippets.

@masuidrive
Last active October 8, 2019 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masuidrive/68ef9e612003fe33a23742679ea50794 to your computer and use it in GitHub Desktop.
Save masuidrive/68ef9e612003fe33a23742679ea50794 to your computer and use it in GitHub Desktop.
mydnsのLet's Encryptを設定するスクリプト
#!/bin/bash
# Usage:
# GROUP=1003 MYDNSJP_DOMAIN=XXXX.mydns.jp MYDNSJP_MASTERID=mydnsXXXXX MYDNSJP_MASTERPWD=XXXX EMAIL=mydns@example.com sh set_mydns_and_ssl.sh
apt install -y php php-mbstring certbot unzip
mkdir -p /usr/local/mydns
cd /usr/local/mydns
wget 'https://github.com/disco-v8/DirectEdit/archive/master.zip' -O DirectEdit-master.zip
unzip -f ./DirectEdit-master.zip
cd DirectEdit-master
cat << EOT > txtedit.conf
<?php
\$MYDNSJP_URL = 'https://www.mydns.jp/directedit.html';
\$MYDNSJP_MASTERID = '$MYDNSJP_MASTERID';
\$MYDNSJP_MASTERPWD = '$MYDNSJP_MASTERPWD';
\$MYDNSJP_DOMAIN = '$MYDNSJP_DOMAIN';
?>
EOT
chmod 700 ./*.php
chmod 600 ./*.conf
certbot certonly --manual \
--preferred-challenges=dns \
--manual-auth-hook /usr/local/mydns/DirectEdit-master/txtregist.php \
--manual-cleanup-hook /usr/local/mydns/DirectEdit-master/txtdelete.php \
-d $MYDNSJP_DOMAIN -d *.$MYDNSJP_DOMAIN \
--server https://acme-v02.api.letsencrypt.org/directory \
--agree-tos -m $EMAIL \
--manual-public-ip-logging-ok
chown -R root:$GROUP /etc/letsencrypt/{live,archive}
chmod 770 /etc/letsencrypt/{live,archive}
cat << EOT > /etc/cron.weekly/certbot
#!/bin/sh
certbot renew
systemctl restart code-server.service
EOT
chmod a+x /etc/cron.weekly/certbot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment