license gpl, per gnu license recommendations of >300 lines of code
[basic-https-conf] / web-conf
index 38dce524cf0153ff47c5592b6d5246802a86b69b..045a9b3d87a8a7d1223eb7984d095d7d607a87c9 100755 (executable)
--- a/web-conf
+++ b/web-conf
@@ -1,17 +1,21 @@
 #!/bin/bash
-# Copyright (C) 2016 Ian Kelling
+# This file is part of web-conf which configures web servers
+# Copyright (C) 2024  Ian Kelling
 
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
 
-#     http://www.apache.org/licenses/LICENSE-2.0
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# SPDX-License-Identifier: GPL-3.0-or-later
 
 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
 
@@ -51,7 +55,8 @@ EXTRA_SETTINGS_FILE can be - for stdin
 -i                Insecure, no ssl.
 -p PORT           Main port to listen on, default 443. 80 implies -i.
 -r DIR            DocumentRoot
--s                Allow symlinks from the doucmentroot
+-s                Allow symlinks from the doucment root
+-t                No settings on documentroot.
 -h|--help         Print help and exit
 
 Note: Uses GNU getopt options parsing style
@@ -65,7 +70,8 @@ symlinkarg=-
 ssl=true
 extra_settings=
 port=443
-temp=$(getopt -l help a:c:e:if:p:r:sh "$@") || usage 1
+do_root_settings=true
+temp=$(getopt -l help a:c:e:if:p:r:sth "$@") || usage 1
 vhostip='*'
 eval set -- "$temp"
 while true; do
@@ -80,6 +86,7 @@ while true; do
     -i) ssl=false; shift ;;
     -p) port="$2"; shift 2 ;;
     -r) root="$2"; shift 2 ;;
+    -t) do_root_settings=false; shift ;;
     -s) symlinkarg=+; shift ;;
     --) shift; break ;;
     -h|--help) usage ;;
@@ -202,10 +209,14 @@ if [[ $t == apache2 ]]; then
 ServerName $h
 ServerAlias www.$h
 DocumentRoot $root
+EOF
+  if $do_root_settings; then
+    cat >>$vhost_file <<EOF
 <Directory $root>
   Options -Indexes ${symlinkarg}FollowSymlinks
 </Directory>
 EOF
+  fi
 
   if [[ $extra_settings ]]; then
     cat -- $extra_settings >>$vhost_file
@@ -403,11 +414,13 @@ EOF
   listen [::]:$port $ssl_arg;
 EOF
   fi
-  cat >>$vhost_file <<EOF
+  if $do_root_settings; then
+    cat >>$vhost_file <<EOF
   location $root {
     autoindex off;
   }
 EOF
+  fi
   if $ssl; then
     cat >>$vhost_file <<EOF
   ssl_certificate $cert_dir/fullchain.pem;