Serge Bazanski | cc25bdf | 2018-10-25 14:02:58 +0200 | [diff] [blame] | 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 2018 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 | EndOfLicense |
| 20 | AUTHOR_REGEX='^// Copyright 20[0-9][0-9] The go-netbox Authors\.$' |
| 21 | |
| 22 | # Scan each Go source file for license. |
| 23 | EXIT=0 |
| 24 | GOFILES=$(find . -name "*.go") |
| 25 | |
| 26 | for FILE in $GOFILES; do |
| 27 | IFS=$'\n' read -r -d '' -a BLOCK < <(tail -n +3 $FILE | head -n 14) |
| 28 | IFS=$'\n' read -r -d '' -a BLOCK2 < <(head -n 14 $FILE) |
| 29 | |
| 30 | tmp_block=${BLOCK[@]:1} |
| 31 | tmp_block2=${BLOCK2[@]:1} |
| 32 | tmp_expected=${EXPECTED[@]:1} |
| 33 | if [[ $tmp_block != $tmp_expected && $tmp_block2 != $tmp_expected ]]; then |
| 34 | echo "file missing license: $FILE" |
| 35 | EXIT=1 |
| 36 | fi |
| 37 | if ! [[ "${BLOCK[0]}" =~ $AUTHOR_REGEX || "${BLOCK2[0]}" =~ $AUTHOR_REGEX ]]; then |
| 38 | echo "file missing author line: $FILE" |
| 39 | EXIT=1 |
| 40 | fi |
| 41 | done |
| 42 | |
| 43 | exit $EXIT |