#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -x
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace

true "INFO: Currently running script: ${BASH_SOURCE[0]} $*"

## Resolve to the repo root regardless of where this script lives or is
## invoked from: the file specified by "${BASH_SOURCE[0]}" is under
## help-steps/, so .. is the repo root.
cd -- "$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")/.."

skip_patterns=(
  COPYING
  copyright
  changelog
  changelog.upstream
  colors
  Banners.ai # binary
  50_common
  derivative.asc # OpenPGP key
  control.authcookie # binary
  mw-wiki-link-archiver # domain name
  archive.today # domain name
  repo-add-dist # contains OpenPGP key
  localectl-list-x11-keymap-layouts-static.txt # auto-generated
  '*/grub.d/*' # forked by upstream. keep diff small.
  '*/auto-generated-man-pages/*' # auto generated
  '*/keys/*' # OpenPGP keys
  '*/tpoarchive-keys.d/*' # OpenPGP keys
  '*/torbrowser-updater-keys.d/*' # OpenPGP keys
  '*/grml-debootstrap/*' # upstream project
  '*/live-build/*' # upstream project
  '*/get-bitcoin-keys*' # a real name
)

ignore_words=(
  te          # color
  ue          # color
  fpr         # fingerprint
  buildd      # build daemon
  SME         # security-misc
  hda         # hard drive
  MERCHANTIBILITY # copyright
  chage       # an application name
  DeVault     # a real name
  DoubleClick # a configuration value
  shotcut     # an actual application
  Commad-Line # style choice
  Ende        # German
  readby      # AppArmor keyword
  bootup      # Acceptable spelling.
)

codespell \
  --skip "$(IFS=,; printf '%s' "${skip_patterns[*]}")" \
  --ignore-words-list "$(IFS=,; printf '%s' "${ignore_words[*]}")"
