check_license_headers.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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' -or -name '*.tsx' -or -name '*.ts' -not -name '*.config.ts' \) -not -path '*/.git/*' -not -path '*/node_modules/*'); 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. $1/util/winutil/subprocess_windows_test.go)
  46. # Subprocess test harness code
  47. ;;
  48. $1/util/winutil/testdata/testrestartableprocesses/main.go)
  49. # Subprocess test harness code
  50. ;;
  51. *$1/k8s-operator/apis/v1alpha1/zz_generated.deepcopy.go)
  52. # Generated kube deepcopy funcs file starts with a Go build tag + an empty line
  53. header="$(head -5 $file | tail -n+3 )"
  54. ;;
  55. $1/derp/xdp/bpf_bpfe*.go)
  56. # Generated eBPF management code
  57. ;;
  58. *)
  59. header="$(head -2 $file)"
  60. ;;
  61. esac
  62. if [ ! -z "$header" ]; then
  63. if ! check_file "$header"; then
  64. fail=1
  65. echo "${file#$1/} doesn't have the right copyright header:"
  66. echo "$header" | sed -e 's/^/ /g'
  67. fi
  68. fi
  69. done
  70. if [ $fail -ne 0 ]; then
  71. exit 1
  72. fi