From 5fd26378ef8a0cdf3882dba00c490117899b20e3 Mon Sep 17 00:00:00 2001 From: Andrey Arapov Date: Sat, 30 Jun 2018 19:19:38 +0200 Subject: [PATCH] fixes --- gencert.sh | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/gencert.sh b/gencert.sh index 39cdbd0..f9f3c3b 100755 --- a/gencert.sh +++ b/gencert.sh @@ -70,19 +70,9 @@ function print_help() { # A POSIX variable OPTIND=1 # Reset in case getopts has been used previously in the shell. -ARGUMENT_LIST=( - "cn" - "key" - "cert" - "days" - "cakey" - "ca" - "cadays" -) - # read arguments opts=$(getopt \ - --longoptions "help,$(printf "%s:," "${ARGUMENT_LIST[@]}")" \ + --longoptions "help,cn:,key:,cert:,days:,cakey:,ca:,cadays:," \ --name "$(basename "$0")" \ --options "" \ -- "$@" @@ -206,9 +196,26 @@ function gen_server_x509() { -extensions v3_req_server -extfile "${OPENSSL_CONFIG}" 2>/dev/null } +function install_openssl() { + if type -p openssl >/dev/null; then + return; + fi + + if [ -f /etc/alpine-release ]; then + apk add --update openssl + elif [ -f /etc/centos-release ]; then + yum -y install openssl + elif grep -q Ubuntu /etc/lsb-release; then + export DEBIAN_FRONTEND=noninteractive + apt-get update + apt-get -y install openssl + fi +} + function start() { echo "[${ME}] Started in ${PWD} directory." + install_openssl; gen_openssl_config; if [ ! -f "${CA_KEY}" ]; then