Skip to content

Instantly share code, notes, and snippets.

@hyperupcall
Created July 10, 2020 23:51
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 hyperupcall/b25e2254d67d50d40ee993dde415bad4 to your computer and use it in GitHub Desktop.
Save hyperupcall/b25e2254d67d50d40ee993dde415bad4 to your computer and use it in GitHub Desktop.
Fetch SPDX Licenses
#!/usr/bin/env bash
set -euo pipefail
# little script that extracts some SPDX licenses from the choosealicense.com project using sed and grep.
# this was before i found https://github.com/spdx/license-list-data
# you will very likely have to tweak things to get this to work. it's just a paste of a shell script in one of my repositories that will be removed in the near future
cd ../licenses
licenses="$(curl -o- --silent https://github.com/github/choosealicense.com/tree/gh-pages/_licenses \
| tac | tac | grep -Pio "(?<=gh-pages/_licenses\/).*(?=.txt\">)")"
function doit() {
declare -r license="${1:-"default"}"
test "$license" = "default" && {
echo "license blank. exiting."
exit 1
}
year="2020"
name="Edwin Kofler"
printf "\033[0;94m%s\033[0m\n" "working on $license"
licenseText="$(curl -o- --silent "https://raw.githubusercontent.com/github/choosealicense.com/gh-pages/_licenses/$license.txt")"
licenseText="$(echo "$licenseText" | tr '\n' '~' | sed -E 's/(---~.*---~~)(.*)/\2/g' | tr '~' '\n' | sed "s/\[year\]/$year/" | sed "s/\[fullname\]/$name/")"
echo "$licenseText" >"${license}.txt"
}
# export -f doit
# slow
# for license in $licenses; do
# parallel -P 0 --link --bar --progress --joblog _parallel.log \
# --trim lr \
# doit ::: "$license"
# done
for license in $licenses; do
doit "$license" &
while test "$(jobs -p | wc -w)" -ge 10; do sleep 0.1; done
done
# doesn't work
# parallel -P 0 --link --bar --progress --joblog _parallel.log \
# --trim lr -a $licenses \
# doit ::: {1}
# other
# doit ::: "$(echo "$licenses" | tr " " "\n" | wc -l | xargs seq 1)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment