+vhost_file=/etc/apache2/sites-enabled/$h.conf
+redir_file=/etc/apache2/sites-enabled/httpsredir.conf
+
+# note, we exepct ServerRoot of /etc/apache2
+# apache requires exactly 1 listen directive per port (when no ip is also given),
+# so we have to parse the config to do it programatically.
+listen_80=false
+listen_port=false
+cd /etc/apache2
+conf_files=(apache2.conf)
+for (( i=0; i < ${#conf_files[@]}; i++ )); do
+ f="${conf_files[i]}"
+ # note: globs are expanded here:
+ conf_files+=( $(sed -rn "s,^\s*Include(Optional)?\s+(\S+).*,\2,p" "$f") )
+ case $(readlink -f "$f") in
+ $vhost_file|$redir_file) continue ;;
+ esac
+ for p in $(sed -rn "s,^\s*listen\s+(\S+).*,\1,Ip" "$f"); do
+ case $p in
+ 80) listen_80=true ;;
+ $port) listen_port=true ;;
+ esac
+ done
+done
+
+if $ssl; then
+ https_arg=" https"
+fi
+
+
+echo "$0: creating $vhost_file"
+cat >$vhost_file <<EOF
+<VirtualHost *:$port>