summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--LICENSE7
-rwxr-xr-xlicenser144
2 files changed, 151 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f973b4b --- /dev/null +++ b/LICENSE
@@ -0,0 +1,7 @@
1Copyright 2020 Case Duckworth
2
3Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
5The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
7THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/licenser b/licenser new file mode 100755 index 0000000..260724e --- /dev/null +++ b/licenser
@@ -0,0 +1,144 @@
1#!/bin/bash
2# licenser: do a license
3
4# defaults
5__DEFAULT_LICENSE=MIT
6: "${LICENSER_LICENSE:=$__DEFAULT_LICENSE}"
7
8# entry point
9licenser() {
10 while getopts hly:a:o: OPT; do
11 case "$OPT" in
12 h)
13 usage
14 exit 0
15 ;;
16 l)
17 list_licenses
18 exit 0
19 ;;
20 y) __YEAR="$OPTARG-01-01" ;;
21 a) __AUTHOR="$OPTARG" ;;
22 o) __OUTPUT="$OPTARG" ;;
23 *)
24 usage
25 exit 1
26 ;;
27 esac
28 done
29 shift $((OPTIND - 1))
30 __LICENSE="${1:-$LICENSER_LICENSE}"
31
32 # fill in blanks
33 [[ -z "$__YEAR" ]] && __YEAR="$(date +%F)"
34 [[ -z "$__AUTHOR" ]] && __AUTHOR="$(git config --get user.name)"
35 [[ -z "$__AUTHOR" ]] && __AUTHOR="$(
36 getent passwd "$USER" | awk -F: '{sub(/,+/,"",$5);print $5}'
37 )"
38 [[ -z "$__AUTHOR" ]] && __AUTHOR="$USER"
39 [[ -z "$__OUTPUT" ]] && __OUTPUT=LICENSE
40
41 if ! type "licenser_$__LICENSE" >/dev/null 2>&1; then
42 echo "Unknown license: $__LICENSE"
43 echo "Available licenses:"
44 list_licenses
45 exit 2
46 fi
47
48 if [[ -e "$__OUTPUT" ]]; then
49 echo "File exists: $__OUTPUT"
50 exit 3
51 fi
52
53 "licenser_$__LICENSE" >"$__OUTPUT"
54}
55
56list_licenses() {
57 declare -F | awk '/licenser_/{sub(/licenser_/,"",$NF); print $NF;}'
58}
59
60usage() {
61 cat <<END
62licenser: plop a license in there
63
64usage: licenser [-h|-l] [-y YEAR] [-a AUTHOR] [-o FILE] LICENSE
65
66 -h show this help and exit
67 -l list available licenses and exit
68 -y YEAR set the copyright date to YEAR
69 -a AUTHOR set the copyright holder to AUTHOR
70 -o FILE output to FILE
71 LICENSE which license to use
72
73 YEAR defaults to the current year.
74 AUTHOR is guessed by the following, in order:
75 - git config --get user.name
76 - getent passwd \$USER
77 - \$USER
78 FILE defaults to LICENSE in the current directory
79END
80}
81
82year() { date +%Y --date="$__YEAR"; }
83author() { printf '%s\n' "$__AUTHOR"; }
84
85licenser_MIT() {
86 cat <<END
87Copyright $(year) $(author)
88
89Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
90
91The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
92
93THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
94END
95}
96
97licenser_BSD2() {
98 cat <<END
99Copyright $(year) $(author)
100
101Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
102
1031. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
104
1052. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
106
107THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
108END
109}
110
111licenser_ISC() {
112 cat <<END
113Copyright $(year) $(author)
114
115Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
116
117THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
118END
119}
120
121licenser_WTFPL() {
122 cat <<END
123Copyright $(year) $(author) and licensed under the terms of the
124
125 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
126 Version 2, December 2004
127
128 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
129
130 Everyone is permitted to copy and distribute verbatim or modified
131 copies of this license document, and changing it is allowed as long
132 as the name is changed.
133
134 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
135 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
136
137 0. You just DO WHAT THE FUCK YOU WANT TO.
138END
139}
140
141# enable sourcing or executing
142if [[ ${BASH_SOURCE[0]} == "$0" ]]; then
143 licenser "$@"
144fi