init can be "non-interactive"

This commit is contained in:
Jérémy Lecour 2022-03-11 14:10:32 +01:00 committed by Jérémy Lecour
parent 6cc29fb1f8
commit 10edbb19fa

View file

@ -171,7 +171,7 @@ init() {
# Parse options # Parse options
# based on https://gist.github.com/deshion/10d3cb5f88a21671e17a # based on https://gist.github.com/deshion/10d3cb5f88a21671e17a
while :; do while :; do
case $1 in case ${1:-} in
--non-interactive) --non-interactive)
non_interactive=1 non_interactive=1
;; ;;
@ -200,17 +200,27 @@ init() {
fi fi
if [ -f "${CA_KEY}" ]; then if [ -f "${CA_KEY}" ]; then
printf "%s already exists, do you really want to erase it ? [y/N] " "${CA_KEY}" if [ "${non_interactive}" -eq 1 ]; then
read -r REPLY error "${CA_KEY} already exists, erase it manually if you want to start over."
resp=$(echo "${REPLY}" | tr 'Y' 'y') else
if [ "${resp}" = "y" ]; then printf "%s already exists, do you really want to erase it ? [y/N] " "${CA_KEY}"
rm -f "${CA_KEY}" "${CA_CERT}" read -r REPLY
resp=$(echo "${REPLY}" | tr 'Y' 'y')
if [ "${resp}" = "y" ]; then
rm -f "${CA_KEY}" "${CA_CERT}"
fi
fi fi
fi fi
passout_arg=""
if [ -n "${CA_PASSWORD:-}" ]; then
passout_arg="-passout pass:${CA_PASSWORD}"
fi
if [ ! -f "${CA_KEY}" ]; then if [ ! -f "${CA_KEY}" ]; then
"${OPENSSL_BIN}" genrsa \ "${OPENSSL_BIN}" genrsa \
-out "${CA_KEY}" \ -out "${CA_KEY}" \
${passout_arg} \
-aes256 \ -aes256 \
"${CA_KEY_LENGTH}" \ "${CA_KEY_LENGTH}" \
>/dev/null 2>&1 >/dev/null 2>&1