openssl-update-copyright 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License 2.0 (the "License"). You may not use
  6. # this file except in compliance with the License. You can obtain a copy
  7. # in the file LICENSE in the source distribution or at
  8. # https://www.openssl.org/source/license.html
  9. myname="$(basename $0)"
  10. this_year="$(date '+%Y')"
  11. some_year="[12][0-9][0-9][0-9]"
  12. year_range="(${some_year})(-${some_year})?"
  13. copyright_owner="The OpenSSL Project"
  14. copyright="Copyright .*${year_range} .*${copyright_owner}"
  15. # sed_script:
  16. # for all lines that contain ${copyright} : {
  17. # replace years yyyy-zzzz (or year yyyy) by yyyy-${this_year}
  18. # replace repeated years yyyy-yyyy by yyyy
  19. # }
  20. sed_script="/${copyright}/{ s/${year_range}/\1-${this_year}/ ; s/(${some_year})-\1/\1/ }"
  21. function usage() {
  22. cat >&2 <<EOF
  23. usage: $myname [-h|--help] [file|directory] ...
  24. Updates the year ranges of all OpenSSL copyright statements in the given
  25. files or directories. (Directories are traversed recursively.)
  26. EOF
  27. }
  28. if [ $# -eq 0 ]; then
  29. usage
  30. exit 0
  31. fi
  32. for arg in "$@"; do
  33. case $arg in
  34. -h|--help)
  35. usage
  36. exit 0
  37. ;;
  38. -*)
  39. echo -e "illegal option: $arg\n" >& 2
  40. usage
  41. exit 1
  42. ;;
  43. *)
  44. if [ -f "$arg" ]; then
  45. sed -E -i "${sed_script}" "$arg"
  46. elif [ -d "$arg" ]; then
  47. find "$arg" -name '.[a-z]*' -prune -o -type f -exec sed -E -i "${sed_script}" {} +
  48. else
  49. echo "$arg: no such file or directory" >&2
  50. fi
  51. ;;
  52. esac
  53. done