| 1 | #!/bin/bash |
| 2 | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | # You may not use this file except in compliance with the License. |
| 6 | # A copy of the License is located at |
| 7 | # |
| 8 | # http://aws.amazon.com/apache2.0 |
| 9 | # |
| 10 | # or in the "license" file accompanying this file. This file is distributed |
| 11 | # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | # express or implied. See the License for the specific language governing |
| 13 | # permissions and limitations under the License. |
| 14 | # |
| 15 | |
| 16 | set -e |
| 17 | |
| 18 | S2N_FILES=$(find "$PWD" -type f -name "s2n_*.[ch]") |
| 19 | S2N_FILES+=" " |
| 20 | S2N_FILES+=$(find "$PWD"/codebuild/ -type f -name "*.sh") |
| 21 | S2N_FILES+=" " |
| 22 | S2N_FILES+=$(find "$PWD"/codebuild/ -type f -name "*.yml") |
| 23 | S2N_FILES+=" " |
| 24 | S2N_FILES+=$(find "$PWD"/tests/ -type f -name "*.sh") |
| 25 | S2N_FILES+=" " |
| 26 | S2N_FILES+=$(find "$PWD"/tests/integrationv2 -type f -name "*.py") |
| 27 | S2N_FILES+=" " |
| 28 | S2N_FILES+=$(find "$PWD" -type f -name "*.rs" | grep -v target) |
| 29 | |
| 30 | FAILED=0 |
| 31 | |
| 32 | for file in $S2N_FILES; do |
| 33 | # The phrase "Copyright (20xx) Amazon.com, Inc. or its affiliates" should appear at least once in the first 4 lines of every file |
| 34 | COUNT=`head -4 $file | grep -i "Copyright" | grep -i "Amazon.com, Inc. or its affiliates" | wc -l`; |
| 35 | if [ "$COUNT" == "0" ]; |
| 36 | then |
| 37 | FAILED=1; |
| 38 | echo "Copyright Check Failed: $file"; |
| 39 | fi |
| 40 | done |
| 41 | |
| 42 | for file in $S2N_FILES; do |
| 43 | # The Apache 2.0 License should appear in every file |
| 44 | COUNT=`head -5 $file | grep -E "Apache License, Version 2.0|Apache-2.0" | wc -l`; |
| 45 | if [ "$COUNT" == "0" ]; |
| 46 | then |
| 47 | FAILED=1; |
| 48 | echo "License Check Failed: $file"; |
| 49 | fi |
| 50 | done |
| 51 | |
| 52 | if [ $FAILED == 1 ]; |
| 53 | then |
| 54 | printf "\\033[31;1mFAILED Copyright Check\\033[0m\\n" |
| 55 | exit -1 |
| 56 | else |
| 57 | printf "\\033[32;1mPASSED Copyright Check\\033[0m\\n" |
| 58 | fi |