check_license_headers.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
  4. # Use of this source code is governed by a BSD-style
  5. # license that can be found in the LICENSE file.
  6. #
  7. # check_license_headers.sh checks that all Go files in the given
  8. # directory tree have a correct-looking Tailscale license header.
  9. check_file() {
  10. got=$1
  11. for year in `seq 2019 2021`; do
  12. want=$(cat <<EOF
  13. // Copyright (c) $year Tailscale Inc & AUTHORS All rights reserved.
  14. // Use of this source code is governed by a BSD-style
  15. // license that can be found in the LICENSE file.
  16. EOF
  17. )
  18. if [ "$got" = "$want" ]; then
  19. return 0
  20. fi
  21. done
  22. return 1
  23. }
  24. if [ $# != 1 ]; then
  25. echo "Usage: $0 rootdir" >&2
  26. exit 1
  27. fi
  28. fail=0
  29. for file in $(find $1 -name '*.go' -not -path '*/.git/*'); do
  30. case $file in
  31. $1/tempfork/*)
  32. # Skip, tempfork of third-party code
  33. ;;
  34. $1/wgengine/router/ifconfig_windows.go)
  35. # WireGuard copyright.
  36. ;;
  37. *)
  38. header="$(head -3 $file)"
  39. if ! check_file "$header"; then
  40. fail=1
  41. echo "${file#$1/} doesn't have the right copyright header:"
  42. echo "$header" | sed -e 's/^/ /g'
  43. fi
  44. ;;
  45. esac
  46. done
  47. if [ $fail -ne 0 ]; then
  48. exit 1
  49. fi