check_license_headers.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/sh
  2. #
  3. # Copyright (c) Tailscale Inc & AUTHORS
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. #
  6. # check_license_headers.sh checks that all Go files in the given
  7. # directory tree have a correct-looking Tailscale license header.
  8. check_file() {
  9. got=$1
  10. want=$(cat <<EOF
  11. // Copyright (c) Tailscale Inc & AUTHORS
  12. // SPDX-License-Identifier: BSD-3-Clause
  13. EOF
  14. )
  15. if [ "$got" = "$want" ]; then
  16. return 0
  17. fi
  18. return 1
  19. }
  20. if [ $# != 1 ]; then
  21. echo "Usage: $0 rootdir" >&2
  22. exit 1
  23. fi
  24. fail=0
  25. for file in $(find $1 -name '*.go' -not -path '*/.git/*'); do
  26. case $file in
  27. $1/tempfork/*)
  28. # Skip, tempfork of third-party code
  29. ;;
  30. $1/wgengine/router/ifconfig_windows.go)
  31. # WireGuard copyright.
  32. ;;
  33. $1/cmd/tailscale/cli/authenticode_windows.go)
  34. # WireGuard copyright.
  35. ;;
  36. *_string.go)
  37. # Generated file from go:generate stringer
  38. ;;
  39. $1/control/controlbase/noiseexplorer_test.go)
  40. # Noiseexplorer.com copyright.
  41. ;;
  42. */zsyscall_windows.go)
  43. # Generated syscall wrappers
  44. ;;
  45. *)
  46. header="$(head -2 $file)"
  47. if ! check_file "$header"; then
  48. fail=1
  49. echo "${file#$1/} doesn't have the right copyright header:"
  50. echo "$header" | sed -e 's/^/ /g'
  51. fi
  52. ;;
  53. esac
  54. done
  55. if [ $fail -ne 0 ]; then
  56. exit 1
  57. fi