2018-03-23 19:50:16 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2018-06-10 15:39:23 +00:00
|
|
|
source ${HOME}/bin/script_framework.sh
|
|
|
|
|
|
|
|
[ -z "${1:-}" ] && {
|
|
|
|
LICENSES=$(curl -sSLf -H 'Accept: application/vnd.github.drax-preview+json' https://api.github.com/licenses | jq -r '.[] | .key' | sort | xargs)
|
|
|
|
info "Supported licenses: ${LICENSES}"
|
|
|
|
info "No license was choosen, falling back to apache-2.0"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2018-06-10 14:22:09 +00:00
|
|
|
LICENSE=${1:-apache-2.0}
|
|
|
|
|
|
|
|
# Download LICENSE template for selected license
|
2018-03-23 19:50:16 +00:00
|
|
|
curl -sSLf -H 'Accept: application/vnd.github.drax-preview+json' \
|
2018-06-10 14:22:09 +00:00
|
|
|
https://api.github.com/licenses/${LICENSE} | jq -r '.body' >LICENSE
|
2018-03-23 19:50:16 +00:00
|
|
|
|
|
|
|
# Replace copyright stub with real data
|
|
|
|
NAME=$(git config --global user.name)
|
|
|
|
MAIL=$(git config --global user.email)
|
|
|
|
|
|
|
|
# Look for the first commit as the start year for the license
|
|
|
|
start_year=$(date +%Y)
|
|
|
|
first_commit=$(git rev-list --max-parents=0 HEAD 2>/dev/null || echo "")
|
|
|
|
[ -n "${first_commit}" ] && start_year=$(git log --format="%cd" --date="format:%Y" "${first_commit}")
|
|
|
|
|
2018-06-10 15:39:23 +00:00
|
|
|
case ${LICENSE} in
|
|
|
|
"apache-2.0")
|
|
|
|
sed -i "s/Copyright \[yyyy\] \[name of copyright owner\]/Copyright ${start_year}- ${NAME} <${MAIL}>/" LICENSE
|
|
|
|
;;
|
|
|
|
|
|
|
|
"bsd-2-clause") ;&
|
|
|
|
"bsd-3-clause")
|
|
|
|
sed -i "s/Copyright (c) \[year\], \[fullname\]/Copyright (c) ${start_year}-, ${NAME} <${MAIL}>/" LICENSE
|
|
|
|
;;
|
|
|
|
|
|
|
|
"mit")
|
|
|
|
sed -i "s/Copyright (c) \[year\] \[fullname\]/Copyright (c) ${start_year}- ${NAME} <${MAIL}>/" LICENSE
|
|
|
|
;;
|
|
|
|
esac
|
2018-06-10 14:22:09 +00:00
|
|
|
|
2018-06-10 15:39:23 +00:00
|
|
|
info "Generated license \"${LICENSE}\" with copyright information \"${start_year}- ${NAME} <${MAIL}>\" if applicable"
|