github.com/digitalocean/go-netbox@v0.0.2/scripts/licensecheck.sh (about) 1 #!/bin/bash 2 3 # Verify that the correct license block is present in all Go source 4 # files. 5 IFS=$'\n' read -r -d '' -a EXPECTED <<EndOfLicense 6 // Copyright 2020 The go-netbox Authors. 7 // 8 // Licensed under the Apache License, Version 2.0 (the "License"); 9 // you may not use this file except in compliance with the License. 10 // You may obtain a copy of the License at 11 // 12 // http://www.apache.org/licenses/LICENSE-2.0 13 // 14 // Unless required by applicable law or agreed to in writing, software 15 // distributed under the License is distributed on an "AS IS" BASIS, 16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 // See the License for the specific language governing permissions and 18 // limitations under the License. 19 // 20 EndOfLicense 21 AUTHOR_REGEX='^// Copyright 20[0-9][0-9] The go-netbox Authors\.$' 22 23 # Scan each Go source file for license. 24 EXIT=0 25 GOFILES=$(find . -name "*.go") 26 27 for FILE in $GOFILES; do 28 IFS=$'\n' read -r -d '' -a BLOCK < <(tail -n +3 $FILE | head -n 14) 29 IFS=$'\n' read -r -d '' -a BLOCK2 < <(head -n 14 $FILE) 30 31 tmp_block=${BLOCK[@]:1} 32 tmp_block2=${BLOCK2[@]:1} 33 tmp_expected=${EXPECTED[@]:1} 34 if [[ $tmp_block != $tmp_expected && $tmp_block2 != $tmp_expected ]]; then 35 echo "file missing license: $FILE" 36 EXIT=1 37 fi 38 if ! [[ "${BLOCK[0]}" =~ $AUTHOR_REGEX || "${BLOCK2[0]}" =~ $AUTHOR_REGEX ]]; then 39 echo "file missing author line: $FILE" 40 EXIT=1 41 fi 42 done 43 44 exit $EXIT