github.com/letsencrypt/trillian@v1.1.2-0.20180615153820-ae375a99d36a/scripts/check_license.sh (about)

     1  #!/bin/bash
     2  #
     3  # Checks that source files (.go and .proto) have the Apache License header.
     4  # Automatically skips generated files.
     5  set -eu
     6  
     7  check_license() {
     8    local path="$1"
     9  
    10    if head -1 "$path" | grep -iq 'generated by'; then
    11      return 0
    12    fi
    13  
    14    # Look for "Apache License" on the file header
    15    if ! head -10 "$path" | grep -q 'Apache License'; then
    16      # Format: $path:$line:$message
    17      echo "$path:10:license header not found"
    18      return 1
    19    fi
    20  }
    21  
    22  main() {
    23    if [[ $# -lt 1 ]]; then
    24      echo "Usage: $0 <path>"
    25      exit 1
    26    fi
    27  
    28    local code=0
    29    while [[ $# -gt 0 ]]; do
    30      local path="$1"
    31      if [[ -d "$path" ]]; then
    32        for f in "$path"/*.{go,proto}; do
    33          if [[ ! -f "$f" ]]; then
    34            continue  # Empty glob
    35          fi
    36          check_license "$f" || code=1
    37        done
    38      else
    39        check_license "$path" || code=1
    40      fi
    41      shift
    42    done
    43    exit $code
    44  }
    45  
    46  main "$@"