add some error checking with exit codes
This commit is contained in:
parent
b3cd92e8ff
commit
8c99b89947
|
@ -13,11 +13,11 @@ help()
|
|||
thisfilename=$(basename -- "$0")
|
||||
echo "Enable Apache config for virtualhost."
|
||||
echo ""
|
||||
echo "usage: $thisfilename -d <domain> -m <macro> [-o <alias>|<redirect_url>] [-h]"
|
||||
echo "usage: $thisfilename -d <domain> [-m <macro>] [-o <alias>|<redirect_url>] [-h]"
|
||||
echo ""
|
||||
echo " -h Print this help."
|
||||
echo " -d <domain> Domain name of VirtualHost to add."
|
||||
echo " -m <macro> Name of Apache macro to apply."
|
||||
echo " -m <macro> Name of Apache macro to apply. Optional, script will attempt to autoselect if possible."
|
||||
echo " -o <option> Alias or Redirect URL if specified macro requires one."
|
||||
echo " For Aliases & Redirects '-d <domain>' is the alias/redirect domain,"
|
||||
echo " and '-o <option>' is the existing VirtualHost to alias/redirect to."
|
||||
|
@ -44,6 +44,12 @@ macro_array=($(grep Macro /etc/apache2/mods-available/macro.conf |cut -d ' ' -f
|
|||
|
||||
vhost:getoptions "$@"
|
||||
|
||||
# check for domain (virtualhost)
|
||||
if [[ ! -n $domain ]]; then
|
||||
echo "domain is required"
|
||||
exit
|
||||
fi
|
||||
|
||||
# check for macro
|
||||
if [[ -n $macro ]]; then
|
||||
if [[ " ${macro_array[@]} " =~ " ${macro} " ]]; then
|
||||
|
@ -53,14 +59,13 @@ if [[ -n $macro ]]; then
|
|||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "macro is required"
|
||||
exit
|
||||
if [[ "$domain" =~ ^mail.* ]]; then
|
||||
macro=VMailHTTPS
|
||||
elif [[ -f "/etc/ssl/letsencrypt/$domain.pem" ]]; then
|
||||
macro=VHostHTTPS
|
||||
else
|
||||
macro=VHostHTTP
|
||||
fi
|
||||
|
||||
# check for domain (virtualhost)
|
||||
if [[ ! -n $domain ]]; then
|
||||
echo "domain is required"
|
||||
exit
|
||||
fi
|
||||
|
||||
# if https check for le cert
|
||||
|
@ -162,4 +167,3 @@ if [[ -h /etc/apache2/sites-enabled/$domain.conf ]]; then
|
|||
else
|
||||
a2ensite --quiet $domain.conf
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user