update-copyright-years.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. ## run this script once a year
  3. set -euo pipefail
  4. THIS_YEAR="$(date +'%Y')"
  5. fix_copyright_year() {
  6. local file="$1"
  7. local copyright_line
  8. copyright_line="$(head -2 "$file" | grep -E "Copyright\s\(c\)\s.+\sEMQ" || true)"
  9. if [ -z "$copyright_line" ]; then
  10. ## No Copyright info, it is not intended to add one from this script
  11. echo "Ignored $file"
  12. return 0
  13. fi
  14. local begin_year
  15. begin_year="$(echo "$copyright_line" | sed -E 's#(.*Copyright \(c\)) (20..).*#\2#g')"
  16. if [ "$begin_year" = "$THIS_YEAR" ]; then
  17. ## new file added this year
  18. return 0
  19. fi
  20. sed -E "s#(.*Copyright \(c\) 20..)(-20.. | )(.*)#\1-$THIS_YEAR \3#g" -i "$file"
  21. }
  22. while read -r file; do
  23. if [[ $file != *.erl ]] && \
  24. [[ $file != *.ex ]] && \
  25. [[ $file != *.hrl ]] && \
  26. [[ $file != *.proto ]]; then
  27. ## Ignore other file
  28. continue
  29. fi
  30. fix_copyright_year "$file"
  31. done < <(git ls-files)
  32. fix_copyright_year apps/emqx/NOTICE
  33. fix_copyright_year NOTICE