update-copyright 998 B

1234567891011121314151617181920212223242526272829
  1. #! /bin/bash
  2. #
  3. # Update the libpqxx copyright strings in the current directory.
  4. #
  5. # Usage: update-copyright [year]
  6. #
  7. # Where "year" is the new copyright year. Defaults to the current year.
  8. #
  9. # Assumes GNU grep and GNU sed.
  10. set -eu -o pipefail
  11. # The regexes are a bit awkward because they must work in both grep and sed.
  12. #
  13. # F'rinstance, PREFIX can't include the dash because our replacement string in
  14. # sed would have a backreference (e.g. "\3") immediately followed by a year
  15. # (e.g. 2022), and there's no clear boundary between the backreference number
  16. # and the year: "\32022".
  17. PREFIX='Copyright (c),* 2000'
  18. YEAR='20[0-9][0-9]'
  19. NEW_YEAR="${1:-$(date '+%Y')}"
  20. SUFFIX=',* \(.* and \)*Jeroen T\. Vermeulen'
  21. grep -rIl "$PREFIX-$YEAR$SUFFIX" |
  22. xargs -r sed -i -e "s/\\($PREFIX\\)-$YEAR\\($SUFFIX\\)/\\1-$NEW_YEAR\\2/"
  23. # This one is so different that I'd rather keep it a special case.
  24. sed \
  25. -i \
  26. -e "s/\\(2000\\)-$YEAR\\(,* Jeroen T\\. Vermeulen\\)/\1-$NEW_YEAR\\2/" \
  27. doc/conf.py