r3560@krups: intrigeri | 2005-11-15 15:13:35 +0100
[matthijs/upstream/backupninja.git] / src / backupninja.in
index 387743fe1934719454b64f61a0095a251120ae06..26634576c1b4655650d1963b5ce658378a981104 100755 (executable)
@@ -19,7 +19,7 @@
 #####################################################
 ## FUNCTIONS
 
-function setupcolors() {
+setupcolors () {
        BLUE="\033[34;01m"
        GREEN="\033[32;01m"
        YELLOW="\033[33;01m"
@@ -27,20 +27,18 @@ function setupcolors() {
        RED="\033[31;01m"
        OFF="\033[0m"
        CYAN="\033[36;01m"
-       COLORS=($BLUE $GREEN $YELLOW $RED $PURPLE)
 }
 
-function colorize() {
+colorize () {
        if [ "$usecolors" == "yes" ]; then
                local typestr=`echo "$@" | sed 's/\(^[^:]*\).*$/\1/'`
-               [ "$typestr" == "Debug" ] && type=0
-               [ "$typestr" == "Info" ] && type=1
-               [ "$typestr" == "Warning" ] && type=2
-               [ "$typestr" == "Error" ] && type=3
-               [ "$typestr" == "Fatal" ] && type=4
-               color=${COLORS[$type]}
+               [ "$typestr" == "Debug" ] && COLOR=$BLUE
+               [ "$typestr" == "Info" ] && COLOR=$GREEN
+               [ "$typestr" == "Warning" ] && COLOR=$YELLOW
+               [ "$typestr" == "Error" ] && COLOR=$RED
+               [ "$typestr" == "Fatal" ] && COLOR=$PURPLE
                endcolor=$OFF
-               echo -e "$color$@$endcolor"
+               echo -e "$COLOR$@$endcolor"
        else
                echo -e "$@"
        fi
@@ -132,22 +130,6 @@ function setsection() {
 }
 
 
-#
-# create a temporary file in a secure way.
-#
-function maketemp() {
-       if [ -x /bin/mktemp ]
-       then
-               local tempfile=`mktemp /tmp/$1.XXXXXXXX`
-       else
-               DATE=`date`
-               sectmp=`echo $DATE | /usr/bin/md5sum | cut -d- -f1`
-               local tempfile=/tmp/$1.$sectmp
-       fi
-       echo $tempfile
-}
-
-
 #
 # sets a global var with name equal to $1
 # to the value of the configuration parameter $1
@@ -426,15 +408,36 @@ if [ ! -r "$conffile" ]; then
        fatal "Configuration file $conffile not found."
 fi
 
+# find $scriptdir
 scriptdir=`grep scriptdirectory $conffile | awk '{print $3}'`
-if [ ! -n "$scriptdir" ]; then
-       echo "Cound not find entry 'scriptdirectory' in $conffile" 
-       fatal "Cound not find entry 'scriptdirectory' in $conffile"
+if [ -z "$scriptdir" ]; then
+        if [ -d "@datadir@" ]; then
+          scriptdir="@datadir@"
+       else
+          echo "Could not find entry 'scriptdirectory' in $conffile" 
+          fatal "Could not find entry 'scriptdirectory' in $conffile" 
+       fi
+else
+        if [ ! -d "$scriptdir" ]; then
+          echo "Script directory $scriptdir not found."
+          fatal "Script directory $scriptdir not found."
+       fi         
 fi
 
-if [ ! -d "$scriptdir" ]; then
-       echo "Script directory $scriptdir not found." 
-       fatal "Script directory $scriptdir not found."
+# find $libdir
+libdir=`grep libdirectory $conffile | awk '{print $3}'`
+if [ -z "$libdir" ]; then
+        if [ -d "@libdir@" ]; then
+          libdir="@libdir@"
+       else
+          echo "Could not find entry 'libdirectory' in $conffile." 
+          fatal "Could not find entry 'libdirectory' in $conffile." 
+       fi
+else
+        if [ ! -d "$libdir" ]; then
+          echo "Lib directory $libdir not found." 
+          fatal "Lib directory $libdir not found." 
+       fi
 fi
 
 setfile $conffile
@@ -469,6 +472,9 @@ if [ ! -d "$configdirectory" ]; then
        fatal "Configuration directory '$configdirectory' not found."
 fi
 
+# include shared functions
+. $libdir/tools
+
 [ -f "$logfile" ] || touch $logfile
 
 if [ "$UID" != "0" ]; then