ClickHouse/utils/list-licenses/list-licenses.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

101 lines
5.4 KiB
Bash
Raw Normal View History

2023-08-21 11:01:08 +00:00
#!/usr/bin/env bash
2020-05-11 01:53:38 +00:00
2024-10-23 20:15:50 +00:00
if [[ "$OSTYPE" == "darwin"* ]]
then
# use GNU versions, their presence is ensured in cmake/tools.cmake
GREP_CMD=ggrep
FIND_CMD=gfind
else
FIND_CMD='find'
GREP_CMD='grep'
fi
2020-05-11 01:53:38 +00:00
ROOT_PATH="$(git rev-parse --show-toplevel)"
LIBS_PATH="${ROOT_PATH}/contrib"
2024-11-19 20:56:16 +00:00
libs=$(echo "${ROOT_PATH}/base/poco"; (find "${LIBS_PATH}" -maxdepth 1 -type d -not -name '*-cmake' -not -name 'rust_vendor' | LC_ALL=C sort) )
for LIB in ${libs}
2024-10-23 20:15:50 +00:00
do
LIB_NAME=$(basename "$LIB")
2020-05-11 01:53:38 +00:00
LIB_LICENSE=$(
2024-10-23 20:15:50 +00:00
LC_ALL=C ${FIND_CMD} "$LIB" -type f -and '(' -iname 'LICENSE*' -or -iname 'COPYING*' -or -iname 'COPYRIGHT*' -or -iname 'NOTICE' ')' -and -not '(' -iname '*.html' -or -iname '*.htm' -or -iname '*.rtf' -or -name '*.cpp' -or -name '*.h' -or -iname '*.json' ')' -printf "%d\t%p\n" |
2021-11-26 02:58:43 +00:00
LC_ALL=C sort | LC_ALL=C awk '
2020-05-11 01:53:38 +00:00
BEGIN { IGNORECASE=1; min_depth = 0 }
/LICENSE/ { if (!min_depth || $1 <= min_depth) { min_depth = $1; license = $2 } }
/COPY/ { if (!min_depth || $1 <= min_depth) { min_depth = $1; copying = $2 } }
2024-10-23 20:15:50 +00:00
/NOTICE/ { if (!min_depth || $1 <= min_depth) { min_depth = $1; notice = $2 } }
END { if (license) { print license } else if (copying) { print copying } else { print notice } }')
2020-05-11 01:53:38 +00:00
2024-10-23 20:15:50 +00:00
if [ -n "$LIB_LICENSE" ]
then
2020-05-11 01:53:38 +00:00
LICENSE_TYPE=$(
(${GREP_CMD} -q -F 'Apache' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "Apache") ||
(${GREP_CMD} -q -F 'Boost' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "Boost") ||
2024-10-23 20:15:50 +00:00
(${GREP_CMD} -q -i -P 'public\s*domain|CC0 1\.0 Universal' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "Public Domain") ||
(${GREP_CMD} -q -F 'BSD' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "BSD") ||
(${GREP_CMD} -q -F 'Lesser General Public License' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "LGPL") ||
2024-10-23 20:15:50 +00:00
(${GREP_CMD} -q -F 'General Public License' "$LIB_LICENSE" &&
echo "GPL") ||
(${GREP_CMD} -q -i -F 'The origin of this software must not be misrepresented' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'Altered source versions must be plainly marked as such' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'This notice may not be removed or altered' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "zLib") ||
2023-05-03 01:12:53 +00:00
(${GREP_CMD} -q -i -F 'This program, "bzip2", the associated library "libbzip2"' "$LIB_LICENSE" &&
echo "bzip2") ||
(${GREP_CMD} -q -i -F 'Permission is hereby granted, free of charge, to any person' "$LIB_LICENSE" &&
2023-05-03 01:12:53 +00:00
${GREP_CMD} -q -i -F 'The above copyright notice and this permission notice shall be' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "MIT") ||
2023-05-03 01:12:53 +00:00
(${GREP_CMD} -q -F 'PostgreSQL' "$LIB_LICENSE" &&
echo "PostgreSQL") ||
(${GREP_CMD} -q -i -F 'Permission to use, copy, modify, and distribute this software for any purpose' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'the name of a copyright holder shall not' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "MIT/curl") ||
2023-05-03 01:12:53 +00:00
(${GREP_CMD} -q -i -F 'OpenLDAP Public License' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'Version 2.8' "$LIB_LICENSE" &&
echo "OpenLDAP Version 2.8") ||
(${GREP_CMD} -q -i -F 'Redistributions of source code must retain the above copyright' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'Redistributions in binary form must reproduce' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'Neither the name' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "BSD 3-clause") ||
(${GREP_CMD} -q -i -F 'Redistributions of source code must retain the above copyright' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'Redistributions in binary form must reproduce' "$LIB_LICENSE" &&
2020-05-11 01:53:38 +00:00
echo "BSD 2-clause") ||
2023-05-03 01:12:53 +00:00
(${GREP_CMD} -q -i -F 'Permission to use, copy, modify, and distribute this software' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'documentation for any purpose and without fee is hereby granted' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'the above copyright notice appear in all copies and that both that copyright' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'notice and this permission notice appear in supporting documentation' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'not be used in advertising or publicity pertaining' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'distribution of the software without specific, written prior permission' "$LIB_LICENSE" &&
${GREP_CMD} -q -i -F 'makes no representations about the suitability of this software' "$LIB_LICENSE" &&
echo "HPND") ||
2020-05-11 01:53:38 +00:00
echo "Unknown")
2024-10-23 20:15:50 +00:00
if [ "$LICENSE_TYPE" == "GPL" ]
then
2024-10-24 01:23:17 +00:00
echo "Fatal error: General Public License found in ${LIB_NAME}." >&2
2024-10-23 20:15:50 +00:00
exit 1
fi
if [ "$LICENSE_TYPE" == "Unknown" ]
then
2024-10-24 01:23:17 +00:00
echo "Fatal error: sources with unknown license found in ${LIB_NAME}." >&2
2024-10-23 20:15:50 +00:00
exit 1
fi
RELATIVE_PATH=$(echo "$LIB_LICENSE" | sed -r -e 's!^.+/(contrib|base)/!/\1/!')
2020-05-11 01:53:38 +00:00
echo -e "$LIB_NAME\t$LICENSE_TYPE\t$RELATIVE_PATH"
fi
done
2024-10-23 20:15:50 +00:00
# Special care for Rust
2024-12-03 12:37:24 +00:00
find "${LIBS_PATH}/rust_vendor/" -name 'Cargo.toml' | xargs ${GREP_CMD} 'license = ' | (${GREP_CMD} -v -P 'MIT|Apache|MPL|ISC|BSD|Unicode|Zlib' && echo "Fatal error: unrecognized licenses in the Rust code" >&2 && exit 1 || true)