summaryrefslogtreecommitdiff
path: root/src/librelib
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-05-26 22:11:51 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-05-26 22:11:51 -0400
commitca6db7290cacee0d3b5ba836e6acea76ea314e50 (patch)
tree7cf3e4eda33335fdcc245d41e75a3b1602485266 /src/librelib
parentb159a370e2b1458c8c3817bdf3cabe2a630732e3 (diff)
redo the library system; avoid hard-coded paths
* install all library files to $(libexecdir)/libretools, instead of - $(bindir) - $(datadir)/libretools - $(datadir)/devtools * symlink the executable library files into $(bindir) * add the tool `librelib` * instead of ". /path/to/lib.sh", use ". $(librelib lib.sh)" * mark all libraries with shebangs of what options they support * move blacklist.sh to libreblacklist
Diffstat (limited to 'src/librelib')
-rwxr-xr-xsrc/librelib60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/librelib b/src/librelib
new file mode 100755
index 0000000..22811db
--- /dev/null
+++ b/src/librelib
@@ -0,0 +1,60 @@
+#!/bin/bash
+# Copyright (c) 2013 by Luke Shumaker <lukeshu@sbcglobal.net>
+#
+# 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.
+#
+# 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/>.
+
+default_libdir=/usr/lib/libretools
+
+cmd=${0##*/}
+usage() {
+ print 'Usage: . $(%s LIBRARY)' "$cmd"
+ print "Finds a shell library file"
+ echo
+ print "While some libraries can be sourced just by their name because"
+ print "they are installed in PATH (like libremessages), some are not"
+ print "installed there (like conf.sh), so path must be given."
+ print "Hardcoding that path is the way of the dark side."
+ echo
+ print "By default, it looks for the files in '%s'," "$default_libdir"
+ print "but this can be changed with the environmental variable"
+ print "LIBRETOOLS_LIBDIR."
+ echo
+ print "Example usage:"
+ print ' . $(librelib conf.sh)'
+}
+
+main() {
+ if [[ $# != 1 ]]; then
+ usage >&2
+ return 2
+ fi
+
+ if [[ -z $LIBRETOOLS_LIBDIR ]]; then
+ export LIBRETOOLS_LIBDIR=$default_libdir
+ fi
+
+ lib=$1
+ lib=${lib#libre}
+ lib=${lib%.sh}
+
+ for file in ${lib} libre${lib} ${lib}.sh libre${lib}.sh; do
+ if [[ -f "$LIBRETOOLS_LIBDIR/$file" ]]; then
+ printf '%s\n' "$LIBRETOOLS_LIBDIR/$file"
+ return 0;
+ fi
+ done
+ return 1
+}
+
+main "$@"