github.com/pvitto98/fabric@v2.1.1+incompatible/scripts/check_license.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp, SecureKey Technologies Inc. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  # shellcheck source=/dev/null
     9  source "$(cd "$(dirname "$0")" && pwd)/functions.sh"
    10  
    11  CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD | tr '\n' ' ')
    12  if [[ -z "$CHECK" ]]; then
    13      CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r "HEAD^..HEAD" | tr '\n' ' ')
    14  fi
    15  
    16  FILTERED=$(filterExcludedAndGeneratedFiles "$CHECK")
    17  if [[ -z "$FILTERED" ]]; then
    18      echo "All files are excluded from having license headers"
    19      exit 0
    20  fi
    21  
    22  missing=$(echo "$FILTERED" | sort -u |  xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier")
    23  if [[ -z "$missing" ]]; then
    24      echo "All files have SPDX-License-Identifier headers"
    25      exit 0
    26  fi
    27  echo "The following files are missing SPDX-License-Identifier headers:"
    28  echo "$missing"
    29  echo
    30  echo "Please replace the Apache license header comment text with:"
    31  echo "SPDX-License-Identifier: Apache-2.0"
    32  
    33  echo
    34  echo "Checking committed files for traditional Apache License headers ..."
    35  missing=$(echo "$missing" | xargs ls -d 2>/dev/null | xargs grep -L "http://www.apache.org/licenses/LICENSE-2.0")
    36  if [[ -z "$missing" ]]; then
    37      echo "All remaining files have Apache 2.0 headers"
    38      exit 0
    39  fi
    40  echo "The following files are missing traditional Apache 2.0 headers:"
    41  echo "$missing"
    42  echo "Fatal Error - All files must have a license header"
    43  exit 1