diff --git a/bin/vhost-enable.sh b/bin/vhost-enable.sh index d4a0966..3efe1a1 100755 --- a/bin/vhost-enable.sh +++ b/bin/vhost-enable.sh @@ -50,15 +50,8 @@ if [[ ! -n $domain ]]; then exit fi -# check for macro -if [[ -n $macro ]]; then - if [[ " ${macro_array[@]} " =~ " ${macro} " ]]; then - macro_vhost_line="Use $macro" - else - echo "invalid macro name" - exit 1 - fi -else +# autodetect macro to use if not set +if [[ ! -n $macro ]]; then if [[ "$domain" =~ ^mail.* ]]; then macro=VMailHTTPS elif [[ -f "/etc/ssl/letsencrypt/$domain.pem" ]]; then @@ -67,6 +60,13 @@ else macro=VHostHTTP fi fi +# verify macro name +if [[ " ${macro_array[@]} " =~ " ${macro} " ]]; then + macro_vhost_line="Use $macro" +else + echo "invalid macro name" + exit 1 +fi # if https check for le cert if [[ "$macro" == *"HTTPS"* ]]; then