1
0
Fork 0

Add mklicense script

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-03-23 20:50:16 +01:00
parent 96f2d5f695
commit c6528bb871
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

17
bin/mklicense Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail
# Download LICENSE template for Apache 2.0
curl -sSLf -H 'Accept: application/vnd.github.drax-preview+json' \
https://api.github.com/licenses/apache-2.0 | jq -r '.body' >LICENSE
# 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}")
sed -i "s/Copyright \[yyyy\] \[name of copyright owner\]/Copyright ${start_year}- ${NAME} <${MAIL}>/" LICENSE