#
# ax-unix: Alex' UNIX Tools & Scripts
-# Copyright (c)2013-2014 Alexander Barton (alex@barton.de)
+# Copyright (c)2013-2015 Alexander Barton (alex@barton.de)
#
# 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
# (at your option) any later version.
#
-SUBDIRS = bup
+SUBDIRS = lib bup
include Makefile.ax
--- /dev/null
+#
+# ax-unix: Alex' UNIX Tools & Scripts
+# Copyright (c)2013-2015 Alexander Barton (alex@barton.de)
+#
+# 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.
+#
+
+SUBDIRS = ax
+
+include ../Makefile.ax
--- /dev/null
+#
+# ax-unix: Alex' UNIX Tools & Scripts
+# Copyright (c)2013-2015 Alexander Barton (alex@barton.de)
+#
+# 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.
+#
+
+ALL = README ax-common.sh
+
+include ../../Makefile.ax
+
+install-local: ax-common.sh
+ install -d -o $(USER) -g $(GROUP) -m 755 \
+ $(DESTDIR)$(PREFIX)/lib/ax
+ install -p -o $(USER) -g $(GROUP) -m 755 README \
+ $(DESTDIR)$(PREFIX)/lib/ax/README
+ install -p -o $(USER) -g $(GROUP) -m 755 ax-common.sh \
+ $(DESTDIR)$(PREFIX)/lib/ax/ax-common.sh
--- /dev/null
+ax-unix: Alex' UNIX Tools & Scripts
+Copyright (c)2013-2015 Alexander Barton (alex@barton.de)
+
+This directory contains library files to use in 3rd party applications and
+scripts. Please see below for usage information.
+
+
+ax-common.sh
+------------
+
+This is a shell script library containing common useful functions. If you want
+to use it in your own code, your script must include ("source") this library
+file, and therefore it has to check some common locations (if you don't bundle
+it in some other ways and exactly know the location it is installed in).
+
+Use something like the following in your scrips:
+
+----> cut here <---------------------------------------------------------------
+# Include "ax-common.sh":
+for dir in "$HOME/lib" "$HOME/.ax" /usr/local /opt/ax /usr; do
+ [ -z "$ax_common_sourced" ] || break
+ ax_common="${dir}/lib/ax/ax-common.sh"
+ [ -r "$ax_common" ] && source "$ax_common"
+done
+if [ -z "$ax_common_sourced" ]; then
+ echo "Error (`basename "$0"`): \"ax-common.sh\" not found, aborting!"
+ echo "Please install 'ax-unix', \"Alex' UNIX Tools & Scripts\", and try again."
+ exit 99
+fi
+unset dir ax_common ax_common_sourced
+----> cut here <---------------------------------------------------------------
--- /dev/null
+#
+# ax-common.sh -- Common Functions for Shell Scripts
+# Copyright (c)2013-2015 Alexander Barton (alex@barton.de)
+#
+# 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.
+#
+
+ax_common_sourced=1
+
+# Display a colored message.
+# $1 Level: -=title, 0=ok, 1=warning, 2=error.
+# $2 Word(s) to highlight.
+# $3-n Remaining word(s). [optional]
+ax_msg1() {
+ case "$1" in
+ "0") c="32"; shift; ;; # green
+ "1") c="33"; shift; ;; # yellow
+ "2") c="31"; shift; ;; # red
+ "-") c="1"; shift; ;; # bold
+ *) c="0";
+ esac
+ # print colored word(s):
+ printf "\x1b[0;${c}m"
+ /bin/echo -n "${1}"
+ printf "\x1b[0m "
+ shift
+ # print remaining word(s) and trailing newline:
+ echo "${*}"
+}
+
+# Display a colored message.
+# $1 Level, see ax_msg1 function.
+# $2-n Word(s) to highlight.
+ax_msg() {
+ level="$1"
+ shift
+ ax_msg1 "$level" "$*"
+}
+
+# Abort the script with an error message and exit code 1.
+# $1 Error message [optional]. Will be formatted as "Error: %s Aborting!".
+# if no error message is given, "Aborting!" will be printed.
+ax_abort() {
+ [ $# -gt 0 ] \
+ && ax_msg 2 "Error: $* Aborting!" \
+ || ax_msg 2 "Aborting!"
+ exit 1
+}