summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Makefile10
-rw-r--r--src/lib/common.sh.top19
-rw-r--r--src/lib/conf.sh14
-rwxr-xr-xsrc/lib/libreblacklist16
-rwxr-xr-xsrc/lib/librelib33
-rwxr-xr-xsrc/lib/libremessages81
-rw-r--r--src/lib/libremessages.1.ronn34
7 files changed, 138 insertions, 69 deletions
diff --git a/src/lib/Makefile b/src/lib/Makefile
index 4f24ad3..495abb1 100644
--- a/src/lib/Makefile
+++ b/src/lib/Makefile
@@ -1,5 +1,5 @@
copy_files = common.sh.in
-libexecs = $(filter-out librelib,$(wildcard libre*))
+libexecs = $(filter-out librelib,$(progs))
# include common.sh in libs explicitly, because it might not exist yet
# when the wildcard is performed
libs = $(sort $(wildcard *.sh) common.sh)
@@ -14,7 +14,13 @@ common.sh: %: %.in %.top Makefile
@{ \
cat '$*.top' && \
echo && \
- sed -r -e '/encoding problem/d;/LANG=/d' -e 's/mesg=\$$(.)/mesg="$$(_ "$$\1")"/' '$*.in' && \
+ sed -r \
+ -e '/encoding problem/d;/LANG=/d' \
+ -e 's/mesg=\$$(.)/mesg="$$(_ "$$\1")"/' \
+ -e 's/gettext /_l _ /g' \
+ -e "s/^(\s+)(msg|error) '/\1_l \2 '/" \
+ -e 's|lock\(\)\s*\{|lock()\n{|' \
+ '$*.in' && \
echo && \
cat '$*.bottom' && \
:; } > '$@'
diff --git a/src/lib/common.sh.top b/src/lib/common.sh.top
index 054301b..d45a7dd 100644
--- a/src/lib/common.sh.top
+++ b/src/lib/common.sh.top
@@ -4,23 +4,22 @@
# This file is included by libremessages.
# You should probably use libremessages instead of this.
-# 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; version 2 of the License.
-#
-# 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.
+# License: Unspecified
+
+shopt -s extglob
if [[ -z ${_INCLUDE_COMMON_SH:-} ]]; then
_INCLUDE_COMMON_SH=true
-export TEXTDOMAIN='libretools'
-export TEXTDOMAINDIR='/usr/share/locale'
+[[ -n ${TEXTDOMAIN:-} ]] || export TEXTDOMAIN='libretools'
+[[ -n ${TEXTDOMAINDIR:-} ]] || export TEXTDOMAINDIR='/usr/share/locale'
if type gettext &>/dev/null; then
_() { gettext "$@"; }
else
_() { echo "$@"; }
fi
+
+_l() {
+ TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@"
+}
diff --git a/src/lib/conf.sh b/src/lib/conf.sh
index 561ae9e..1aa7b56 100644
--- a/src/lib/conf.sh
+++ b/src/lib/conf.sh
@@ -1,11 +1,13 @@
#!/bin/bash # non-executable, but put this there as a hint to text editors
# This may be included with or without `set -euE`
-# Copyright (c) 2012-2013 by Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2012-2014 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# License: GNU GPLv2+
#
# 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 3 of the License, or
+# 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,
@@ -122,7 +124,7 @@ load_files() {
# Check whether the variables listed are properly set.
# If not, it prints a message saying to set them in the configuration file(s)
# for $slug.
-check_vars() {
+check_vars() (
local slug=$1; shift
local ret=0
@@ -132,10 +134,10 @@ check_vars() {
if [[ -z ${!VAR:-} ]]; then
type print &>/dev/null || . libremessages
if [[ $(list_files $slug|wc -l) -gt 1 ]]; then
- print "Configure '%s' in one of:" "$VAR"
+ _l print "Configure '%s' in one of:" "$VAR"
list_files $slug | sed 's/./ -> &/'
else
- print "Configure '%s' in '%s'" "$VAR" "$(list_files $slug)"
+ _l print "Configure '%s' in '%s'" "$VAR" "$(list_files $slug)"
fi
ret=1
fi
@@ -144,7 +146,7 @@ check_vars() {
if [[ $ret != 0 ]]; then
return 1
fi
-}
+)
# Usage: get_var <slug> <var_name> <default_value>
# Does not work with arrays
diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist
index 5db1a3f..8aa33cc 100755
--- a/src/lib/libreblacklist
+++ b/src/lib/libreblacklist
@@ -2,11 +2,13 @@
# This may be included with or without `set -euE`
# When run directly, it does `set -euE`
-# Copyright (c) 2013 by Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2013-2014 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# License: GNU GPLv2+
#
# 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 3 of the License, or
+# 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,
@@ -48,7 +50,7 @@ blacklist-update() (
local remote_blacklist="$BLACKLIST"
local local_blacklist="$XDG_CACHE_HOME/libretools/blacklist.txt"
- stat_busy "Downloading blacklist of proprietary software packages"
+ _l stat_busy "Downloading blacklist of proprietary software packages"
mkdir -p "${local_blacklist%/*}"
if wget -N -q -O "${local_blacklist}.part" "$remote_blacklist" 2>/dev/null; then
@@ -58,9 +60,9 @@ blacklist-update() (
stat_done
rm "${local_blacklist}.part"
if [[ -e "$local_blacklist" ]]; then
- warning "Using local copy of blacklist"
+ _l warning "Using local copy of blacklist"
else
- error "Download failed, exiting"
+ _l error "Download failed, exiting"
return 1
fi
@@ -109,6 +111,8 @@ if [[ "${0##*/}" == libreblacklist ]]; then
sed 's/\r/\n/g'<<<"$1"|sed -e '/^$/d' -e 's/^# //'
}
usage() {
+ export TEXTDOMAIN='librelib'
+ export TEXTDOMAINDIR='/usr/share/locale'
. $(librelib messages)
if [[ $# -eq 0 ]]; then
print "Usage: %s [-h] COMMAND [ARGUMENTS]" "${0##*/}"
@@ -135,7 +139,7 @@ if [[ "${0##*/}" == libreblacklist ]]; then
}
if [[ $# -eq 0 ]]; then
- usage >/dev/stderr
+ usage >&2
exit 1
fi
_blacklist_cmd=$1
diff --git a/src/lib/librelib b/src/lib/librelib
index a58f5d3..63d9a26 100755
--- a/src/lib/librelib
+++ b/src/lib/librelib
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
-# Copyright (c) 2013 by Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2013-2014 Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# License: GNU GPLv3+
#
# 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
@@ -16,18 +18,31 @@
default_libdir=/usr/lib/libretools
-if ! type gettext &>/dev/null; then
- gettext() { echo "$@"; }
+if type gettext &>/dev/null; then
+ _() { gettext "$@"; }
+else
+ _() { echo "$@"; }
fi
+_l() {
+ TEXTDOMAIN='librelib' TEXTDOMAINDIR='/usr/share/locale' "$@"
+}
+
print() {
- mesg=$1
+ local mesg="$(_ "$1")"
shift
- printf -- "$(gettext "$mesg")\n" "$@"
+ printf -- "$mesg\n" "$@"
+}
+
+_html_whitespace_collapse() {
+ [[ $# == 0 ]] || panic
+ tr '\n' ' ' | sed -r -e 's/\t/ /g' -e 's/ +/ /g'
}
prose() {
- print "$@" | fmt -su
+ [[ $# -ge 1 ]] || panic
+ local mesg="$(_ "$(_html_whitespace_collapse <<<"$1")")"; shift
+ printf -- "$mesg" "$@" | fmt -u
}
cmd=${0##*/}
@@ -54,11 +69,11 @@ usage() {
main() {
if [[ $# != 1 ]]; then
- usage >&2
+ _l usage >&2
return 2
fi
if [[ $1 == '-h' ]]; then
- usage
+ _l usage
return 0;
fi
@@ -76,7 +91,7 @@ main() {
return 0;
fi
done
- print '%s: could not find library: %s' "$cmd" "$lib" >> /dev/stderr
+ _l print '%s: could not find library: %s' "$cmd" "$lib" >&2
return 1
}
diff --git a/src/lib/libremessages b/src/lib/libremessages
index c6d08e2..b89e2bc 100755
--- a/src/lib/libremessages
+++ b/src/lib/libremessages
@@ -2,28 +2,33 @@
# This may be included with or without `set -euE`
# When run directly, it does `set -euE`
-# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
-# Copyright (c) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>
-# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
-# Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
-# Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
-# Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
-# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
-# Copyright (c) 2011 by Joshua Haase <hahj87@gmail.com>
-# Copyright (c) 2012-2013 by Luke Shumaker <lukeshu@sbcglobal.net>
+# Copyright (C) 2011 Joshua Ismael Haase Hernández (xihh) <hahj87@gmail.com>
+# Copyright (C) 2012 Nicolás Reynolds <fauno@parabola.nu>
+# Copyright (C) 2012-2014 Luke Shumaker <lukeshu@sbcglobal.net>
+
+# For just the setup_traps() function:
+# Copyright (C) 2002-2006 Judd Vinet <jvinet@zeroflux.org>
+# Copyright (C) 2006-2010 Pacman Development Team <pacman-dev@archlinux.org>
+# Copyright (C) 2005 Aurelien Foret <orelien@chez.com>
+# Copyright (C) 2005 Christian Hamar <krics@linuxforum.hu>
+# Copyright (C) 2006 Alex Smith <alex@alex-smith.me.uk>
+# Copyright (C) 2006 Andras Voroskoi <voroskoi@frugalware.org>
+# Copyright (C) 2006 Miklos Vajna <vmiklos@frugalware.org>
#
-# 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 3 of the License, or
-# (at your option) any later version.
+# License: GNU GPLv2+
#
-# 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.
+# 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.
#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# 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. If not, see <http://www.gnu.org/licenses/>.
################################################################################
# Inherit most functions from devtools #
@@ -36,7 +41,7 @@
################################################################################
panic() {
- echo "$(_ 'panic: malformed call to internal function')" >&2
+ echo "$(_l _ 'panic: malformed call to internal function')" >&2
exit 1
}
@@ -88,8 +93,6 @@ bullet() {
# bullet.
flag() {
[[ $# == 2 ]] || panic
- local n='
-'
local flag=$1
local desc="$(_ "$(_html_whitespace_collapse <<<"$2")")"
@@ -99,7 +102,7 @@ flag() {
done
local lines
- IFS=$n lines=($(fmt -u -w $((73-indent)) <<<"$desc"))
+ IFS=$'\n' lines=($(fmt -u -w $((73-indent)) <<<"$desc"))
local line
for line in "${lines[@]}"; do
printf " %-${indent}s %s\n" "$flag" "$line"
@@ -119,6 +122,38 @@ term_title() {
printf "$fmt" "$*"
}
+# Usage: setup_traps [handler]
+# Sets up traps on TERM, HUP, QUIT and INT signals, as well as the ERR event,
+# similar to makepkg.
+#
+# If `handler` is specified, instead of using the default handler
+# (which is good for most purposes), it will call the command handler
+# with the arguments:
+#
+# ${handler} SIGNAL_NAME MESSAGE_FMT [MESSAGE_PARAMS...]
+#
+# where MESSAGE_* are printf-like stuff.
+setup_traps() {
+ [[ $# -le 1 ]] || panic
+ if [[ $# == 1 ]]; then
+ eval "_libremessages_trap_exit() { $1 \"\$@\"; }"
+ else
+ _libremessages_trap_exit() {
+ local signal=$1; shift
+ echo
+ error "$@"
+ trap -- "$signal"
+ kill "-$signal" "$$"
+ }
+ fi
+ set -E
+ for signal in TERM HUP QUIT; do
+ trap "_libremessages_trap_exit $signal '%s signal caught. Exiting...' $signal" $signal
+ done
+ trap '_libremessages_trap_exit INT "Aborted by user! Exiting..."' INT
+ trap '_libremessages_trap_exit USR1 "An unknown error has occurred. Exiting..."' ERR
+}
+
################################################################################
# Run one of the defined functions if invoked directly #
################################################################################
diff --git a/src/lib/libremessages.1.ronn b/src/lib/libremessages.1.ronn
index b91a958..2bf73a1 100644
--- a/src/lib/libremessages.1.ronn
+++ b/src/lib/libremessages.1.ronn
@@ -69,6 +69,15 @@ Unless otherwise noted, these do not implicitly call `gettext`.
Joins all arguments with whitespace, and sets the terminal title
to that.
+ * `setup_traps` [<HANDLER>]:
+ Sets traps on TERM, HUP, QUIT and INT signals, as sell as the ERR
+ event, similar to makepkg. If <HANDLER> is specified, instead of
+ using the default handler (which is good for most purposes), it
+ will call <HANDLER> with the arguments
+ `<HANDLER> <SIGNAL_NAME> <MESSAGE> [<MESSAGE_ARGS>...]`, where
+ <MESSAGE> is a `printf`(1)-formatted string, and <MESSAGE_ARGS>
+ are its arguments.
+
### PROSE ROUTINES
These routines print to standard output, ande are useful for printing
@@ -104,7 +113,7 @@ For each of these, <MESSAGE> is fed through `gettext` automatically.
These routines print to standard error, and all take arguments in the
same format as `printf`(1), except for `stat_done`, which doesn't take
-any arguments.
+any arguments. Each of these print to stderr, not stdout.
For each of these, <MESSAGE> is fed through `gettext` automatically.
@@ -147,15 +156,16 @@ these, you could end up deleting a lot of someone's work.
* `cleanup` [<EXIT_STATUS>]:
*If* `setup_workdir` has been run, `rm -rf "$WORKDIR"`. If given
- a numeric argument, it will then call `exit`(1) with that argument.
+ a numeric argument, it will then call `exit`(1) with that
+ argument, otherwise it calls `exit`(1) with a status of 0.
* `abort`:
Calls `msg` with the message "Aborting...", then calls
- `cleanup 0`.
+ `cleanup 255`.
* `die` <MESSAGE> [<ARGS>...]:
Exactly like `error`, but calls `cleanup` and calls `exit`(1)
- with a status of 1.
+ with a status of 255.
### LOCKFILE ROUTINES
@@ -178,6 +188,13 @@ these, you could end up deleting a lot of someone's work.
These routines relate to `makepkg`(8).
+ * `find_cached_package` <PKGNAME> <PKGVER>[-<PKGREL] <ARCH>:
+ Searches for a localy built copy of the specified package, in
+ <PKGDEST> and the current working directory. If <PKGREL> is not
+ specified, any value will match. If multiple matching files are
+ found (not counting duplicate links), then an error is printed to
+ stderr and nothing is prented to stdout.
+
* `get_full_version` [<PKGNAME>]:
Inspects variables that are set, and prints the full version
spec, including <epoch> if necessary, <pkgver>, and <pkgrel>. By
@@ -188,12 +205,6 @@ These routines relate to `makepkg`(8).
## BUGS
-libremessages sets <TEXTDOMAIN> to `libretools` unconditionally,
-making it generally unsuitable for use outside of libretools. If you
-override <TEXTDOMAIN> after loading the library, that should work, but
-you will also have to provide translations for libremessage's internal
-messages (such as "ERROR" or "Warning").
-
Generating `.pot` files for the prose functions is a pain. The
libretools Makefiles have rules to do it, but it might make sense to
pull it into a separate program.
@@ -202,9 +213,6 @@ pull it into a separate program.
xterm and rxvt (and their various <TERM> values;
"rxvt-unicode-256color" is still rxvt).
-Also, I think `abort` calling `cleanup 1` would make more sense than
-`cleanup 0`.
-
## SEE ALSO
librelib(7), gettext(1), common.sh(3)