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