]> mj.ucw.cz Git - libucw.git/commitdiff
Added a (so far trivial) library of functions for shell scripts.
authorMartin Mares <mj@ucw.cz>
Wed, 7 Dec 2005 22:27:54 +0000 (22:27 +0000)
committerMartin Mares <mj@ucw.cz>
Wed, 7 Dec 2005 22:27:54 +0000 (22:27 +0000)
lib/shell/Makefile
lib/shell/libucw.sh [new file with mode: 0644]

index 2e58399ef5dd5f6cd8d329f9a4135bf8c4be6872..df69210379bfe3f74628ea3994d5f65d8183ddb3 100644 (file)
@@ -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 (file)
index 0000000..b02230c
--- /dev/null
@@ -0,0 +1,42 @@
+# The UCW Library -- Shell Functions
+# (c) 2005 Martin Mares <mj@ucw.cz>
+#
+# 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 "$@"`
+}