blob: bfa62411012a6688b7a79b596efb99cff256a3c3 [file] [log] [blame]
Serge Bazanskicc25bdf2018-10-25 14:02:58 +02001#!/bin/bash
2
3# Verify that the correct license block is present in all Go source
4# files.
5IFS=$'\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.
19EndOfLicense
20AUTHOR_REGEX='^// Copyright 20[0-9][0-9] The go-netbox Authors\.$'
21
22# Scan each Go source file for license.
23EXIT=0
24GOFILES=$(find . -name "*.go")
25
26for 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
41done
42
43exit $EXIT