From 9ce9d984986c1f44fe8486591b1a59e66e28f23b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 7 Dec 2005 22:27:54 +0000 Subject: [PATCH] Added a (so far trivial) library of functions for shell scripts. --- lib/shell/Makefile | 1 + lib/shell/libucw.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 lib/shell/libucw.sh diff --git a/lib/shell/Makefile b/lib/shell/Makefile index 2e58399e..df692103 100644 --- a/lib/shell/Makefile +++ b/lib/shell/Makefile @@ -2,6 +2,7 @@ DIRS+=lib/shell PROGS+=$(o)/lib/shell/config $(o)/lib/shell/logger +DATAFILES+=$(o)/lib/shell/libucw.sh $(o)/lib/shell/config: $(o)/lib/shell/config.o $(LIBSH) $(o)/lib/shell/logger: $(o)/lib/shell/logger.o $(LIBSH) diff --git a/lib/shell/libucw.sh b/lib/shell/libucw.sh new file mode 100644 index 00000000..b02230cf --- /dev/null +++ b/lib/shell/libucw.sh @@ -0,0 +1,42 @@ +# The UCW Library -- Shell Functions +# (c) 2005 Martin Mares +# +# This software may be freely distributed and used according to the terms +# of the GNU Lesser General Public License. + +UCW_CF= +while [ "${1:0:2}" = "-C" -o "${1:0:2}" = "-S" ] ; do + if [ -z "${1:2:1}" ] ; then + UCW_CF="$UCW_CF $1 $2" + shift 2 + else + UCW_CF="$UCW_CF $1" + shift 1 + fi +done + +function log # msg +{ + bin/logger $UCW_PROGNAME I "$1" +} + +function errlog # msg +{ + bin/logger $UCW_PROGNAME E "$1" +} + +function warnlog # msg +{ + bin/logger $UCW_PROGNAME E "$1" +} + +function die # msg +{ + bin/logger $UCW_PROGNAME ! "$1" + exit 1 +} + +function parse-config # section vars... +{ + eval `bin/config$UCW_CF "$@"` +} -- 2.39.2