From 2089bd407937828abde3de41e7136a0ea2c18431 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 27 Nov 2022 02:53:19 -0500 Subject: [PATCH] removed tabs & added stderr redirections --- check_licenses.sh | 61 +++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/check_licenses.sh b/check_licenses.sh index 19da131..1f5710f 100755 --- a/check_licenses.sh +++ b/check_licenses.sh @@ -2,37 +2,46 @@ set -e +# check usage +if ! test -n "$1"; then + printf "Usage: %s [pattern...]\n" "$0" 2>&1 + exit 64 # sysexits(3) EX_USAGE +fi + # 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 + printf "%s: Missing dependency: tomcat(1)\n" 2>&1 + exit 69 # sysexits(3) EX_UNAVAILABLE fi 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 - 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 - 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')" - then - printf "%s: Missing or malformed copyright holder information\n" \ - "$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")" - fi - done + + 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")" 2>&1 + continue + fi + + 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 + printf "%s: Missing or malformed license information\n" \ + "$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")" 2>&1 + fi + + if ! test -n "$(printf "%s\n" "$info" | head -n 1 |\ + sed -n '/\/\/ Copyright (c) .\+/p')" + then + printf "%s: Missing or malformed copyright holder information\n" \ + "$(printf "%s\n" "$file" | sed "s/^.\+$dir\///g")" 2>&1 + fi + done done