X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=apache-site;h=9a22d2aad73a308d4bffc0b4fd6c6e2a85e2dcf7;hb=17878ab5996f12d3f9d1ce602954bb2fbf357849;hp=8a67722ada42f9487a7fa6408a0a9d29d7612784;hpb=74fad776536c29ecc45395259ea19fd3b1cf5cac;p=basic-https-conf diff --git a/apache-site b/apache-site index 8a67722..9a22d2a 100755 --- a/apache-site +++ b/apache-site @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -# run as root. [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@" set -eE -o pipefail @@ -27,15 +26,14 @@ ssl config provided by let's encrypt and my standard location for storing certs. EXTRA_SETTINGS_FILE can be - for stdin --p PORT --i Insecure, no ssl -c CERT_DIR In priority: this arg, $ACME_TINY_WRAPPER_CERT_DIR, $HOME/webservercerts, if the other options aren't set. --h|--help Print help and exit +-i Insecure, no ssl +-p PORT Main port to listen on, default 443 -r DocumentRoot --- Subsequent arguments are never treated as options +-h|--help Print help and exit -Note: options and non-options can be in any order. +Note: Uses GNU getopt options parsing style EOF exit $1 } @@ -48,25 +46,25 @@ if [[ ! $cert_dir ]]; then fi ssl=true extra_settings= -args=() port="*:443" -while [[ $1 ]]; do +temp=$(getopt -l help ic:p:r:h "$@") || usage 1 +eval set -- "$temp" +while true; do case $1 in - -i) ssl=false; shift ;; # i for insecure + -i) ssl=false; shift ;; -c) cert_dir="$2"; shift 2 ;; -p) port="$2"; shift 2 ;; -r) root="$2"; shift 2 ;; --) shift; break ;; - -?*|-h|--help) usage ;; - *) args+=("$1"); shift ;; + -h|--help) usage ;; + *) echo "$0: Internal error!" ; exit 1 ;; esac done -args+=("$@") -if (( ${#args[@]} == 2 )); then - read extra_settings h <<<"${args[@]}" +if (( ${#@} == 2 )); then + read -r extra_settings h <<<"${@}" else - read h <<<"${args[@]}" + read -r h <<<"${@}" fi if [[ ! $h ]]; then @@ -96,7 +94,8 @@ fi rm -f /etc/apache2/sites-enabled/000-default.conf mkdir -p $root -dd of=/etc/apache2/sites-enabled/$h.conf <$vhost_file < ServerName $h ServerAlias www.$h @@ -104,26 +103,30 @@ dd of=/etc/apache2/sites-enabled/$h.conf <s %O \"%{Referer}i\" \"%{User-Agent}i\" %D" vhost_time_combined ServerAdmin webmaster@localhost DocumentRoot /var/www/html @@ -140,9 +143,8 @@ EOF mkdir -p /etc/letsencrypt - base_file=/etc/letsencrypt/options-ssl-apache.conf # this is from cerbot, see below. - dd of=$base_file <<'EOF' + cat >$certbot_ssl_conf <<'EOF' # Baseline setting to Include for SSL sites SSLEngine on @@ -168,7 +170,7 @@ LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common EOF upstream=https://github.com/certbot/certbot/raw/master/certbot-apache/certbot_apache/options-ssl-apache.conf - if ! diff -c <(wget -q -O - $upstream) $base_file; then + if ! diff -c <(wget -q -O - $upstream) $certbot_ssl_conf; then cat < # vim: syntax=apache ts=4 sw=4 sts=4 sr noet