#!/bin/sh
# vim:set sw=4 ts=4:
#
# $Id: alicerc1,v 1.2 2005/04/11 14:21:48 fabian Exp $
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
#############################################################################
#
# Copyright (c) 2000-2001 SuSE Linux Solutions AG, Eschborn, Germany
#               2002,2003 SuSE Linux AG, Eschborn, Germany 
# All rights reserved.
#
# This file is part of ALICE, which was sponsored by
# T-Online International AG
#
# Author: Fabian Herschel
#
#############################################################################
#
# alicerc1
export alice_nls_dir="$alice_dir/lib/nls"
export _self=$(basename $0)

WELCOME()
{
   MESSAGE HALLO $_self "$(date  +"%Y-%m-%d,%H:%M:%S,(%Z)")"
}

GOOD_BYE()
{
   MESSAGE BYE $_self "$(date  +"%Y-%m-%d,%H:%M:%S,(%Z)")"
   exit $alice_rc
}

ERROR()
{
   # parameter: message-id message-params
   MESSAGE -n ERR
   MESSAGE "$@"
   test $alice_rc -lt 2 && alice_rc=2
}

WARNING()
{
   MESSAGE -n WARN
   MESSAGE "$@"
   test $alice_rc -eq 0 && alice_rc=1
}

MESSAGE()
{
   #
   # -n says "no carr. return" after the message
   # -t <type>
   #
   typeset MSG MSGID RT="\n" TYPE=info MSGPAR FACILITY=local0
   while [ $# -gt 0 ]
   do
      case "$1" in
          -n )
              RT=""
              shift
              ;; 
          -t )
              TYPE="$2"
              shift 2
              ;;
           * ) 
              MSGID=$1
              shift
	          break;    # <-- the rest of params should be plain text
              ;;
      esac
   done

   #
   # Using LANG to get the correct error file (only C supported now)
   #
   if [ ! -f $alice_nls_dir/message_$LANG ]
   then
      export LANG=C
   fi
   MSG=$(grep ^$MSGID: $alice_nls_dir/message_$LANG)
   MSG=${MSG#$MSGID:}
#   printf "$MSG$RT" "$MSGPARAM"
   printf "$MSG$RT" "$@"
   if [ -n "$ALICE_LOGGER_FACILITY" ]
   then
      FACILITY="${ALICE_LOGGER_FACILITY%%[ \t]*}"
   fi
   logger -t ALICE -p ${FACILITY}.info "$(printf "$MSG$RT" "$@")"
}

FATAL()
{
   # parameter: message-id message-params
   MESSAGE -n FATAL
   MESSAGE "$@" 
   MESSAGE ERREXIT
   alice_rc=3
   GOOD_BYE
}

