Bug 15303 Followup for koha-remove
authorMirko Tietgen <mirko@abunchofthings.net>
Fri, 15 Apr 2016 11:35:16 +0000 (13:35 +0200)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 29 Apr 2016 13:04:31 +0000 (13:04 +0000)
This patch makes koha-remove take care of

/etc/letsencrypt/renewal/$opacdomain.conf
/var/lib/koha/$site/letsencrypt.enabled

It also adds a few helper functions.

To test
- create a koha instance with LE
- observe you got both files mentioned above
- remove that instance
- verify the files are gone

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
debian/scripts/koha-create
debian/scripts/koha-functions.sh
debian/scripts/koha-remove

index 4484910..263ee14 100755 (executable)
@@ -361,7 +361,7 @@ letsencrypt_instance()
     # enable redirect from http to https on port 80
     sed -i "s:^\s*#\(.*\)#nohttps$:\1:" "/etc/apache2/sites-available/$name.conf"
     # make koha-list --letsencrypt aware of this instance # could be done by checking apache conf instead
-    touch /var/lib/koha/$name/letsencrypt.enabled
+    echo -e "opacdomain=\"$opacdomain\"\nintradomain=\"$intradomain\"" > /var/lib/koha/$name/letsencrypt.enabled
     # restart apache with working certs
     service apache2 restart
 }
index ef71a3a..1c309fc 100755 (executable)
@@ -43,6 +43,46 @@ get_apache_config_for()
     fi
 }
 
+get_opacdomain_for()
+{
+    local site=$1
+
+    if [ -e /etc/koha/koha-sites.conf ]; then
+        . /etc/koha/koha-sites.conf
+    else
+        echo "Error: /etc/koha/koha-sites.conf not present." 1>&2
+        exit 1
+    fi
+    local opacdomain="$OPACPREFIX$site$OPACSUFFIX$DOMAIN"
+    echo "$opacdomain"
+}
+
+get_intradomain_for()
+{
+    local site=$1
+
+    if [ -e /etc/koha/koha-sites.conf ]; then
+        . /etc/koha/koha-sites.conf
+    else
+        echo "Error: /etc/koha/koha-sites.conf not present." 1>&2
+        exit 1
+    fi
+    local intradomain="$INTRAPREFIX$site$INTRASUFFIX$DOMAIN"
+    echo "$intradomain"
+}
+
+letsencrypt_get_opacdomain_for()
+{
+    local site=$1
+
+    if [ -e /var/lib/koha/$site/letsencrypt.enabled ]; then
+        . /var/lib/koha/$site/letsencrypt.enabled
+    else
+        local opacdomain=$(get_opacdomain_for $site)
+    fi
+    echo "$opacdomain"
+}
+
 is_enabled()
 {
     local site=$1
index 88392ba..4342c5d 100755 (executable)
@@ -80,6 +80,7 @@ eof
     koha-stop-zebra $name || /bin/true
 
     instancefile=$(get_apache_config_for $name)
+    le_opacdomain=$(letsencrypt_get_opacdomain_for $name)
 
     [ -f "$instancefile" ]  && \
         rm "$instancefile"
@@ -97,6 +98,10 @@ eof
         rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
     [ -f "/etc/koha/sites/$name/zebra.passwd" ] && \
         rm "/etc/koha/sites/$name/zebra.passwd"
+    [ -f "/var/lib/koha/$name/letsencrypt.enabled" ] && \
+        rm -r "/var/lib/koha/$name/letsencrypt.enabled"
+    [ -f "/etc/letsencrypt/renewal/$le_opacdomain.conf" ] && \
+        rm -r "/etc/letsencrypt/renewal/$le_opacdomain.conf"
     # Maybe a user has left something in the config directory they want to keep? We won't delete it here, nor throw an error if the have.
     [ -d "/etc/koha/sites/$name" ] && \
         rmdir --ignore-fail-on-non-empty "/etc/koha/sites/$name"