update recert (make it acutaly work)
This commit is contained in:
parent
1d5a5dc1a2
commit
ed35463a36
1 changed files with 41 additions and 10 deletions
51
recert
Executable file → Normal file
51
recert
Executable file → Normal file
|
@ -7,6 +7,10 @@ cert='cert.pem' # where the public cert should go
|
||||||
key='cert.key' # where the private cert should go
|
key='cert.key' # where the private cert should go
|
||||||
domain='localhost' # the domain to copy certs from
|
domain='localhost' # the domain to copy certs from
|
||||||
|
|
||||||
|
email="freya@freyacat.org"
|
||||||
|
|
||||||
|
status=0
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf "usage: recert [-hsfq] [-d DOMAIN] [-c CERT] [-k KEY]\n\n"
|
printf "usage: recert [-hsfq] [-d DOMAIN] [-c CERT] [-k KEY]\n\n"
|
||||||
printf "\t-h\t\tshow the help message\n"
|
printf "\t-h\t\tshow the help message\n"
|
||||||
|
@ -25,11 +29,18 @@ hash() {
|
||||||
}
|
}
|
||||||
|
|
||||||
letscert() {
|
letscert() {
|
||||||
|
args=(--non-interactive --agree-tos --no-eff-email --email "$email")
|
||||||
|
certbot delete \
|
||||||
|
$args \
|
||||||
|
--cert-name "$domain"
|
||||||
certbot certonly \
|
certbot certonly \
|
||||||
|
$args \
|
||||||
--preferred-chain "ISRG Root X1" \
|
--preferred-chain "ISRG Root X1" \
|
||||||
--key-type rsa \
|
--key-type rsa \
|
||||||
--webroot --webroot-path "/var/www/html" \
|
--webroot \
|
||||||
-d "$1"
|
--webroot-path "/var/www/html" \
|
||||||
|
--domains "$1"
|
||||||
|
status=1
|
||||||
}
|
}
|
||||||
|
|
||||||
recert_log() {
|
recert_log() {
|
||||||
|
@ -101,8 +112,6 @@ if openssl x509 -checkend 604800 -noout -in "$lets_cert" > /dev/null; then
|
||||||
rmdir "$lets_root"
|
rmdir "$lets_root"
|
||||||
recert_log "renewing... "
|
recert_log "renewing... "
|
||||||
letscert "$domain"
|
letscert "$domain"
|
||||||
else
|
|
||||||
recert_log "up to date... "
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
recert_log "renewing... "
|
recert_log "renewing... "
|
||||||
|
@ -119,14 +128,36 @@ if [ $single = 1 ]; then
|
||||||
} >> "$tmp"
|
} >> "$tmp"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Step 4: copy certs
|
# Setup 4: get hashes
|
||||||
recert_log "copied certs\n"
|
current_hash=""
|
||||||
if [ $single = 1 ]; then
|
if [ -f "$cert" ]; then
|
||||||
cp "$tmp" "$cert"
|
current_hash=$(md5sum "$lets_cert" | cut -f 1 -d " ")
|
||||||
else
|
else
|
||||||
cp "$lets_cert" "$cert"
|
current_hash="FORCE"
|
||||||
cp "$lets_key" "$key"
|
fi
|
||||||
|
|
||||||
|
new_hash=""
|
||||||
|
if [ $single = 1 ]; then
|
||||||
|
new_hash=$(md5sum "$tmp" | cut -f 1 -d " ")
|
||||||
|
else
|
||||||
|
new_hash=$(md5sum "$lets_cert" | cut -f 1 -d " ")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Step 5: copy if hases out of date
|
||||||
|
if [ "$current_hash" != "$new_hash" ]; then
|
||||||
|
recert_log "copied certs\n"
|
||||||
|
if [ $single = 1 ]; then
|
||||||
|
cp "$tmp" "$cert"
|
||||||
|
else
|
||||||
|
cp "$lets_cert" "$cert"
|
||||||
|
cp "$lets_key" "$key"
|
||||||
|
fi
|
||||||
|
status=1
|
||||||
|
else
|
||||||
|
recert_log "up to date\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
rm "$tmp"
|
rm "$tmp"
|
||||||
|
|
||||||
|
exit "$status"
|
||||||
|
|
Loading…
Reference in a new issue