fsfe-website/tools/inline-css-finder.sh
Darragh Elliott 519623e5f0
All checks were successful
continuous-integration/drone/pr Build is passing
Only match files tracked by git
2024-08-06 14:27:44 +02:00

50 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# Check dependencies
# =============================================================================
deperrors=''
for depend in git grep xmllint find cat read wc; do
if ! command -v "$depend" >/dev/null 2>&1; then
deperrors="$depend $deperrors"
fi
done
if [ -n "$deperrors" ]; then
cat <<-EOF
The githook script depends on some other programs to function. Not all of
those programs could be located on your system. Please use your package
manager to install the following programs: $deperrors
EOF
exit 1
fi >>/dev/stderr
all_files="$(git ls-files | grep '\.xml\|\.xsl\|\.xhtml')"
style_class_files="$(
echo "$all_files" | while read -r file; do
if xmllint --xpath "//style" "${file}" &>/dev/null; then
echo "$file"
fi
done
)"
style_attribute_files="$(
echo "$all_files" | while read -r file; do
if xmllint --xpath "//@style" "${file}" &>/dev/null; then
echo "$file"
fi
done
)"
cat <<-EOF
The following files contain <style> class:
$style_class_files
$(echo "$style_class_files" | wc -l) files contain style class
--------------------------------------------
The following files contain style attributes:
$style_attribute_files
$(echo "$style_attribute_files" | wc -l) files contain style attribute
EOF