Created
September 20, 2018 18:05
-
-
Save robmccoll/240317eceb73e3f4e29ea662e3ea4063 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A hacky bash script that scans Go vendor dirs for licenses. | |
# License checking could probably be improved... | |
CODEDIRS=$(find vendor -name "*.go" | xargs dirname | sort | uniq) | |
LICENSEDIRS=$(find vendor -name LICENSE | xargs dirname) | |
# echo -e "CODE DIRS *********************\n" | |
# echo -n "$CODEDIRS" | |
# echo -e "\n\nLICENSE DIRS *********************\n" | |
# echo -n "$LICENSEDIRS" | |
echo -e "\n\nCHECKING THAT ALL CODE IS LICENSED..." | |
for D in $LICENSEDIRS; do | |
CODEDIRS=$(echo "$CODEDIRS" | grep -v "$D") | |
done | |
echo -e "\n\nREMAINING DIRS *********************\n" | |
echo -n "$CODEDIRS" | |
if [ $(echo -n "$CODEDIRS" | wc -l) -ne 0 ]; then | |
echo -e "\n\n!!! DIRECTORIES NOT COVERED BY A LICENSE WERE FOUND !!!" | |
exit -1 | |
fi | |
echo -e "\n\nCHECKING THAT LICENSES ARE OK..." | |
for D in $LICENSEDIRS; do | |
if [ $(cat $D/LICENSE | grep -i "GNU GENERAL PUBLIC" | wc -l) -ne 0 ]; then | |
echo "$D/LICENSE appears to be GPL..." | |
exit -1 | |
fi | |
if [ $(cat $D/LICENSE | grep -i "Affero" | wc -l) -ne 0 ]; then | |
echo "$D/LICENSE appears to be AGPL..." | |
exit -1 | |
fi | |
APPROVED=0 | |
# APACHE V2 | |
if [ $(cat $D/LICENSE | grep -i "http://www.apache.org/licenses/LICENSE-2.0" | wc -l) -ne 0 ]; then APPROVED=1; fi | |
# BSD | |
if [ $(cat $D/LICENSE | grep -i "* Redistributions of source code must retain the above copyright" | wc -l) -ne 0 ]; then APPROVED=1; fi | |
# MIT | |
if [ $(cat $D/LICENSE | grep -i "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR" | wc -l) -ne 0 ]; then APPROVED=1; fi | |
if [ $APPROVED -ne 1 ]; then | |
echo "$D/LICENSE does not match as approved" | |
exit -1 | |
fi | |
done | |
echo -e "\n\nGENERATING LICENSE FILE..." | |
OUTFILE=license/third_party.go | |
mkdir -p $(dirname $OUTFILE) | |
echo "package license" > $OUTFILE | |
echo "// ThirdPartyLicenses generated from vendor by scripts/license.sh" >> $OUTFILE | |
echo -n "var ThirdPartyLicenses = map[string]string{" >> $OUTFILE | |
for D in $LICENSEDIRS; do | |
echo -n -e "\n\`${D#vendor/}\`: \`" >> $OUTFILE | |
cat $D/LICENSE >> $OUTFILE | |
echo -n "\`," >> $OUTFILE | |
done | |
echo "}" >> $OUTFILE | |
go fmt $OUTFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment