|
9 | 9 |
|
10 | 10 | DOMAIN_=mycloud.ownyourbits.com
|
11 | 11 | EMAIL_=mycloud@ownyourbits.com
|
| 12 | +NOTIFYUSER_=ncp |
12 | 13 |
|
13 | 14 | NCDIR=/var/www/nextcloud
|
14 | 15 | OCC="$NCDIR/occ"
|
@@ -53,32 +54,51 @@ configure()
|
53 | 54 | {
|
54 | 55 | local DOMAIN_LOWERCASE="${DOMAIN_,,}"
|
55 | 56 |
|
| 57 | + # Configure Apache |
56 | 58 | grep -q ServerName $VHOSTCFG && \
|
57 | 59 | sed -i "s|ServerName .*|ServerName $DOMAIN_|" $VHOSTCFG || \
|
58 | 60 | sed -i "/DocumentRoot/aServerName $DOMAIN_" $VHOSTCFG
|
59 | 61 |
|
| 62 | + # Do it |
60 | 63 | letsencrypt certonly -n --no-self-upgrade --webroot -w $NCDIR --hsts --agree-tos -m $EMAIL_ -d $DOMAIN_ && {
|
| 64 | + |
| 65 | + # Set up auto-renewal |
61 | 66 | cat > /etc/cron.weekly/letsencrypt-ncp <<EOF
|
62 | 67 | #!/bin/bash
|
63 |
| -/usr/bin/certbot renew --quiet |
| 68 | +
|
| 69 | +# renew and notify |
| 70 | +/usr/bin/certbot renew --quiet --renew-hook ' |
| 71 | + sudo -u www-data php $OCC notification:generate \ |
| 72 | + $NOTIFYUSER_ "SSL renewal" \ |
| 73 | + -l "Your SSL certificate(s) \$RENEWED_DOMAINS has been renewed for another 90 days" |
| 74 | + ' |
| 75 | +
|
| 76 | +# notify if fails |
| 77 | +[[ \$? -ne 0 ]] && sudo -u www-data php $OCC notification:generate \ |
| 78 | + $NOTIFYUSER_ "SSL renewal error" \ |
| 79 | + -l "SSL certificate renewal failed. See /var/log/letsencrypt/letsencrypt.log" |
| 80 | +
|
| 81 | +# cleanup |
64 | 82 | rm -rf $NCDIR/.well-known
|
65 | 83 | EOF
|
66 | 84 | chmod +x /etc/cron.weekly/letsencrypt-ncp
|
67 | 85 |
|
| 86 | + # Configure Apache |
68 | 87 | sed -i "s|SSLCertificateFile.*|SSLCertificateFile /etc/letsencrypt/live/$DOMAIN_LOWERCASE/fullchain.pem|" $VHOSTCFG
|
69 | 88 | sed -i "s|SSLCertificateKeyFile.*|SSLCertificateKeyFile /etc/letsencrypt/live/$DOMAIN_LOWERCASE/privkey.pem|" $VHOSTCFG
|
70 | 89 |
|
71 | 90 | sed -i "s|SSLCertificateFile.*|SSLCertificateFile /etc/letsencrypt/live/$DOMAIN_LOWERCASE/fullchain.pem|" $VHOSTCFG2
|
72 | 91 | sed -i "s|SSLCertificateKeyFile.*|SSLCertificateKeyFile /etc/letsencrypt/live/$DOMAIN_LOWERCASE/privkey.pem|" $VHOSTCFG2
|
73 | 92 |
|
| 93 | + # Configure Nextcloud |
74 | 94 | sudo -u www-data php $OCC config:system:set trusted_domains 4 --value=$DOMAIN_
|
75 | 95 | sudo -u www-data php $OCC config:system:set overwrite.cli.url --value=https://$DOMAIN_
|
76 | 96 |
|
77 | 97 | # delayed in bg so it does not kill the connection, and we get AJAX response
|
78 | 98 | bash -c "sleep 2 && service apache2 reload" &>/dev/null &
|
79 | 99 | rm -rf $NCDIR/.well-known
|
80 | 100 |
|
81 |
| - # update configuration |
| 101 | + # Update configuration |
82 | 102 | [[ "$DOCKERBUILD" == 1 ]] && update-rc.d letsencrypt enable
|
83 | 103 |
|
84 | 104 | return 0
|
|
0 commit comments