summaryrefslogtreecommitdiff
path: root/security/lego/files/deploy.sh.sample.in
blob: ceddaacab5dafa2301ebf722d5646c82ae14dcca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh -e

SSLDIR="%%PREFIX%%/etc/ssl"

copy_certs () {
  local certdir certfile domain keyfile rc
  rc=1

  certdir="${SSLDIR}/lego/certificates"
  certfiles="$(find "${certdir}" -name "*.crt" -not -name "*.issuer.crt")"
  for certfile in $certfiles
  do
    domain="$(basename "$certfile" .crt)"
    keyfile="$(dirname "$certfile")/${domain}.key"

    if ! cmp -s "${certfile}" "${SSLDIR}/certs/${domain}.crt"
    then
      cp "${certfile}" "${SSLDIR}/certs/${domain}.crt"
      cp "${keyfile}" "${SSLDIR}/private/${domain}.key"
      rc=0
    fi
  done

  return $rc
}

if copy_certs
then
  output=$(service nginx reload 2>&1) || (echo "$output" && exit 1)
fi