#!/usr/bin/env bash # Nothing we add may name the private estate it was written on (the LLeMbas section rule: # "everything public is current-state and estate-free"), as a check that runs on every push. # # This is a fork: WezTerm's own tree has example addresses of its own (ssh tests, docs), and those # are upstream's, not ours. So the check reads only what this fork adds: every line added since the # upstream commit named in `UPSTREAM` (moved on each merge from upstream). This file is the one place # that may spell the patterns, and is skipped. set -euo pipefail cd "$(dirname "$0")/.." base=$(tr -d '[:space:]' < UPSTREAM) git cat-file -e "$base^{commit}" 2>/dev/null || { echo "hygiene: UPSTREAM names $base, which this clone does not have" >&2; exit 2; } patterns=( 'houmeres' '\b[a-z0-9-]+\.lan\b' '\bCT ?2[0-9]{2}\b' '\b10\.0\.0\.[0-9]+' '\b192\.168\.[0-9]+\.[0-9]+' '\bgamebox\b' '\bthor\b' ) # Added lines only, with their file, from the fork point to the working tree (staged or not). added=$(git diff --no-color --unified=0 "$base" -- . ':(exclude)scripts/hygiene.sh' \ | awk '/^\+\+\+ b\//{file=substr($0,7); next} /^\+/ && !/^\+\+\+/{print file": "substr($0,2)}') # And files not yet tracked, which a diff does not show. while IFS= read -r -d '' f; do [ "$f" = scripts/hygiene.sh ] && continue [ -f "$f" ] || continue added+=$'\n'$(awk -v f="$f" '{print f": "$0}' "$f") done < <(git ls-files -z --others --exclude-standard) # What is allowed to match, each for a reason — a line of `file: text` as built above: allowed=( # The package's maintainer address, as a .deb must carry one: the same that signs every commit. '^llembas/packaging/package\.sh: Maintainer: LLeMbas $' ) allow="$(IFS='|'; echo "${allowed[*]}")" added=$(printf '%s\n' "$added" | grep -vE -- "$allow" || true) found=0 for pattern in "${patterns[@]}"; do # grep: 0 = matched, 1 = no match, anything else is an error and must not read as "clean". set +e hits=$(printf '%s\n' "$added" | grep -IEi -- "$pattern") rc=$? set -e if [ "$rc" -eq 0 ]; then printf '%s\n' "$hits" echo "hygiene: the lines above match /$pattern/" >&2 found=1 elif [ "$rc" -ne 1 ]; then echo "hygiene: grep failed on /$pattern/" >&2 exit 2 fi done [ "$found" -eq 0 ] && echo "hygiene: nothing private in what this fork adds (since ${base:0:9})" exit "$found"