2020-10-30 13:12:35 +01:00
|
|
|
#!/usr/bin/env bash
|
2014-05-13 16:41:33 +02:00
|
|
|
|
2017-04-20 12:15:36 +02:00
|
|
|
# Copyright 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
2015-09-27 18:58:30 +02:00
|
|
|
# Copyright 2014 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
|
2014-11-28 18:03:38 +01:00
|
|
|
#
|
|
|
|
# This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
# General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
# directory for more details.
|
|
|
|
|
2018-06-05 17:06:11 +02:00
|
|
|
: "${RIOTBASE:=$(cd $(dirname $0)/../../../; pwd)}"
|
|
|
|
cd $RIOTBASE
|
|
|
|
|
|
|
|
: "${RIOTTOOLS:=${RIOTBASE}/dist/tools}"
|
2018-03-22 17:21:09 +01:00
|
|
|
. "${RIOTTOOLS}"/ci/changed_files.sh
|
2017-04-20 12:15:36 +02:00
|
|
|
|
2014-05-13 16:41:33 +02:00
|
|
|
# customizable
|
|
|
|
CHECKROOT=$(dirname "${0}")
|
|
|
|
LICENSEDIR="${CHECKROOT}/patterns"
|
|
|
|
OUTPUT="${CHECKROOT}/out"
|
|
|
|
UNKNOWN="${OUTPUT}/unknown"
|
|
|
|
TMP="${CHECKROOT}/.tmp"
|
|
|
|
|
2015-01-12 03:20:09 +01:00
|
|
|
# Needed for compatibility with BSD sed
|
|
|
|
TAB_CHAR="$(printf '\t')"
|
|
|
|
|
2014-05-13 16:41:33 +02:00
|
|
|
# prepare
|
|
|
|
ROOT=$(git rev-parse --show-toplevel)
|
|
|
|
LICENSES=$(ls "${LICENSEDIR}")
|
|
|
|
EXIT_CODE=0
|
2017-04-20 12:15:36 +02:00
|
|
|
|
|
|
|
: ${ERROR_EXIT_CODE:=1}
|
2014-05-13 16:41:33 +02:00
|
|
|
|
|
|
|
# reset output dir
|
|
|
|
rm -fr "${OUTPUT}"
|
|
|
|
mkdir -p "${OUTPUT}"
|
|
|
|
for LICENSE in ${LICENSES}; do
|
|
|
|
echo -n '' > "${OUTPUT}/${LICENSE}"
|
|
|
|
done
|
|
|
|
|
2017-04-20 12:15:36 +02:00
|
|
|
FILES=$(FILEREGEX='\.([sSch]|cpp)$' changed_files)
|
2014-06-20 17:57:34 +02:00
|
|
|
|
2014-05-13 16:41:33 +02:00
|
|
|
# categorize files
|
2014-06-20 17:57:34 +02:00
|
|
|
for FILE in ${FILES}; do
|
2014-05-13 16:41:33 +02:00
|
|
|
FAIL=1
|
2015-01-12 03:20:09 +01:00
|
|
|
head -100 "${ROOT}/${FILE}" | sed -e 's/[\/\*'"${TAB_CHAR}"']/ /g' -e 's/$/ /' | tr -d '\r\n' | sed -e 's/ */ /g' > "${TMP}"
|
2014-05-13 16:41:33 +02:00
|
|
|
for LICENSE in ${LICENSES}; do
|
|
|
|
if pcregrep -q -f "${LICENSEDIR}/${LICENSE}" "${TMP}"; then
|
|
|
|
echo "${FILE}" >> "${OUTPUT}/${LICENSE}"
|
|
|
|
FAIL=0
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ ${FAIL} = 1 ]; then
|
|
|
|
echo "${FILE}" >> "${UNKNOWN}"
|
2014-06-20 17:57:34 +02:00
|
|
|
echo "file has an unknown license header: '${FILE}'"
|
2014-11-23 10:14:44 +01:00
|
|
|
EXIT_CODE=${ERROR_EXIT_CODE}
|
2014-05-13 16:41:33 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exit ${EXIT_CODE}
|