#!/bin/sh # What this repository adds to BentoPDF's finished build, run in the # Dockerfile's builder stage after `npm run build`: # # finish.sh # # 1. a ' pages=$(find "$dist" -name '*.html' | wc -l) [ "$pages" -gt 100 ] || { echo "finish: only $pages pages in $dist" >&2; exit 1; } find "$dist" -name '*.html' | while read -r page; do grep -q '' "$page" || { echo "finish: $page has no " >&2; exit 1; } sed -i "s##$tag#" "$page" rm -f "$page.gz" "$page.br" gzip -9 -k -n "$page" done # find -exec rather than grep --include, which busybox's grep does not know. tagged=$(find "$dist" -name '*.html' -exec grep -lF "$tag" {} + | wc -l) [ "$tagged" -eq "$pages" ] || { echo "finish: $tagged of $pages pages carry the tag" >&2; exit 1; } stale=$(find "$dist" -name '*.html.br' | wc -l) [ "$stale" -eq 0 ] || { echo "finish: $stale brotli copies left" >&2; exit 1; } for conf in security-headers.conf security-headers-docs.conf; do sed -E -i 's# https?:(//[^ ;"]*)?##g' "$app/$conf" if grep -Eq 'https?:' "$app/$conf"; then echo "finish: $conf still names a host:" >&2 grep -Eo 'https?:[^ ;"]*' "$app/$conf" >&2 exit 1 fi done echo "finish: $tagged pages tagged, CSP without hosts"