diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-03-14 21:26:47 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-03-14 21:26:47 -0400 |
commit | 94cacc84d322429e70485dea49bb858f48aa26c8 (patch) | |
tree | 2d6a493697e8e1b6db655a3bccc0869251db8e97 /modules/blobs/_shlib.sh.m4 | |
parent | 634f61cc8b4e096853c61686ccd535fbd45e9158 (diff) |
stuff
Diffstat (limited to 'modules/blobs/_shlib.sh.m4')
-rw-r--r-- | modules/blobs/_shlib.sh.m4 | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/modules/blobs/_shlib.sh.m4 b/modules/blobs/_shlib.sh.m4 new file mode 100644 index 0000000..567486f --- /dev/null +++ b/modules/blobs/_shlib.sh.m4 @@ -0,0 +1,129 @@ +#!/hint/bash +# Copyright (C) 2009-2010, 2016 Luke Shumaker +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. +# If not, see <http://www.gnu.org/licenses>. + +m4_include(config.sh) + +# + +_() { + if type gettext &>/dev/null; then + TEXTDOMAINDIR=$localedir gettext "$pkgtextdomain" "$1"; + else + printf '%s' "$1"; + fi +} + +# variables: +# - usage[] +# - desc +# - doc (optional) +usage() { + local form + local pfix1="$(_ 'Usage:')" + local pfix2="$(_ ' Or:')" + local pfix="pfix1" + for form in "${usage[@]}"; do + printf '%s %q %q %s\n' "$pfix" "$RVS" "$form" + pfix="$pfix2" + done + printf '%s\n' "$(_ "$desc")" + if [[ -n "$doc" ]] && [[ "$volume" != '-q' ]]; then + printf '\n\n%s\n' "$(_ "$doc")" + fi +} + +# variables: +# - name +# - ver +# - copyright +# - license +# - volume +version() { + declare -A license_name + license_name['GPLv1']='GNU GPL version 1' + license_name['GPLv1+']='GNU GPL version 1 or later' + license_name['GPLv2']='GNU GPL version 2' + license_name['GPLv2+']='GNU GPL version 2 or later' + license_name['GPLv3']='GNU GPL version 3' + license_name['GPLv3+']='GNU GPL version 3 or later' + license_name['LGPLv2']='GNU Library GPL version 2' + license_name['LGPLv2+']='GNU Library GPL version 2 or later' + license_name['LGPLv2.1']='GNU Lesser GPL version 2.1' + license_name['LGPLv2.1+']='GNU Lesser GPL version 2.1 or later' + license_name['LGPLv3']='GNU Lesser GPL version 3' + license_name['LGPLv3+']='GNU Lesser GPL version 3 or later' + licensE_name['AGPLv3']='GNU Affero GPL version 3' + licensE_name['AGPLv3+']='GNU Affero GPL version 3 or later' + declare -A license_url + license_url['GPLv2']='https://gnu.org/licenses/old-licenses/gpl-1.0.html' + license_url['GPLv2']='https://gnu.org/licenses/old-licenses/gpl-2.0.html' + license_url['GPLv3']='https://gnu.org/licenses/gpl.html' + license_url['LGPLv2']='https://gnu.org/licenses/old-licenses/lgpl-2.0.html' + license_url['LGPLv2.1']='https://gnu.org/licenses/old-licenses/lgpl-2.1.html' + license_url['LGPLv3']='https://gnu.org/licenses/lgpl.html' + license_url['AGPLv3']='https://gnu.org/licenses/agpl.html' + + printf "$(_ '%s (RVS) %s\n')" "$name" "$ver" + if [ "$volume" != '-q' ]; then + printf "$(_ 'Copyright (C) %s\n')" "${copyright[@]}" + local url="${license_url[$license]}" + if [[ -z "$url" ]]; then + url="${license_url[${license%+}]}" + fi + printf "$(_ 'License %s: %s <%s>.\n')" "$license" "${license_name[$license]}" "$url" + printf "$(_ \ +'This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extend permitted by law. +')" + if [[ -z "$author" ]] && [[ "${#copyright[@]}" -eq 1 ]]; then + printf -v author "$(_ 'Originally written by %s.')" "$(sed 's/^[0-9, -]*//' <<<"${copyright[0]}")" + fi + if [[ -n "$author" ]]; then + printf '%s\n' "$author" + fi + fi +} + +verbose() { + if [ "$volume" == '-v' ]; then + printf "$(_ "$1")\n" "${@:2}" >&2 + fi +} + +out() { + if [ "$volume" != '-q' ]; then + printf "$(_ "$1")\n" "${@:2}" >&2 + fi +} + +warn() { + printf "$name: $(_ "$1")\n" "${@:2}" >&2 +} + +error() { + warn "$@" + exit 1 +} + +errusage() { + if [[ $# -gt 0 ]]; then + warn "$@" + fi + volume='-q' + usage >&2 + exit 1 +} |