From 9d48e187cd2cf0ce7aaf7b41bf4d8e94dd03b629 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 May 2020 20:41:08 -0500 Subject: Initial commit --- licenser | 144 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100755 licenser (limited to 'licenser') diff --git a/licenser b/licenser new file mode 100755 index 0000000..260724e --- /dev/null +++ b/licenser @@ -0,0 +1,144 @@ +#!/bin/bash +# licenser: do a license + +# defaults +__DEFAULT_LICENSE=MIT +: "${LICENSER_LICENSE:=$__DEFAULT_LICENSE}" + +# entry point +licenser() { + while getopts hly:a:o: OPT; do + case "$OPT" in + h) + usage + exit 0 + ;; + l) + list_licenses + exit 0 + ;; + y) __YEAR="$OPTARG-01-01" ;; + a) __AUTHOR="$OPTARG" ;; + o) __OUTPUT="$OPTARG" ;; + *) + usage + exit 1 + ;; + esac + done + shift $((OPTIND - 1)) + __LICENSE="${1:-$LICENSER_LICENSE}" + + # fill in blanks + [[ -z "$__YEAR" ]] && __YEAR="$(date +%F)" + [[ -z "$__AUTHOR" ]] && __AUTHOR="$(git config --get user.name)" + [[ -z "$__AUTHOR" ]] && __AUTHOR="$( + getent passwd "$USER" | awk -F: '{sub(/,+/,"",$5);print $5}' + )" + [[ -z "$__AUTHOR" ]] && __AUTHOR="$USER" + [[ -z "$__OUTPUT" ]] && __OUTPUT=LICENSE + + if ! type "licenser_$__LICENSE" >/dev/null 2>&1; then + echo "Unknown license: $__LICENSE" + echo "Available licenses:" + list_licenses + exit 2 + fi + + if [[ -e "$__OUTPUT" ]]; then + echo "File exists: $__OUTPUT" + exit 3 + fi + + "licenser_$__LICENSE" >"$__OUTPUT" +} + +list_licenses() { + declare -F | awk '/licenser_/{sub(/licenser_/,"",$NF); print $NF;}' +} + +usage() { + cat < + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. +END +} + +# enable sourcing or executing +if [[ ${BASH_SOURCE[0]} == "$0" ]]; then + licenser "$@" +fi -- cgit 1.4.1-21-gabe81