Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Usage: ./ez_letsencrypt.sh -h <hostname> [<options>]
-w, --webrootdir <webroot_dir> directory on host to store webroot challenge files
-k, --checkcert show certificate issuer, subject and dates for given hostname
-p, --pubkey show certificate pubkey for given hostname
-q, --quiet Run non-interactively & suppress all certbot output except errors
-d, --dryrun test "renew" or "certonly" without saving any certificates to disk
-r, --renew renew all previously obtained certificates that are near expiry
-s, --selinux host is running centos with selinux enabled
Expand Down Expand Up @@ -128,6 +129,10 @@ Usage: ./ez_letsencrypt.sh -h <hostname> [<options>]

- **OPTIONAL**: Using the provided hostname to define a domain, an OpenSSL s_client call is issued to port 443 of the domain and if successful will return `pubkey` information for the certificate being used by that domain

### `-q`, `--quiet`: Run non-interactively & suppress all certbot output except errors

- **OPTIONAL**: By default certbot runs in a mode unsuitable for headless execution. Use quiet mode for automation & extended scripting.

### `-d`, `--dryrun`: test "renew" or "certonly" without saving any certificates to disk

- **OPTIONAL**: A full authentication challenge is run for obtaining or renewing a certificate but no new files are saved to disk. This is a good option to use while initially configuring your system.
Expand Down
33 changes: 23 additions & 10 deletions ez_letsencrypt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dryrun=false
renew=false
selinux=false
verbose=false
quiet=false
num_args=$#
### DEFAULT VALUES ###

Expand All @@ -28,6 +29,7 @@ Usage: $0 -h <hostname> [<options>]
-w, --webrootdir <webroot_dir> directory on host to store webroot challenge files
-k, --checkcert show certificate issuer, subject and dates for given hostname
-p, --pubkey show certificate pubkey for given hostname
-q, --quiet Run non-interactively & suppress all certbot output except errors
-d, --dryrun test "renew" or "certonly" without saving any certificates to disk
-r, --renew renew all previously obtained certificates that are near expiry
-s, --selinux host is running centos with selinux enabled
Expand Down Expand Up @@ -194,30 +196,35 @@ run_certbot_container() {
# Select appropriate staging arg
case $dryrun in
true) staging_arg="--dry-run"; ;;
*) staging_arg=""
*) staging_arg=""; ;;
esac
case $quiet in
true) quiet_arg="--quiet"; docker_prompt="docker run --rm"; ;;
*) quiet_arg=""; docker_prompt="docker run -it --rm"; ;;
esac

# Select appropriate run call
case $selinux in
(true)
case $renew in
(true)
docker run -it --rm \
$docker_prompt \
-v $le_certsdir:/etc/letsencrypt:z,rw \
-v $le_webrootdir:/data/letsencrypt:z,rw \
certbot/certbot \
renew \
--webroot --webroot-path=/data/letsencrypt \
$staging_arg \
$staging_arg $quiet_arg \
--rsa-key-size $rsa_key_size
;;
(false )
docker run -it --rm \
$docker_prompt \
-v $le_certsdir:/etc/letsencrypt:z,rw \
-v $le_webrootdir:/data/letsencrypt:z,rw \
certbot/certbot \
certonly \
--webroot --webroot-path=/data/letsencrypt \
$staging_arg \
$staging_arg $quiet_arg \
$email_arg \
$domain_args \
--rsa-key-size $rsa_key_size \
Expand All @@ -228,23 +235,23 @@ run_certbot_container() {
(false)
case $renew in
(true)
docker run -it --rm \
$docker_prompt \
-v $le_certsdir:/etc/letsencrypt \
-v $le_webrootdir:/data/letsencrypt \
certbot/certbot \
renew \
--webroot --webroot-path=/data/letsencrypt \
$staging_arg \
$staging_arg $quiet_arg \
--rsa-key-size $rsa_key_size
;;
(false )
docker run -it --rm \
$docker_prompt \
-v $le_certsdir:/etc/letsencrypt \
-v $le_webrootdir:/data/letsencrypt \
certbot/certbot \
certonly \
--webroot --webroot-path=/data/letsencrypt \
$staging_arg \
$staging_arg $quiet_arg \
$email_arg \
$domain_args \
--rsa-key-size $rsa_key_size \
Expand All @@ -259,6 +266,8 @@ run_certbot_container() {
for arg in "$@"; do
shift
case "$arg" in
"--quiet") set -- "$@" "-q" ;;
"-quiet") echo "did you mean --quiet?"; usage ;;
"--hostname") set -- "$@" "-h" ;;
"-hostname") echo "did you mean --hostname?"; usage ;;
"--email") set -- "$@" "-e" ;;
Expand Down Expand Up @@ -288,7 +297,7 @@ for arg in "$@"; do
done

# parse user input for valid options
while getopts "h:e:n:c:w:kpdrsuv" o; do
while getopts "h:e:n:c:w:kpqdrsuv" o; do
case "${o}" in
h)
le_hostname=${OPTARG}
Expand All @@ -315,6 +324,9 @@ while getopts "h:e:n:c:w:kpdrsuv" o; do
openssl_pubkey
exit 0;
;;
q)
quiet=true
;;
d)
dryrun=true
;;
Expand Down Expand Up @@ -342,6 +354,7 @@ case $verbose in
(true)
cat <<EOF
[DEBUG] variable settings
- quiet = $quiet
- hostname = $le_hostname
- email = $le_email
- nginx = $le_nginx
Expand Down