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

     1  #!/bin/bash
     2  #
     3  # Checks that source files (.go and .proto) don't import known forks
     4  # of other packages by mistake.
     5  set -eu
     6  
     7  check_import() {
     8    local path="$1"
     9  
    10    local result=$(grep -Hne '\("github.com/gogo/protobuf/proto"\|"golang.org/x/net/context"\)' "$path")
    11    if [[ ! -z "${result}" ]]; then
    12      echo "$result - import of forked library"
    13      return 1
    14    fi
    15  }
    16  
    17  check_blacklist() {
    18    local path="$1"
    19  
    20    local result=$(grep -Hne '\("github.com/google/certificate-transparency-go/trillian.*"\)' "$path")
    21    if [[ ! -z "${result}" ]]; then
    22      echo "$result - importing CT specific code into generic repo is not allowed"
    23      return 1
    24    fi
    25  }
    26  
    27  main() {
    28    if [[ $# -lt 1 ]]; then
    29      echo "Usage: $0 <path>"
    30      exit 1
    31    fi
    32  
    33    local code=0
    34    while [[ $# -gt 0 ]]; do
    35      local path="$1"
    36      if [[ -d "$path" ]]; then
    37        for f in "$path"/*.{go,proto}; do
    38          if [[ ! -f "$f" ]]; then
    39            continue  # Empty glob
    40          fi
    41          check_import "$f" || code=1
    42          check_blacklist "$f" || code=1
    43        done
    44      else
    45        check_import "$path" || code=1
    46        check_blacklist "$path" || code=1
    47      fi
    48      shift
    49    done
    50    exit $code
    51  }
    52  
    53  main "$@"