Skip to content

Commit a460216

Browse files
License Scripts Added
Signed-off-by: Muthu <muthu.sundaravadivel@in.ibm.com>
1 parent eab7f59 commit a460216

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

scripts/check-license.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
#
3+
# Copyright contributors to the Hyperledger Fabric Operations Console project
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at:
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
19+
20+
cat << EOB > golang_copyright.txt
21+
/*
22+
* Copyright contributors to the Hyperledger Fabric Operations Console project
23+
*
24+
* SPDX-License-Identifier: Apache-2.0
25+
*
26+
* Licensed under the Apache License, Version 2.0 (the "License");
27+
* you may not use this file except in compliance with the License.
28+
* You may obtain a copy of the License at:
29+
*
30+
* http://www.apache.org/licenses/LICENSE-2.0
31+
*
32+
* Unless required by applicable law or agreed to in writing, software
33+
* distributed under the License is distributed on an "AS IS" BASIS,
34+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35+
* See the License for the specific language governing permissions and
36+
* limitations under the License.
37+
*/
38+
39+
EOB
40+
41+
cat << EOB > shell_copyright.txt
42+
#
43+
# Copyright contributors to the Hyperledger Fabric Operations Console project
44+
#
45+
# SPDX-License-Identifier: Apache-2.0
46+
#
47+
# Licensed under the Apache License, Version 2.0 (the "License");
48+
# you may not use this file except in compliance with the License.
49+
# You may obtain a copy of the License at:
50+
#
51+
# http://www.apache.org/licenses/LICENSE-2.0
52+
#
53+
# Unless required by applicable law or agreed to in writing, software
54+
# distributed under the License is distributed on an "AS IS" BASIS,
55+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
56+
# See the License for the specific language governing permissions and
57+
# limitations under the License.
58+
#
59+
60+
EOB
61+
62+
function filterGeneratedFiles {
63+
for f in $@; do
64+
head -n5 $f | grep -qE 'Code generated by.*DO NOT EDIT' || echo $f
65+
done
66+
}
67+
68+
function filterExcludedFiles {
69+
CHECK=`echo "$CHECK" \
70+
| grep -v "^\.build/" \
71+
| grep -v "^\.git/" \
72+
| grep -v "^\.gitignore" \
73+
| grep -v "\.json$" \
74+
| grep -v "\.pem$" \
75+
| grep -v "\.crt$" \
76+
| grep -v "\.txt$" \
77+
| grep -v "\.md$" \
78+
| grep -v "_sk$" \
79+
| grep -v "\.key$" \
80+
| grep -v "\.gen\.go$" \
81+
| grep -v "tools/" \
82+
| grep -v "testdata/" \
83+
| grep -v "vendor/" \
84+
| grep -v "go.mod" \
85+
| grep -v "go.sum" \
86+
| grep -v .secrets.baseline \
87+
| grep -v .pre-commit-config.yaml \
88+
| sort -u`
89+
90+
CHECK=$(filterGeneratedFiles "$CHECK")
91+
}
92+
93+
CHECK=$(git diff --name-only --diff-filter=ACMRTUXB HEAD)
94+
filterExcludedFiles
95+
if [[ -z "$CHECK" ]]; then
96+
CHECK=$(git diff-tree --no-commit-id --name-only --diff-filter=ACMRTUXB -r "HEAD^..HEAD")
97+
filterExcludedFiles
98+
fi
99+
100+
if [[ -z "$CHECK" ]]; then
101+
echo "All files are excluded from having license headers"
102+
exit 0
103+
fi
104+
105+
missing=`echo "$CHECK" | xargs ls -d 2>/dev/null | xargs grep -L "SPDX-License-Identifier: Apache-2.0"`
106+
if [[ -z "$missing" ]]; then
107+
echo "All files have SPDX-License-Identifier: Apache-2.0"
108+
exit 0
109+
fi
110+
111+
TMPFILE="./tmpfile"
112+
113+
for FILE in ${missing}; do
114+
EXT="${FILE##*.}"
115+
echo "Adding copyright notice to $FILE"
116+
if [ "${EXT}" = "go" ]; then
117+
cat golang_copyright.txt ${FILE} > ${TMPFILE}
118+
cat ${TMPFILE} > ${FILE}
119+
rm -f ${TMPFILE}
120+
echo " ${FILE} copyright notice added"
121+
elif [ "${EXT}" = "yaml" ]; then
122+
cat shell_copyright.txt ${FILE} > ${TMPFILE}
123+
cat ${TMPFILE} > ${FILE}
124+
rm -f ${TMPFILE}
125+
echo " ${FILE} copyright notice added"
126+
elif [ "${EXT}" = "sh" ]; then
127+
cat shell_copyright.txt ${FILE} > ${TMPFILE}
128+
cat ${TMPFILE} > ${FILE}
129+
rm -f ${TMPFILE}
130+
echo " ${FILE} copyright notice added"
131+
else
132+
echo "invalid file extension"
133+
fi
134+
done
135+
136+
rm golang_copyright.txt shell_copyright.txt
137+
138+
exit 0

0 commit comments

Comments
 (0)