allow export of config variables for use in other scripts

This commit is contained in:
Lukas Schauer
2015-12-14 01:20:21 +01:00
parent 5120dfb5f3
commit 1ab6a436c0

View File

@@ -52,7 +52,9 @@ init_system() {
echo "WARNING: No config file found, using default config!" echo "WARNING: No config file found, using default config!"
sleep 2 sleep 2
elif [[ -e "${CONFIG}" ]]; then elif [[ -e "${CONFIG}" ]]; then
echo "Using config file ${CONFIG}" if [[ ! "${COMMAND}" = "env" ]]; then
echo "Using config file ${CONFIG}"
fi
BASEDIR="$(dirname "${CONFIG}")" BASEDIR="$(dirname "${CONFIG}")"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. "${CONFIG}" . "${CONFIG}"
@@ -71,6 +73,10 @@ init_system() {
fi fi
set_defaults set_defaults
if [[ "${COMMAND}" = "env" ]]; then
return
fi
# Lockfile handling (prevents concurrent access) # Lockfile handling (prevents concurrent access)
set -o noclobber set -o noclobber
if ! { date > "${LOCKFILE}"; } 2>/dev/null; then if ! { date > "${LOCKFILE}"; } 2>/dev/null; then
@@ -120,7 +126,7 @@ init_system() {
register="1" register="1"
fi fi
fi fi
# Get public components from private key and calculate thumbprint # Get public components from private key and calculate thumbprint
pubExponent64="$(printf "%06x" "$(openssl rsa -in "${PRIVATE_KEY}" -noout -text | grep publicExponent | head -1 | cut -d' ' -f2)" | hex2bin | urlbase64)" pubExponent64="$(printf "%06x" "$(openssl rsa -in "${PRIVATE_KEY}" -noout -text | grep publicExponent | head -1 | cut -d' ' -f2)" | hex2bin | urlbase64)"
pubMod64="$(printf '%s' "$(openssl rsa -in "${PRIVATE_KEY}" -noout -modulus | cut -d'=' -f2)" | hex2bin | urlbase64)" pubMod64="$(printf '%s' "$(openssl rsa -in "${PRIVATE_KEY}" -noout -modulus | cut -d'=' -f2)" | hex2bin | urlbase64)"
@@ -462,7 +468,7 @@ command_help() {
echo echo
( (
echo "Commands:" echo "Commands:"
grep -e '# Usage:' -e '# Description:' -e '^command_.*()\s*{' "${0}" | while read -r usage; read -r description; read -r command; do grep -e '^\s*# Usage:' -e '^\s*# Description:' -e '^command_.*()\s*{' "${0}" | while read -r usage; read -r description; read -r command; do
if [[ ! "${usage}" =~ Usage ]]; then if [[ ! "${usage}" =~ Usage ]]; then
echo "Error generating help text." echo "Error generating help text."
exit 1 exit 1
@@ -490,6 +496,14 @@ command_help() {
) | column -t -s $'\t' | sed 's/^---$//g' ) | column -t -s $'\t' | sed 's/^---$//g'
} }
# Usage: --env (-e)
# Description: Output configuration variables for use in other scripts
command_env() {
echo "# letsencrypt.sh configuration"
typeset -p CA LICENSE BASEDIR WELLKNOWN PRIVATE_KEY KEYSIZE OPENSSL_CNF ROOTCERT HOOK RENEW_DAYS PRIVATE_KEY_RENEW CONTACT_EMAIL
exit 0
}
args="" args=""
# change long args to short args # change long args to short args
# inspired by http://kirk.webfinish.com/?p=45 # inspired by http://kirk.webfinish.com/?p=45
@@ -501,6 +515,7 @@ for arg; do
--revoke) args="${args}-r ";; --revoke) args="${args}-r ";;
--privkey) args="${args}-p ";; --privkey) args="${args}-p ";;
--config) args="${args}-f ";; --config) args="${args}-f ";;
--env) args="${args}-e ";;
--*) --*)
echo "Unknown parameter detected: ${arg}" echo "Unknown parameter detected: ${arg}"
echo echo
@@ -534,7 +549,7 @@ check_parameters() {
fi fi
} }
while getopts ":hcr:s:f:p:" option; do while getopts ":hcer:s:f:p:" option; do
case "${option}" in case "${option}" in
h) h)
command_help command_help
@@ -543,6 +558,9 @@ while getopts ":hcr:s:f:p:" option; do
c) c)
set_command cron set_command cron
;; ;;
e)
set_command env
;;
r) r)
set_command revoke set_command revoke
check_parameters "${OPTARG:-}" check_parameters "${OPTARG:-}"
@@ -584,6 +602,9 @@ case "${COMMAND}" in
cron) cron)
command_cron command_cron
;; ;;
env)
command_env
;;
sign) sign)
command_sign ${sign_me} command_sign ${sign_me}
;; ;;