- Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathdeplicense.sh
executable file
·119 lines (98 loc) · 3.15 KB
/
deplicense.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
# Copyright 2017 The Cockroach Authors.
#
# Use of this software is governed by the CockroachDB Software License
# included in the /LICENSE file.
set -euo pipefail
# Output the license info for the current directory's dependencies.
#
# The output is sorted by package name:
# <package-repo-root> <license info>
functionisApache2() {
# The first pair of patterns matches the apache license itself; the
# last is the header that some projects use in place of the full
# license.
(grep -q '[[:space:]]*Apache License'"$1"&& \
grep -q '[[:space:]]*Version 2\.0,'"$1") || \
grep -q '^Licensed under the Apache License, Version 2.0 (the "License")'"$1"
}
functionisBSD2Clause() {
grep -q 'Redistributions of source code must retain the above copyright'"$1"&& \
grep -q 'list of conditions and the following disclaimer'"$1"&&
grep -q 'Redistributions in binary form must reproduce the above'"$1"
}
functionisBSD3Clause() {
egrep -q 'Neither the name of .* nor the names of its'"$1"
}
functionisBSD4Clause() {
grep -q 'All advertising materials mentioning features'"$1"
}
functionisLGPLV3() {
grep -q '[[:space:]]*GNU LESSER GENERAL PUBLIC LICENSE'"$1"&& \
grep -q '[[:space:]]Version 3'"$1"
}
functionisMIT() {
if grep -q 'MIT License'"$1";then
return 0
fi
grep -q 'Permission is hereby granted, free of charge, to any person'"$1"&& \
grep -q 'The above copyright notice and this permission notice'"$1"
}
functionisCC0() {
grep -q 'This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication'"$1"
}
functionisMPL2() {
grep -q '^Mozilla Public License Version 2.0'"$1"|| \
grep -q 'http://mozilla.org/MPL/2.0/'"$1"
}
functionisISC() {
grep -q '^ISC License$'"$1"
}
functioninspect() {
local dir="$1"
local files="$(ls ${dir}/{LICENSE,COPYING} 2>/dev/null)"
files="${files}$(ls ${dir}/LICEN[CS]E.{md,txt,code} 2>/dev/null)"
files="${files}$(ls ${dir}/*/{LICENSE,COPYING} 2>/dev/null)"
forfilein$files;do
if [ -e"${file}" ];then
if isApache2 "${file}";then
echo"Apache License 2.0"
return
elif isBSD2Clause "${file}";then
if isBSD4Clause "${file}";then
echo"BSD 4-Clause License"
elif isBSD3Clause "${file}";then
echo"BSD 3-Clause License"
else
echo"BSD 2-Clause License"
fi
return
elif isLGPLV3 "${file}";then
echo"GNU Lesser General Public License 3.0"
return
elif isMIT "${file}";then
echo"MIT License"
return
elif isCC0 "${file}";then
echo"Creative Commons CC0"
return
elif isMPL2 "${file}";then
echo"Mozilla Public License 2.0"
return
elif isISC "${file}";then
echo"ISC license"
return
fi
# TODO(pmattis): This is incomplete. Add other license
# detectors as necessary.
break
fi
done
echo"unable to determine license"
}
make -k vendor_rebuild
pkgs=$(grep '^ name = ' Gopkg.lock | cut -d'"' -f2)
forpkgin${pkgs};do
info=$(inspect "vendor/${pkg}")
printf"%-50s %s\n""${pkg}""${info}"
done