From 6912de47974c4672abe52021aac471b4e8281640 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sun, 14 Jul 2024 15:11:01 -0400 Subject: [PATCH 1/6] Improve mail system Add antivirus, DKIM, ARC, and related tools. Start adding Mailman3 --- tiamat-install.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tiamat-install.sh b/tiamat-install.sh index 000738b..cec679b 100755 --- a/tiamat-install.sh +++ b/tiamat-install.sh @@ -29,6 +29,9 @@ boost-devel certbot certbot python3-certbot-apache clamav +clamav-milter +clamav-update +clamd cmake dnf-automatic dovecot @@ -46,6 +49,7 @@ links man2html mariadb mariadb-server +mailman3 mod_ssl mpfr-devel mutt @@ -60,6 +64,9 @@ nagios-plugins-swap nagios-plugins-users nmstate nrpe +openarc +opendkim +opendkim-tools pam-devel php php-gd @@ -154,9 +161,14 @@ firewall-cmd --runtime-to-permanent # Start services services=' +clamd@service +clamav-milter httpd +mailman3 mariadb named +openarc +opendkim postgresql saslauthd sendmail From 1031597b739f4bb3fbc0a4a6363724d644d2b60d Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 14 Dec 2024 11:48:28 -0500 Subject: [PATCH 2/6] Add btidy.sh --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0462eb0..2a9d51c 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Obscure Scripts A collection of scripts from [The Obscure Organization](https://www.obscure.org) - a public access UNIX system in continuous use since 1995. * [blockip.sh](blockip.sh) - Use iptables to temporarily block an IP addreess or CIDR block +* [btidy.sh](btidy.sh) - Use [HTML tidy]() but only versus the body of an HTML file. Useful for filtering fragments of HTML files, or for using in vim (`:'a,'b ! btidy -wrap 0 -i -asxml`) * [cloud-init-centos-7-ipv6.yml](cloud-init-centos-7-ipv6.yml) - Use in instance data for CentOS 7.x EC2 servers that are having trouble getting an IPv6 default route. See also [cloud-init-centos-7.6-ipv4-ena.yml](cloud-init-centos-7.6-ipv4-ena.yml) and [cloud-init-centos-7.6-ipv6-ena.yml](cloud-init-centos-7.6-ipv4-ena.yml) * [icinga2-graceful.sh](icinga2-graceful.sh) - Check the validity of icinga2 system configuration files, then restart it only if the configuration is ok. From bdebd9e9bf689eb8df151623a86ecdb2be443c37 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 14 Dec 2024 11:50:44 -0500 Subject: [PATCH 3/6] Add btidy.sh --- btidy.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 btidy.sh diff --git a/btidy.sh b/btidy.sh new file mode 100755 index 0000000..992f6a6 --- /dev/null +++ b/btidy.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# +# btidy.sh +# +# Use HTML tidy on just the body of an HTML file. +# +# Usage: +# btidy [options] ... +# +# Copyright (C) 2024 by The Obscure Organization +# +# MIT licensed. See the LICENSE file for details. +# +# Release History: +# +# 1.0 (Sat Dec 14, 2024) +# First public release + +# Use bash unofficial strict mode +set -euo pipefail +IFS=$'\n\t' + +TMPFILE=$(mktemp /tmp/btidy.XXXXXX) + +# remove tempfile on exit +function finish { + rm -f "$TMPFILE" +} +trap finish EXIT + +echo '' >> "$TMPFILE" + +echo "invisible" >> "$TMPFILE" +FILE=$1 +shift +cat "$FILE" >> "$TMPFILE" +# shellcheck disable=SC2048,SC2086 +tidy -q --show-body-only y $* "$TMPFILE" +if [ $? -lt 2 ] && echo "$*" | grep -- '-m' > /dev/null; then + cat "$TMPFILE" > "$FILE" +fi +#echo "grep exit: $?" From 2212afdab58bfe39f430898d07a4ef5edb6063bf Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 14 Dec 2024 12:16:06 -0500 Subject: [PATCH 4/6] WIP on btidy.sh --- README.md | 2 +- btidy.sh | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2a9d51c..12d590f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Obscure Scripts A collection of scripts from [The Obscure Organization](https://www.obscure.org) - a public access UNIX system in continuous use since 1995. * [blockip.sh](blockip.sh) - Use iptables to temporarily block an IP addreess or CIDR block -* [btidy.sh](btidy.sh) - Use [HTML tidy]() but only versus the body of an HTML file. Useful for filtering fragments of HTML files, or for using in vim (`:'a,'b ! btidy -wrap 0 -i -asxml`) +* [btidy.sh](btidy.sh) - Use [HTML tidy](https://www.html-tidy.org/) but only versus the body of an HTML file. Useful for filtering fragments of HTML files, or for using in vim (`:'a,'b ! btidy -wrap 0 -i -asxml`) * [cloud-init-centos-7-ipv6.yml](cloud-init-centos-7-ipv6.yml) - Use in instance data for CentOS 7.x EC2 servers that are having trouble getting an IPv6 default route. See also [cloud-init-centos-7.6-ipv4-ena.yml](cloud-init-centos-7.6-ipv4-ena.yml) and [cloud-init-centos-7.6-ipv6-ena.yml](cloud-init-centos-7.6-ipv4-ena.yml) * [icinga2-graceful.sh](icinga2-graceful.sh) - Check the validity of icinga2 system configuration files, then restart it only if the configuration is ok. diff --git a/btidy.sh b/btidy.sh index 992f6a6..a8d7c7a 100755 --- a/btidy.sh +++ b/btidy.sh @@ -3,6 +3,7 @@ # btidy.sh # # Use HTML tidy on just the body of an HTML file. +# See https://www.html-tidy.org/ for documentation on tidy. # # Usage: # btidy [options] ... @@ -28,16 +29,23 @@ function finish { } trap finish EXIT -echo '' >> "$TMPFILE" - -echo "invisible" >> "$TMPFILE" -FILE=$1 -shift +# Nice, thanks https://www.cyberciti.biz/faq/linux-unix-bsd-apple-osx-bash-get-last-argument/ +FILE="${BASH_ARGV[0]}" +#FILE=${1:-/dev/stdin} +# If a file is specified as the first CLI option, consume the first parameter +if [ -f "$FILE" ]; then + # tricksy - thanks https://unix.stackexchange.com/a/273531 + ARGS="${@:1:$#-1}" +fi +cat < "$TMPFILE" + +invisible + +EOF cat "$FILE" >> "$TMPFILE" # shellcheck disable=SC2048,SC2086 -tidy -q --show-body-only y $* "$TMPFILE" -if [ $? -lt 2 ] && echo "$*" | grep -- '-m' > /dev/null; then +tidy -q --show-body-only y $ARGS "$TMPFILE" +if [ $? -lt 2 ] && echo "$ARGS" | grep --quiet -- '-m'; then cat "$TMPFILE" > "$FILE" fi #echo "grep exit: $?" From 22fc9b71bed19d3e358f027649c3a997f785b2c3 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 14 Dec 2024 13:11:35 -0500 Subject: [PATCH 5/6] Make this work properly with stdin and without Getting the argument processing and error handling was tricky. Encapsulate Tidy output in HTML comments when used as a filter. --- btidy.sh | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/btidy.sh b/btidy.sh index a8d7c7a..90ab8dc 100755 --- a/btidy.sh +++ b/btidy.sh @@ -21,31 +21,62 @@ set -euo pipefail IFS=$'\n\t' +DEBUG=${DEBUG:-false} + +# Thanks https://stackoverflow.com/a/17805088 +$DEBUG && export PS4='${LINENO}: ' && set -x + TMPFILE=$(mktemp /tmp/btidy.XXXXXX) +TMPERR=$(mktemp /tmp/btidy-err.XXXXXX) +TMPOUT=$(mktemp /tmp/btidy-out.XXXXXX) # remove tempfile on exit function finish { - rm -f "$TMPFILE" + rm -f "$TMPFILE" "$TMPERR" } trap finish EXIT # Nice, thanks https://www.cyberciti.biz/faq/linux-unix-bsd-apple-osx-bash-get-last-argument/ -FILE="${BASH_ARGV[0]}" -#FILE=${1:-/dev/stdin} -# If a file is specified as the first CLI option, consume the first parameter -if [ -f "$FILE" ]; then +FILE="${BASH_ARGV[0]:-}" +if [ -z "$FILE" ]; then + ARGS="$*" + FILE=/dev/stdin +elif [ -f "$FILE" ]; then + # If a file is specified as the last CLI option, consume the last parameter # tricksy - thanks https://unix.stackexchange.com/a/273531 + # shellcheck disable=2124 ARGS="${@:1:$#-1}" +else + ARGS="$*" + FILE=/dev/stdin fi + cat < "$TMPFILE" invisible EOF cat "$FILE" >> "$TMPFILE" +set +e # shellcheck disable=SC2048,SC2086 -tidy -q --show-body-only y $ARGS "$TMPFILE" -if [ $? -lt 2 ] && echo "$ARGS" | grep --quiet -- '-m'; then +tidy -q --show-body-only y $ARGS "$TMPFILE" > "$TMPOUT" 2>"$TMPERR" +EXITCODE=$? +set -e + +if [[ "$EXITCODE" -gt 0 ]]; then + echo "WARNING: tidy had non-zero exit $EXITCODE" >> "$TMPERR" +fi +if [[ "$FILE" != "/dev/stdin" ]] \ + && echo "$ARGS" | grep --quiet -E -- '-m|--modify' +then cat "$TMPFILE" > "$FILE" +else + if [[ -s "$TMPERR" ]]; then + TV="$(tidy --version)" + printf '\n' "$TV" + sed 's/^\(.*\)$//' "$TMPERR" + fi + cat "$TMPOUT" fi -#echo "grep exit: $?" + +exit $EXITCODE From 284a0fe3db791d7559227fb6fa9c374a4cf83762 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Sat, 14 Dec 2024 13:14:55 -0500 Subject: [PATCH 6/6] Add better comments --- btidy.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/btidy.sh b/btidy.sh index 90ab8dc..00457a9 100755 --- a/btidy.sh +++ b/btidy.sh @@ -5,8 +5,16 @@ # Use HTML tidy on just the body of an HTML file. # See https://www.html-tidy.org/ for documentation on tidy. # +# When used as a filter, this will enclose each line of tidy output in +# an HTML comment. +# # Usage: -# btidy [options] ... +# ./btidy.sh [options] ... +# +# # From vi family editors, assuming btidy.sh is in your path: +# :% ! btidy.sh [options] +# # vi example in a marked section: +# :'a,'b ! btidy.sh -i # # Copyright (C) 2024 by The Obscure Organization #