Skip to content

Instantly share code, notes, and snippets.

@markcaudill
Last active September 30, 2022 18:35
Show Gist options
  • Save markcaudill/e2bc8d275a2f1a4a50b99f2755f35fa0 to your computer and use it in GitHub Desktop.
Save markcaudill/e2bc8d275a2f1a4a50b99f2755f35fa0 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o pipefail
PREREQS=(curl fmt jq)
usage() {
cat <<USAGE
Usage: ${0##*/} [-h] [ID]
Generate a LICENSE.txt file.
-h This message
ID The SPDX license identifier (default LGPL-3.0-or-later)
A list of available identifiers is available at <https://spdx.org/licenses/>
USAGE
}
# Make sure prereq commands are available
for cmd in "${PREREQS[@]}"; do
if ! command -v "${cmd}" &>/dev/null; then
echo "${cmd} command not found"
exit 1
fi
done
# Parse options
while getopts "h" opt; do
case ${opt} in
h) usage && exit 0;;
*) usage && exit 1;;
esac
done
shift $((OPTIND - 1))
# Get the license
curl -s "https://spdx.org/licenses/${1:-LGPL-3.0-or-later}.json" \
| jq -r '.licenseText' \
| fmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment