-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathcheck_copyright.sh
More file actions
executable file
·70 lines (63 loc) · 2.15 KB
/
check_copyright.sh
File metadata and controls
executable file
·70 lines (63 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# Copyright (c) 2020 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the COPYING file.
# This script checks if all the changed files in current revision
# have proper copyright headers
#
# Usage: ./check_copyright [<branch>]
#
# branch is optional - you can provide base branch manually (e.g `trunk`)
# otherwise it would use `git log --first-parent`
# egrep that comes with our Linux distro doesn't like \d, so use [0-9]
notice='Copyright \(c\) 20[0-9][0-9] Arista Networks, Inc.'
apacheNotice='Use of this source code is governed by the Apache License 2.0'
apacheNoticeSource='that can be found in the COPYING file.'
confidential='Confidential and Proprietary'
generatedCodePaths='(^arista|^fmp).*'
copyrightCheck='.*(check_copyright.sh)'
# To omit dubious ownership git errors
repoFolder=`dirname "${BASH_SOURCE[0]}"`
cd $repoFolder && git config --global --add safe.directory $repoFolder
if [ ! -z "$1" ]; then
branchBaseCommit=`git show $1 --format=format:%H --no-patch`
exitCode=$?
if [ $exitCode != "0" ]; then
echo Error finding revision $1
exit $exitCode
fi
else
branchBaseCommit=`git show --first-parent --format=format:%H --no-patch`
fi
files=`git diff-tree --no-commit-id --name-only --diff-filter=ACMR -r $branchBaseCommit | \
egrep '\.(go|proto|py|sh)$' | \
grep -v '_pb2\.py$' | \
grep -v '_pb2_grpc\.py$' |\
grep -v 'docsrc/'`
status=0
for file in $files; do
if egrep -q "$confidential" $file ; then
# Need to omit the check_copyright script from this check as it will always fail
if [[ "$file" =~ $copyrightCheck ]] ; then
continue
fi
echo "$file: use of confidential material per copyright notice"
status=1
fi
if ! egrep -q "$notice" $file; then
echo "$file: missing or incorrect copyright notice for Arista"
status=1
fi
if [[ "$file" =~ $generatedCodePaths ]]; then
continue
fi
if ! egrep -q "$apacheNotice" $file ; then
echo "$file: missing or incorrect Apache Licence 2.0 notice"
status=1
fi
if ! egrep -q "$apacheNoticeSource" $file ; then
echo "$file: missing or incorrect Apache Licence 2.0 notice COPYING directive"
status=1
fi
done
exit $status