]> git.street.me.uk Git - andy/dehydrated.git/blobdiff - import-certs.sh
moved _openssl helper a bit up to be near the other helper methods
[andy/dehydrated.git] / import-certs.sh
index a9cfa203fe509d12dd05f4b32c0731b3a237eec8..133f0af3fe3b25643f46b3eb5bcd0d1e011cc20d 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 set -e
 set -u
@@ -10,8 +10,12 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 BASEDIR="${SCRIPTDIR}"
 LETSENCRYPT="/etc/letsencrypt"
 
-# shellcheck disable=SC1090
-. "${SCRIPTDIR}/config.sh"
+eval "$("${SCRIPTDIR}/letsencrypt.sh" --env)"
+
+if [[ ! -e "${LETSENCRYPT}" ]]; then
+  echo "No existing letsencrypt files found."
+  exit 1
+fi
 
 if [[ -e "${BASEDIR}/domains.txt" ]]; then
   DOMAINS_TXT="${BASEDIR}/domains.txt"
@@ -48,8 +52,7 @@ for certdir in "${LETSENCRYPT}/live/"*; do
   fi
 
   # Check if certificate still valid
-  set +e; openssl x509 -checkend 0 -noout -in "${certdir}/cert.pem" > /dev/null 2> /dev/null; expired="${?}"; set -e
-  if [[ "${expired}" = "1" ]]; then
+  if ! openssl x509 -checkend 0 -noout -in "${certdir}/cert.pem" >/dev/null 2>&1; then
     echo " + Skipping: Certificate is expired."
     continue
   fi