From b3c7d1375e57b6476c68976b4b5dab2d4422582d Mon Sep 17 00:00:00 2001
From: nachoparker <nacho@ownyourbits.com>
Date: Sun, 28 Apr 2019 17:33:05 -0600
Subject: [PATCH] letsencrypt: switch to apt version

---
 bin/ncp/NETWORKING/letsencrypt.sh   | 13 ++++---------
 changelog.md                        |  8 ++++++--
 docker-armhf/nextcloudpi/Dockerfile | 26 --------------------------
 docker/nextcloudpi/Dockerfile       | 26 --------------------------
 update.sh                           |  3 +++
 5 files changed, 13 insertions(+), 63 deletions(-)

diff --git a/bin/ncp/NETWORKING/letsencrypt.sh b/bin/ncp/NETWORKING/letsencrypt.sh
index 686df42c3..180692a56 100644
--- a/bin/ncp/NETWORKING/letsencrypt.sh
+++ b/bin/ncp/NETWORKING/letsencrypt.sh
@@ -11,7 +11,7 @@
 ncdir=/var/www/nextcloud
 vhostcfg=/etc/apache2/sites-available/nextcloud.conf
 vhostcfg2=/etc/apache2/sites-available/ncp.conf
-letsencrypt=/etc/letsencrypt/letsencrypt-auto
+letsencrypt=/usr/bin/letsencrypt
 
 is_active()
 {
@@ -22,13 +22,8 @@ install()
 {
   cd /etc || return 1
   apt-get update
-  apt-get install --no-install-recommends -y python3-minimal
-  wget -O- --content-disposition https://github.com/letsencrypt/letsencrypt/archive/master/latest.tar.gz \
-  | tar -xz \
-  || exit 1
-  mv certbot-master letsencrypt
-  export VIRTUALENV_NO_DOWNLOAD=1          # temporal workaround for https://github.com/certbot/certbot/issues/6682
-  $letsencrypt --help                      # do not actually run certbot, only install packages
+  apt-get install --no-install-recommends -y letsencrypt
+  rm -f /etc/cron.d/certbot
   mkdir -p /etc/letsencrypt/live
 
   [[ "$DOCKERBUILD" == 1 ]] && {
@@ -46,7 +41,7 @@ EOF
   return 0
 }
 
-# tested with certbot 0.30.0
+# tested with certbot 0.28.0
 configure() 
 {
   local DOMAIN_LOWERCASE="${DOMAIN,,}"
diff --git a/changelog.md b/changelog.md
index 30e277b02..5eb767398 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,7 +1,11 @@
 
-[v1.11.2](https://github.com/nextcloud/nextcloudpi/commit/25ceed5) (2019-04-06) armbian: fix uu
+[v1.11.4](https://github.com/nextcloud/nextcloudpi/commit/62a7f45) (2019-04-28) letsencrypt: switch to apt version
 
-[v1.11.1](https://github.com/nextcloud/nextcloudpi/commit/a712935) (2019-04-05) nc-backup: fix space calculation
+[v1.11.3 ](https://github.com/nextcloud/nextcloudpi/commit/71d8f52) (2019-04-09) nc-restore: check btrfs command
+
+[v1.11.2, master](https://github.com/nextcloud/nextcloudpi/commit/3754609) (2019-04-06) armbian: fix uu
+
+[v1.11.1 ](https://github.com/nextcloud/nextcloudpi/commit/a712935) (2019-04-05) nc-backup: fix space calculation
 
 [v1.11.0 ](https://github.com/nextcloud/nextcloudpi/commit/5dedeaf) (2019-04-05) upgrade to NC15.0.6
 
diff --git a/docker-armhf/nextcloudpi/Dockerfile b/docker-armhf/nextcloudpi/Dockerfile
index cf36c9183..f2da9f88d 100644
--- a/docker-armhf/nextcloudpi/Dockerfile
+++ b/docker-armhf/nextcloudpi/Dockerfile
@@ -46,32 +46,6 @@ rm /.ncp-image; \
 source /usr/local/etc/library.sh; \
 find /usr/local/bin/ncp -name '*.sh' | while read l; do cleanup_script $l; done; \
 
-# letsencrypt build artifacts cleanup
-apt-get purge -y \
-  make \
-  binutils \
-  cpp \
-  cpp-6 \
-  gcc \
-  gcc-6 \
-  libasan3 \
-  libaugeas0 \
-  libc-dev-bin \
-  libc6-dev \
-  libcc1-0 \
-  libexpat1-dev \
-  libffi-dev \
-  libgcc-6-dev \
-  libisl15 \
-  libmpc3 \
-  libubsan0 \
-  linux-libc-dev \
-  python-virtualenv \
-  python-pkg-resources \
-  python3-pkg-resources \
-  python3-virtualenv \
-  virtualenv; \
-
 # should be cleaned up in no-ip.sh, but breaks udiskie.
 # safe to do it here since no automount in docker
 apt-get purge -y make gcc libc-dev; \
diff --git a/docker/nextcloudpi/Dockerfile b/docker/nextcloudpi/Dockerfile
index cbf76f861..2cfdc4e19 100644
--- a/docker/nextcloudpi/Dockerfile
+++ b/docker/nextcloudpi/Dockerfile
@@ -46,32 +46,6 @@ rm /.ncp-image; \
 source /usr/local/etc/library.sh; \
 find /usr/local/bin/ncp -name '*.sh' | while read l; do cleanup_script $l; done; \
 
-# letsencrypt build artifacts cleanup
-apt-get purge -y \
-  make \
-  binutils \
-  cpp \
-  cpp-6 \
-  gcc \
-  gcc-6 \
-  libasan3 \
-  libaugeas0 \
-  libc-dev-bin \
-  libc6-dev \
-  libcc1-0 \
-  libexpat1-dev \
-  libffi-dev \
-  libgcc-6-dev \
-  libisl15 \
-  libmpc3 \
-  libubsan0 \
-  linux-libc-dev \
-  python-virtualenv \
-  python-pkg-resources \
-  python3-pkg-resources \
-  python3-virtualenv \
-  virtualenv; \
-
 # should be cleaned up in no-ip.sh, but breaks udiskie.
 # safe to do it here since no automount in docker
 apt-get purge -y make gcc libc-dev; \
diff --git a/update.sh b/update.sh
index 3ef4bf599..4921e6755 100755
--- a/update.sh
+++ b/update.sh
@@ -184,6 +184,9 @@ EOF
   # armbian fix uu
   rm -f /etc/apt/apt.conf.d/02-armbian-periodic
 
+  # switch back to the apt LE version
+  which letsencrypt &>/dev/null || install_app letsencrypt
+
   # remove redundant opcache configuration. Leave until update bug is fixed -> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=815968
   # Bug #416 reappeared after we moved to php7.2 and debian buster packages. (keep last)
   [[ "$( ls -l /etc/php/7.2/fpm/conf.d/*-opcache.ini |  wc -l )" -gt 1 ]] && rm "$( ls /etc/php/7.2/fpm/conf.d/*-opcache.ini | tail -1 )"