2016-05-27 10:26:08 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-08-31 02:42:43 +00:00
|
|
|
source lib/util
|
2016-05-27 10:26:08 +00:00
|
|
|
|
2016-05-30 23:48:21 +00:00
|
|
|
usage() {
|
|
|
|
while read -r line; do printf '%s\n' "$line"; done <<- EOF
|
|
|
|
Usage: le [options] <-d domain> [-d domain] ...
|
|
|
|
Options:
|
|
|
|
-c <dir> # Configuration directory. Default: \$HOME/.acme
|
|
|
|
-t <sec> # How many seconds till exipration to consider as soon. Default: 259200 (3 days)
|
|
|
|
# Can be specified multiple time for multi-domain certs.
|
|
|
|
-h # Show this message.
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2016-05-27 10:26:08 +00:00
|
|
|
main() {
|
|
|
|
declare cfg_dir
|
|
|
|
declare -a domains le_args
|
|
|
|
|
|
|
|
while (( $# )); do
|
|
|
|
case $1 in
|
|
|
|
-c)
|
|
|
|
cfg_dir=$2
|
|
|
|
shift;;
|
|
|
|
|
|
|
|
-t)
|
|
|
|
checkend_seconds=$2
|
|
|
|
shift;;
|
|
|
|
|
2016-05-30 23:48:21 +00:00
|
|
|
-h)
|
|
|
|
usage
|
|
|
|
return 0;;
|
2016-05-27 10:26:08 +00:00
|
|
|
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break;;
|
|
|
|
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
set_default cfg_dir "$HOME/.acme"
|
|
|
|
set_default checkend_seconds 259200
|
|
|
|
|
|
|
|
certname=$1
|
|
|
|
|
|
|
|
if ! [[ "$certname" ]]; then
|
|
|
|
err "Please tell me what to do!"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2016-05-27 10:36:04 +00:00
|
|
|
if [[ -f "$cfg_dir/domains/$certname/renew.fail" ]]; then
|
|
|
|
err "Fail flag exists: $cfg_dir/domains/$certname/renew.fail, not attempting renew."
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
|
2016-05-27 10:26:08 +00:00
|
|
|
if ! openssl x509 -checkend "$checkend_seconds" < "$cfg_dir/domains/$certname/certificate.pem"; then
|
|
|
|
if ! (( "${#domains[@]}" )); then
|
|
|
|
if [[ -f "$cfg_dir/domains/$certname/renew.cfg" ]]; then
|
|
|
|
source "$cfg_dir/domains/$certname/renew.cfg"
|
|
|
|
else
|
|
|
|
domains=( "$certname" )
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
for d in "${domains[@]}"; do
|
|
|
|
le_args+=( '-d' "$d" )
|
|
|
|
done
|
|
|
|
|
2016-05-30 23:39:23 +00:00
|
|
|
le "${le_args[@]}"
|
|
|
|
|
|
|
|
if (( $? )); then
|
2016-05-27 10:36:04 +00:00
|
|
|
> "$cfg_dir/domains/$certname/renew.fail"
|
|
|
|
fi
|
2016-05-27 10:26:08 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|