From 485d47158d509579e1f8a2ce11ff312fd2283c6c Mon Sep 17 00:00:00 2001 From: christoph Date: Fri, 4 Mar 2022 00:11:28 +0100 Subject: [PATCH] create_vhost.sh: allow multiple ipv6/ipv4 addresses. --- create_vhost.sh | 113 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 85 insertions(+), 28 deletions(-) diff --git a/create_vhost.sh b/create_vhost.sh index dd85b1a..929e87c 100755 --- a/create_vhost.sh +++ b/create_vhost.sh @@ -182,12 +182,28 @@ _major_php_verisons=`echo "$__major_php_verisons" | sed 's/^ *//'` # - Determin IP Addresses # - if ifconfig | grep -i -q -E "inet (address|Adresse):" ; then - __ipv4="`ifconfig | grep -e \"^\s*inet Adresse\" | grep -v \"127.0.0.1\" | awk '{print$2}' | cut -d\":\" -f2 | sort | head -1`" - __ipv6="`ifconfig | grep -e \"^\s*inet6-Adresse\" | awk '{print$2}' | grep -v -e \"^::1/\" | grep -v -e \"^fe80\" | cut -d\"/\" -f1 | sort | head -1`" + #__ipv4="`ifconfig | grep -e \"^\s*inet Adresse\" | grep -v \"127.0.0.1\" | awk '{print$2}' | cut -d\":\" -f2 | sort | head -1`" + __ipv4="`ifconfig | grep -E \"^\s*inet [address|Adresse]\" | grep -v \"127.0.0.1\" | awk '{print$2}' | cut -d\":\" -f2 | sort`" + #__ipv6="`ifconfig | grep -e \"^\s*inet6-Adresse\" | awk '{print$2}' | grep -v -e \"^::1/\" | grep -v -e \"^fe80\" | cut -d\"/\" -f1 | sort | head -1`" + __ipv6="`ifconfig | grep -e \"^\s*inet6-Adresse\" | awk '{print$2}' | grep -v -e \"^::1/\" | grep -v -e \"^fe80\" | cut -d\"/\" -f1 | sort`" else - __ipv4="`ifconfig | grep -e \"^\s*inet \" | grep -v \"127.0.0.1\" | awk '{print$2}' | sort | head -1`" - __ipv6="`ifconfig | grep -e \"^\s*inet6 \" | awk '{print$2}' | grep -v \"^::1\" | grep -v -e \"^fe80\" | sort | head -1`" + #__ipv4="`ifconfig | grep -e \"^\s*inet \" | grep -v \"127.0.0.1\" | awk '{print$2}' | sort | head -1`" + __ipv4="`ifconfig | grep -e \"^\s*inet \" | grep -v \"127.0.0.1\" | awk '{print$2}' | sort`" + #__ipv6="`ifconfig | grep -e \"^\s*inet6 \" | awk '{print$2}' | grep -v \"^::1\" | grep -v -e \"^fe80\" | sort | head -1`" + __ipv6="`ifconfig | grep -e \"^\s*inet6 \" | awk '{print$2}' | grep -v \"^::1\" | grep -v -e \"^fe80\" | sort`" fi +for _ip in $__ipv4 ; do + _ipv4="$_ipv4 $_ip" +done +for _ip in $__ipv6 ; do + _ipv6="$_ipv6 $_ip" +done +## - Trim leading whitespaces +## - +shopt -s extglob +__ipv4="${_ipv4##*( )}" +__ipv6="${_ipv6##*( )}" +shopt -u extglob # - Determin httpd binary # - @@ -1016,6 +1032,7 @@ if [ -z "$_existing_vhost_config_file" ]; then fi done + IPv4_FIRST=`echo $_ipv4 | cut -d " " -f1` _ipv6= while [ "X$_ipv6" = "X" ] @@ -1036,6 +1053,11 @@ if [ -z "$_existing_vhost_config_file" ]; then fi fi done + if [ "$_ipv6" != "disabled" ]; then + IPv6_FIRST=`echo $_ipv6 | cut -d " " -f1` + else + IPv6_FIRST="" + fi echo "" @@ -2035,6 +2057,37 @@ if $_print_summary ; then [ $OK = "yes" -o $OK = "Yes" ] || fatal Repeat installation with different parameters fi + +_default_ipv6=false + + +if [[ -n "${IPv4_FIRST}" ]]; then + _default_ipv4=true +fi +if [[ -n "${IPv6_FIRST}" ]]; then + _default_ipv6=true +fi + +_vhost_default_80="> ${_new_vhost_config_file} - +$_vhost_default_80 ServerAdmin $server_admin @@ -2110,7 +2163,7 @@ EOF if $_https ; then cat <> ${_new_vhost_config_file} - +$_vhost_default_443 ServerAdmin $server_admin @@ -2889,19 +2942,21 @@ EOF _failed=true fi done -if [ "$_ipv6" != "disabled" ]; then - cat <> ${_new_vhost_config_file} - - -EOF -else - cat <> ${_new_vhost_config_file} - - -EOF -fi +#if [ "$_ipv6" != "disabled" ]; then +# cat <> ${_new_vhost_config_file} +# +# +#EOF +#else +# cat <> ${_new_vhost_config_file} +# +# +#EOF +#fi cat <> ${_new_vhost_config_file} +$_vhost_default_80 + ServerAdmin $server_admin ServerName $_server_name @@ -2996,20 +3051,22 @@ if [ "$?" != "0" ]; then fi if $_https ; then - if [ "$_ipv6" != "disabled" ]; then - cat <> ${_new_vhost_config_file} - - -EOF - else - cat <> ${_new_vhost_config_file} - - -EOF - fi +# if [ "$_ipv6" != "disabled" ]; then +# cat <> ${_new_vhost_config_file} +# +# +#EOF +# else +# cat <> ${_new_vhost_config_file} +# +# +#EOF +# fi cat <> ${_new_vhost_config_file} +$_vhost_default_443 + ServerAdmin $server_admin ServerName $_server_name