#!/bin/bash
#  l11 - LetsEncrypt SSL certificate helper

set -e

source "/home/zwelch/src/mcf/mcsh-release/install/share/mcsh/mcsh.sh"

lib_load 'sec/tool/certbot'
lib_load 'sys/tool/cron'

######
# Certificate CLI

l11_cert() { cmd_dispatch "$@"; }
l11_cert_usage() {
	cat <<USAGE
<cmd> [...]
Certificate Commands:
	request <domain>+		Request a new certificate
	renew				Renews existing certificates
USAGE
}
l11_cert_request() { certbot_request "$@"; }
l11_cert_renew() { certbot_renew "$@"; }


######
# Cron CLI

l11_cron() { cmd_dispatch "$@"; }
l11_cron_usage() {
	cat <<USAGE
<cmd> [...]
Cron Commands:
	install				Installs cron task
	remove				Removes cron task

Internal Cron Commands:
	run				Called by cron to perform task
USAGE
}

l11_cron_install() { cron_script_install daily; }
l11_cron_remove() { cron_script_remove daily; }

l11_cron_run() {
	if certbot_renew --quiet --no-self-upgrade; then
		return
	fi
	local log
	log=$(script_log_filename "renew")

cat <<REPORT
######
# SSL Cert Renewal Failed

Host: $host
Domain: $domain

======
$log
------
REPORT
	cat "$log"
}


######
# Certbot CLI

l11_certbot() { cmd_dispatch "$@"; }
l11_certbot_usage() {
	cat <<USAGE
<cmd> ...
Certbot Commands:
	download			Downloads the certbot script
	run ...				Runs the certbot script
USAGE
}
l11_certbot_download() { certbot_download "$@"; }
l11_certbot_run() {
	local -a certbot_opts=(  )
	run_certbot "$@"
}


######
# Main

l11_desc() { echo "LetsEncrypt SSL certificate helper"; }

l11_usage() {
	cat <<USAGE
<cmd> ...
Command Groups:
	cert ...			Certifiate management commands
	certbot ...			Certbot script commands
	cron ...			Cron job commands

USAGE
}

app_run "$@"

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:34:40 PDT 2017 by mcsh d14 v0.23.0.