Skip to content

Instantly share code, notes, and snippets.

@Jimmy-Xu
Last active November 1, 2018 07:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jimmy-Xu/cc44d3f48f7aa59b55a9794fa9eebfd3 to your computer and use it in GitHub Desktop.
Save Jimmy-Xu/cc44d3f48f7aa59b55a9794fa9eebfd3 to your computer and use it in GitHub Desktop.
get vendor of repo
#!/bin/bash
# env
github_api_token=$1
owner=$2
# clean
ls -d */ | xargs -i rm -rf {}
rm -rf repo.txt
# download
for name in $(curl -s "https://api.github.com/orgs/${owner}/repos?access_token=${github_api_token}" | jq -r '.[].name')
do
wget -c -O $name.zip "https://api.github.com/repos/${owner}/$name/zipball?access_token=${github_api_token}"
echo ${name} >> repo.txt
done
# uncompress
while read LINE
do
unzip ${LINE}.zip
done < repo.txt
# stat
mkdir -p result
rm -rf result/*
while read LINE
do
cd ${owner}-${LINE}-*
find . -name vendor -type d| while read v; do find ${v} -name LICENSE |while read l; do rv=${l#*/vendor/}; echo -n "${rv%/LICENSE},,";p=unknown; grep Apache $l >/dev/null && p="Apache 2.0"; grep "MIT License" $l >/dev/null && p="MIT"; grep "Redistributions of source code must retain the above copyright" $l > /dev/null && p="2-Clause BSD" ; [ "$p" = "2-Clause BSD" ] && grep "Neither the name of" $l > /dev/null && p="3-Clause BSD"; grep "Mozilla Public" $l >/dev/null && p="Mozilla MPL"; echo $p ; done; done | sed -e 's/^src\///'|sort|uniq > ../result/${LINE}.txt
cd ..
done < repo.txt
echo "list result"
for f in $(ls result)
do
if [ -s result/$f ];then
ls -l result/$f
fi
done
# get vendor deital with repo
rm -rf result_with_repo.txt
while read LINE
do
f=${LINE}.txt
if [ -s result/$f ];then
cat result/$f | awk -v repo="${owner}/${LINE}" '{printf "%s,%s\n",repo, $0}' >> result_with_repo.txt
fi
done < repo.txt
# get global vendor detail
find . -name vendor -type d| while read v; do find ${v} -name LICENSE |while read l; do rv=${l#*/vendor/}; echo -n "${rv%/LICENSE},,";p=unknown; grep Apache $l >/dev/null && p="Apache 2.0"; grep "MIT License" $l >/dev/null && p="MIT"; grep "Redistributions of source code must retain the above copyright" $l > /dev/null && p="2-Clause BSD" ; [ "$p" = "2-Clause BSD" ] && grep "Neither the name of" $l > /dev/null && p="3-Clause BSD"; grep "Mozilla Public" $l >/dev/null && p="Mozilla MPL"; echo $p ; done; done | sed -e 's/^src\///'|sort|uniq > result_global.txt
echo "see detail result in result_global.txt or result_with_repo.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment