Explorar el Código

Bump version. Fix int. to acme-sh

Joachim M. Giæver hace 4 años
padre
commit
4fb7c2efbc
Se han modificado 4 ficheros con 20 adiciones y 20 borrados
  1. 14 12
      scripts/bin/certs-daemon
  2. 2 3
      scripts/config/init
  3. 0 4
      snap/hooks/disconnect-slot-certs
  4. 4 1
      snap/snapcraft.yaml

+ 14 - 12
scripts/bin/certs-daemon

@@ -12,14 +12,22 @@ if [ "${DOMAIN}" != "--not-set" ]; then
         exit 1
     fi
 
-    CERT_MATCH_NAME="${UUID}_${DOMAIN}"
+    readarray -d '' DOMAINS < <(find "${CERTS_DIR}" -type d -name "${DOMAIN}" -print0)
+    logger "Certificate (${DOMAIN}) available for ${SNAP_NAME}:${UUID}"
 
-    readarray -d '' CERTIFICATES < <(find ${CERTS_DIR} -type f -name "*${CERT_MATCH_NAME}*" -print0)
-    logger "`expr ${#CERTIFICATES[@]} / 4` available for ${CERT_MATCH_NAME}"
-
-    if [ "${#CERTIFICATES[@]}" -ne 0 ]; then
+    if [ "${#DOMAINS[@]}" -ne 0 ]; then
+        DOMAIN_DIR="${DOMAINS[0]}"
         gpg_start_agent
         i=0
+        LAST_EDITED=`stat "${DOMAIN_DIR}/.time" --format="%Y" 2> /dev/null || echo 0`
+        ORIG_EDITED=`stat "${SSL_DIR}/.time" --format="%Y" 2> /dev/null || echo 0`
+
+        if [ "${LAST_EDITED}" -le "${ORIG_EDITED}" ]; then 
+            logger "Certificate for ${DOMAIN} is not changed, exiting"
+            exit 1
+        fi
+
+        readarray -d '' CERTIFICATES < <(find "${DOMAIN_DIR}" -type f -name "*.gpg" -print0)
         for CERTIFICATE in "${CERTIFICATES[@]}"; do
             DEST="${SSL_DIR}/`basename "${CERTIFICATE}" ".gpg"`"
             ORIG=""
@@ -36,16 +44,10 @@ if [ "${DOMAIN}" != "--not-set" ]; then
             fi
         done
         if [ "${i}" -ne 0 ]; then
+            cp -f "${DOMAIN_DIR}/.time" "${SSL_DIR}/.time"
             logger "Certificates (${DOMAIN}) changed for ${SNAP_NAME}-${UUID}, restart"
             snapctl restart "${SNAP_NAME}.hass"
         fi
         gpg_close_agent
     fi
-else
-    readarray -d '' CERTIFICATES < <(find ${CERTS_DIR} -type f -name "*${UUID}*" -print0)
-
-    if [ "${#CERTIFICATES[@]}" -ne 0 ]; then
-        logger "> `expr ${#CERTIFICATES[@]} / 4` available for ${SNAP_NAME} (uuid: ${UUID})"
-        logger "> Consider setting your domain with 'sudo snap set ${SNAP_NAME} domain=\"domain.tld\"'"
-    fi
 fi

+ 2 - 3
scripts/config/init

@@ -26,10 +26,9 @@ function gpg_start_agent {
         gpg-agent --daemon 2> /dev/null
         if [ $? -eq 0 ]; then
             logger "GPG-agent started"
-            return 0
+        else
+            logger "Failed starting GPG-agent, trying anyway"
         fi
-        logger "Failed starting GPG-agent"
-        return 1
     fi
     return 0
 }

+ 0 - 4
snap/hooks/disconnect-slot-certs

@@ -3,9 +3,5 @@
 source "${SNAP}/init"
 logger "Disconnect ${SNAP_NAME}:certs (uuid: ${UUID})"
 
-logger "TODO: Remove certificate?"
-logger "TODO: Remove GPG-key?"
-logger "TODO: Restart HASS?"
-
 rm -rf "${SSL_DIR}"
 snapctl restart "${SNAP_NAME}.hass"

+ 4 - 1
snap/snapcraft.yaml

@@ -1,5 +1,5 @@
 name: home-assistant-snap
-version: '0.114.3'
+version: '0.114.4'
 summary: Open source home automation that puts local control and privacy first
 description: |
     Home Assistant is a home automation platform running on Python 3. 
@@ -58,6 +58,9 @@ apps:
     timer: 00:00-24:00/287
     slots:
       - certs
+    plugs:
+      - network
+      - network-bind
 
 hooks:
   prepare-slot-certs: