canary-rs/check_licenses.sh

39 lines
1.1 KiB
Bash
Raw Normal View History

2022-11-03 02:25:04 +00:00
#!/bin/sh
2022-11-12 04:56:48 +00:00
set -e
# check if we have tomcat(1)
if ! command -v tomcat >/dev/null 2>&1; then
printf "%s: Missing dependency: tomcat(1)\n"
exit 69 # sysexits(3) EX_UNAVAILABLE
2022-11-12 06:22:37 +00:00
fi
2022-11-16 06:25:08 +00:00
dir="$(pwd | sed 's/\//\n/g' | tail -n 1)"
for toml in $(find "$PWD" -name "Cargo.toml"); do
printf "Project: %s\n" "$(tomcat package.name "$toml")"
toml_lic="$(tomcat package.license "$toml")"
if ! test -n "$toml_lic"; then
printf "%s: Missing license information\n" "$(printf "%s\n" "$toml" |\
sed "s/^.\+$dir\///g")"
continue 2
fi
2022-11-16 06:25:08 +00:00
for file in $(find "$(printf "%s\n" "$toml" |\
sed 's/Cargo\.toml/src/g')" -name "*.rs")
do
info="$(head -n 2 "$file")"
if ! [ "$toml_lic" = "$(printf "%s\n" "$info" | tail -n 1 |\
sed -n 's/\/\/ SPDX-License-Identifier: //p')" ]
then
2022-11-16 06:25:08 +00:00
printf "%s: Missing or malformed license information\n" \
"$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")"
fi
if ! test -n "$(printf "%s\n" "$info" | head -n 1 |\
sed -n '/\/\/ Copyright (c) .\+/p')"
2022-11-12 08:11:20 +00:00
then
2022-11-16 06:25:08 +00:00
printf "%s: Missing or malformed copyright holder information\n" \
"$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")"
2022-11-12 08:11:20 +00:00
fi
done
done