[ssl_mgmt] Add option to only generate openssl.cnf

This commit is contained in:
Thomas Preud'homme 2014-03-09 16:22:54 +08:00
parent e428424cf0
commit d6f92888a8
1 changed files with 28 additions and 8 deletions

View File

@ -30,11 +30,15 @@ usage ()
progname=$1
echo "Usage :"
echo
echo "$progname renew <service>"
echo "$progname [-c] renew <service>"
echo "$progname -h"
echo
echo "First form renew the certificate of the given service"
echo
echo "Possible option:"
echo
echo "-c Only generate the configuration"
echo
echo "Second form prints this help."
}
@ -63,13 +67,16 @@ ask_user_default_no ()
return 0
}
# Test number of argument is correct and their value are correct also.
test_args ()
# Parse arguments and test their number and value is correct.
parse_args ()
{
local - user domain
while getopts "h" opt
local - user domain action
config_only=""
while getopts "ch" opt
do
case $opt in
"c")
config_only=yes ;;
"h")
if [ $# -gt 1 ]
then
@ -80,7 +87,8 @@ test_args ()
exit 0 ;;
esac
done
if [ $# -ne 2 -o "$1" != "renew" ]
eval action="\${$OPTIND:-}"
if [ $(($#-$OPTIND+1)) -ne 2 -o "$action" != "renew" ]
then
usage $(basename "$0")
exit 0
@ -215,7 +223,7 @@ main ()
{
local - ret servicesok
ret=0
test_args "$@"
parse_args "$@"
# This test should be useless if rights on this file are corrects
# (that is 770 for root:gt owner)
if must_sudo
@ -238,6 +246,10 @@ main ()
servicesok=""
get_cert_params
generate_config
if [ -n "$config_only" ]
then
continue
fi
if ! generate_cert
then
ret=1
@ -245,7 +257,15 @@ main ()
servicesok="$servicesok${servicesok:+ }$service"
fi
done
echo "You should restart the following services: $servicesok"
if [ -z "$config_only" ]
then
if [ -n "$servicesok" ]
then
echo "You should restart the following services: $servicesok"
else
echo "No certificate generated"
fi
fi
return $ret
}