improve error display

This commit is contained in:
Jérémy Lecour 2020-05-05 15:24:06 +02:00 committed by Jérémy Lecour
parent d9f866fc3a
commit 0c4d36cb57

View file

@ -56,7 +56,7 @@ init() {
-aes256 ${CA_KEY_LENGTH} \ -aes256 ${CA_KEY_LENGTH} \
>/dev/null 2>&1 >/dev/null 2>&1
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the CA key: $?" error "Error generating the CA key"
fi fi
fi fi
@ -89,7 +89,7 @@ $(cat "${CONF_FILE}")
commonName_default = ${cn} commonName_default = ${cn}
EOF EOF
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the CA certificate: $?" error "Error generating the CA certificate"
fi fi
fi fi
} }
@ -113,7 +113,7 @@ ocsp() {
${KEY_LENGTH} \ ${KEY_LENGTH} \
>/dev/null 2>&1 >/dev/null 2>&1
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the OCSP key: $?" error "Error generating the OCSP key"
fi fi
fi fi
@ -129,7 +129,7 @@ commonName_default = ${url}
authorityInfoAccess = OCSP;URI:http://${ocsp_uri} authorityInfoAccess = OCSP;URI:http://${ocsp_uri}
EOF EOF
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the OCSP request: $?" error "Error generating the OCSP request"
fi fi
if [ ! -f "${OCSP_CERT}" ]; then if [ ! -f "${OCSP_CERT}" ]; then
@ -144,7 +144,7 @@ EOF
-passin pass:${CA_PASSWORD} \ -passin pass:${CA_PASSWORD} \
-config "${CONF_FILE}" -config "${CONF_FILE}"
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the OCSP certificate: $?" error "Error generating the OCSP certificate"
fi fi
fi fi
@ -264,7 +264,10 @@ create() {
# csr-file option, with value separated by space # csr-file option, with value separated by space
if [ -n "$2" ]; then if [ -n "$2" ]; then
from_csr=1 from_csr=1
csr_file=$(readlink --canonicalize --verbose -- "${2}") csr_file=$(readlink --canonicalize -- "${2}")
if [ "$?" -ne 0 ]; then
error "Error accessing file \`${2}'"
fi
shift shift
else else
printf 'ERROR: "--csr-file" requires a non-empty option argument.\n' >&2 printf 'ERROR: "--csr-file" requires a non-empty option argument.\n' >&2
@ -274,7 +277,10 @@ create() {
--file=?*|--csr-file=?*) --file=?*|--csr-file=?*)
from_csr=1 from_csr=1
# csr-file option, with value separated by = # csr-file option, with value separated by =
csr_file=$(readlink --canonicalize --verbose -- "${1#*=}") csr_file=$(readlink --canonicalize -- "${1#*=}")
if [ "$?" -ne 0 ]; then
error "Error accessing file \`${1#*=}'"
fi
;; ;;
--file=|--csr-file=) --file=|--csr-file=)
# csr-file options, without value # csr-file options, without value
@ -287,7 +293,10 @@ create() {
--password-file) --password-file)
# password-file option, with value separated by space # password-file option, with value separated by space
if [ -n "$2" ]; then if [ -n "$2" ]; then
password_file=$(readlink --canonicalize --verbose -- "${2}") password_file=$(readlink --canonicalize -- "${2}")
if [ "$?" -ne 0 ]; then
error "Error accessing file \`${2}'"
fi
shift shift
else else
printf 'ERROR: "--password-file" requires a non-empty option argument.\n' >&2 printf 'ERROR: "--password-file" requires a non-empty option argument.\n' >&2
@ -296,7 +305,10 @@ create() {
;; ;;
--password-file=?*) --password-file=?*)
# password-file option, with value separated by = # password-file option, with value separated by =
password_file=$(readlink --canonicalize --verbose -- "${1#*=}") password_file=$(readlink --canonicalize -- "${1#*=}")
if [ "$?" -ne 0 ]; then
error "Error accessing file \`${1#*=}'"
fi
;; ;;
--password-file=) --password-file=)
# password-file options, without value # password-file options, without value
@ -433,7 +445,7 @@ create() {
-out "${crt_file}" \ -out "${crt_file}" \
${crt_expiration_arg} ${crt_expiration_arg}
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the certificate: $?" error "Error generating the certificate"
else else
echo "The certificate file is available at \`${crt_file}'" echo "The certificate file is available at \`${crt_file}'"
fi fi
@ -481,7 +493,7 @@ create() {
${KEY_LENGTH} \ ${KEY_LENGTH} \
>/dev/null 2>&1 >/dev/null 2>&1
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the private key: $?" error "Error generating the private key"
fi fi
# generate csr req # generate csr req
@ -502,7 +514,7 @@ $(cat "${CONF_FILE}")
commonName_default = ${cn} commonName_default = ${cn}
EOF EOF
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the CSR: $?" error "Error generating the CSR"
fi fi
# ca sign and generate cert # ca sign and generate cert
@ -513,7 +525,7 @@ EOF
-out "${crt_file}" \ -out "${crt_file}" \
${crt_expiration_arg} ${crt_expiration_arg}
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the certificate: $?" error "Error generating the certificate"
fi fi
# check if CRT is a valid # check if CRT is a valid
@ -555,7 +567,7 @@ EOF
-out "${pkcs12_file}" \ -out "${pkcs12_file}" \
${PASS_ARGS} ${PASS_ARGS}
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
error "Error generating the pkcs12 file: $?" error "Error generating the pkcs12 file"
fi fi
if [ -n "${password_file_out}" ]; then if [ -n "${password_file_out}" ]; then