Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add btidy, misc provisioning script fixes #13

Merged
merged 7 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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](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.
Expand Down
90 changes: 90 additions & 0 deletions btidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env bash
#
# btidy.sh
#
# 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.sh <filename> [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
#
# 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'

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" "$TMPERR"
}
trap finish EXIT

# Nice, thanks https://www.cyberciti.biz/faq/linux-unix-bsd-apple-osx-bash-get-last-argument/
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 <<EOF > "$TMPFILE"
<!doctype html>
<html><head><title>invisible</title></head>
<body>
EOF
cat "$FILE" >> "$TMPFILE"
set +e
# shellcheck disable=SC2048,SC2086
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 '<!-- %s -->\n' "$TV"
sed 's/^\(.*\)$/<!-- \1 -->/' "$TMPERR"
fi
cat "$TMPOUT"
fi

exit $EXITCODE
12 changes: 12 additions & 0 deletions tiamat-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ boost-devel
certbot
certbot python3-certbot-apache
clamav
clamav-milter
clamav-update
clamd
cmake
dnf-automatic
dovecot
Expand All @@ -46,6 +49,7 @@ links
man2html
mariadb
mariadb-server
mailman3
mod_ssl
mpfr-devel
mutt
Expand All @@ -60,6 +64,9 @@ nagios-plugins-swap
nagios-plugins-users
nmstate
nrpe
openarc
opendkim
opendkim-tools
pam-devel
php
php-gd
Expand Down Expand Up @@ -154,10 +161,15 @@ firewall-cmd --runtime-to-permanent

# Start services
services='
clamd@service
clamav-milter
dnf-automatic.timer
httpd
mailman3
mariadb
named
openarc
opendkim
postgresql
saslauthd
sendmail
Expand Down
Loading