|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This script detects non-compliant licenses in the output of language-specific license checkers. |
| 4 | + |
| 5 | +# These licenses are allowed. |
| 6 | +# These are the exact and complete license strings for 100% legal certainty, no regexes. |
| 7 | +ALLOWED_LICENSES=( |
| 8 | + '0BSD' |
| 9 | + 'AFLv2.1' |
| 10 | + 'AFLv2.1,BSD' |
| 11 | + '(AFL-2.1 OR BSD-3-Clause)' |
| 12 | + 'Apache 2.0' |
| 13 | + 'Apache-2.0' |
| 14 | + '(Apache-2.0 OR MPL-1.1)' |
| 15 | + 'Apache-2.0 AND MIT' |
| 16 | + 'Apache License, Version 2.0' |
| 17 | + 'Apache*' |
| 18 | + 'Artistic-2.0' |
| 19 | + 'BlueOak-1.0.0' |
| 20 | + 'BSD' |
| 21 | + 'BSD*' |
| 22 | + 'BSD-2-Clause' |
| 23 | + '(BSD-2-Clause OR MIT OR Apache-2.0)' |
| 24 | + 'BSD-3-Clause' |
| 25 | + '(BSD-3-Clause OR GPL-2.0)' |
| 26 | + 'BSD-3-Clause OR MIT' |
| 27 | + 'CC0-1.0' |
| 28 | + 'CC-BY-3.0' |
| 29 | + 'CC-BY-4.0' |
| 30 | + '(CC-BY-4.0 AND MIT)' |
| 31 | + 'ISC' |
| 32 | + 'ISC*' |
| 33 | + 'LGPL-2.1' # LGPL allows commercial use, requires only that modifications to LGPL-protected libraries are published under a GPL-compatible license |
| 34 | + 'MIT' |
| 35 | + 'MIT*' |
| 36 | + 'MIT-0' |
| 37 | + 'MIT AND ISC' |
| 38 | + '(MIT AND BSD-3-Clause)' |
| 39 | + '(MIT AND Zlib)' |
| 40 | + '(MIT OR Apache-2.0)' |
| 41 | + '(MIT OR CC0-1.0)' |
| 42 | + '(MIT OR GPL-2.0)' |
| 43 | + 'MPL-2.0' |
| 44 | + '(MPL-2.0 OR Apache-2.0)' |
| 45 | + 'Public Domain' |
| 46 | + 'Python-2.0' # the Python-2.0 is a permissive license, see https://en.wikipedia.org/wiki/Python_License |
| 47 | + 'Unlicense' |
| 48 | + 'WTFPL' |
| 49 | + 'WTFPL OR ISC' |
| 50 | + '(WTFPL OR MIT)' |
| 51 | + '(MIT OR WTFPL)' |
| 52 | + 'LGPL-3.0-or-later' # Requires only that modifications to LGPL-protected libraries are published under a GPL-compatible license which is not the case at Ory |
| 53 | +) |
| 54 | + |
| 55 | +# These modules don't work with the current license checkers |
| 56 | +# and have been manually verified to have a compatible license (regex format). |
| 57 | +APPROVED_MODULES=( |
| 58 | + 'https://github.com/ory-corp/cloud/' # Ory IP |
| 59 | + 'github.com/ory/hydra-client-go' # Apache-2.0 |
| 60 | + 'github.com/ory/hydra-client-go/v2' # Apache-2.0 |
| 61 | + 'github.com/ory/kratos-client-go' # Apache-2.0 |
| 62 | + 'github.com/gobuffalo/github_flavored_markdown' # MIT |
| 63 | + '[email protected]' # MIT: original source at http://github.com/substack/node-bufferlist is deleted but a fork at https://github.com/pkrumins/node-bufferlist/blob/master/LICENSE contains the original license by the original author (James Halliday) |
| 64 | + 'https://github.com/iconify/iconify/packages/react' # MIT: license is in root of monorepo at https://github.com/iconify/iconify/blob/main/license.txt |
| 65 | + 'github.com/gobuffalo/.*' # MIT: license is in root of monorepo at https://github.com/gobuffalo/github_flavored_markdown/blob/main/LICENSE |
| 66 | + 'github.com/ory-corp/cloud/.*' # Ory IP |
| 67 | + 'github.com/golang/freetype/.*' # FreeType license: https://freetype.sourceforge.net/FTL.TXT |
| 68 | + 'go.opentelemetry.io/otel/exporters/jaeger/internal/third_party/thrift/lib/go/thrift' # Incorrect detection, actually Apache-2.0: https://github.com/open-telemetry/opentelemetry-go/blob/exporters/jaeger/v1.17.0/exporters/jaeger/internal/third_party/thrift/LICENSE |
| 69 | + 'go.uber.org/zap/exp/.*' # MIT license is in root of exp folder in monorepo at https://github.com/uber-go/zap/blob/master/exp/LICENSE |
| 70 | + 'github.com/ory/client-go' # Apache-2.0 |
| 71 | + 'github.com/ian-kent/linkio' # BSD - https://github.com/ian-kent/linkio/blob/97566b8728870dac1c9863ba5b0f237c39166879/linkio.go#L1-L3 |
| 72 | + 'github.com/t-k/fluent-logger-golang/fluent' # Apache-2.0 https://github.com/t-k/fluent-logger-golang/blob/master/LICENSE |
| 73 | + 'github.com/jmespath/go-jmespath' # Apache-2.0 https://github.com/jmespath/go-jmespath/blob/master/LICENSE |
| 74 | + 'github.com/ory/keto/proto/ory/keto/opl/v1alpha1' # Apache-2.0 - submodule of keto |
| 75 | + 'github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2' # Apache-2.0 - submodule of keto |
| 76 | +) |
| 77 | + |
| 78 | +# These lines in the output should be ignored (plain text, no regex). |
| 79 | +IGNORE_LINES=( |
| 80 | + '"module name","licenses"' # header of license output for Node.js |
| 81 | +) |
| 82 | + |
| 83 | +echo_green() { |
| 84 | + printf "\e[1;92m%s\e[0m\n" "$@" |
| 85 | +} |
| 86 | + |
| 87 | +echo_red() { |
| 88 | + printf "\e[0;91m%s\e[0m\n" "$@" |
| 89 | +} |
| 90 | + |
| 91 | +# capture STDIN |
| 92 | +input=$(cat -) |
| 93 | + |
| 94 | +# remove ignored lines |
| 95 | +for ignored in "${IGNORE_LINES[@]}"; do |
| 96 | + input=$(echo "$input" | grep -vF "$ignored") |
| 97 | +done |
| 98 | + |
| 99 | +# remove pre-approved modules |
| 100 | +for approved in "${APPROVED_MODULES[@]}"; do |
| 101 | + input=$(echo "$input" | grep -v "\"${approved}\"") |
| 102 | + input=$(echo "$input" | grep -v "\"Custom: ${approved}\"") |
| 103 | +done |
| 104 | + |
| 105 | +# remove allowed licenses |
| 106 | +for allowed in "${ALLOWED_LICENSES[@]}"; do |
| 107 | + input=$(echo "$input" | grep -vF "\"${allowed}\"") |
| 108 | +done |
| 109 | + |
| 110 | +# anything left in the input at this point is a module with an invalid license |
| 111 | + |
| 112 | +# print outcome |
| 113 | +if [ -z "$input" ]; then |
| 114 | + echo_green "Licenses are okay." |
| 115 | +else |
| 116 | + echo_red "Unknown licenses found!" |
| 117 | + echo "$input" |
| 118 | + exit 1 |
| 119 | +fi |
0 commit comments