#----------------------------------------------------------------------------
# /etc/rc.d/rc405.imond - startup of imond
# was file /etc/rc.d/imond
#
# Creation:     10.10.2000 fm
# Last Update:  $Id: rc405.imond 10576 2005-12-08 23:53:34Z felix $
#----------------------------------------------------------------------------

if [ "$START_IMOND" = yes ]
then
    begin_script IMOND "starting imond ..."

    #------------------------------------------------------------------------
    # export some config variables for imond
    #------------------------------------------------------------------------
    export START_IMOND IMOND_PASS IMOND_ADMIN_PASS IMOND_ENABLE IMOND_DIAL
    export IMOND_ROUTE IMOND_REBOOT DIALMODE

    if [ "$MOUNT_BOOT" != 'rw' -a "$IMOND_LOGDIR" = '/boot' ]
    then 
        log_error "*** WARNING: /boot not mounted writeable ***"
        sleep 10
    fi  

    if [ -n "$IMOND_LED" ]
    then
        opt="-port $IMOND_PORT -led /dev/$IMOND_LED"
    else
        opt="-port $IMOND_PORT"
    fi

    [ "$IMOND_BEEP" = yes ] && opt="$opt -beep"

    echo $IMOND_PORT >/var/run/imond.port

    syslog_opt=''
    [ -f /etc/rc.d/rc325.syslogd ] &&  syslog_opt='-log-to-syslog'

    telmond_logdir=''
    [ "$OPT_TELMOND" = yes -a "$TELMOND_LOG" = yes ] && telmond_logdir="$TELMOND_LOGDIR"

    mgetty_logdir=''
    case "$OPT_MGETTY" in
        yes)
            mgetty_logdir="$MGETTY_FAXDIR"
        ;;
        *)
            case "$OPT_FAXRCV" in
                yes)
                    case "$FAXRCV_IMONC_LIST" in
                        0) ;;
                        *)
                            if echo "$FAXRCV_IMONC_LIST" | grep -q " "
                            then
                                mgetty_logdir="$FAXRCV_IMONC_DIR"
                            else
                                eval mgetty_logdir='$FAXRCV_'$FAXRCV_IMONC_LIST'_DIRECTORY'
                            fi
                        ;;
                    esac
                ;;
            esac
        ;;
    esac

    if [ "$IMOND_USE_ORIG" = yes ]
    then
	imond=/usr/local/bin/imond 
	ipopt=''
    else
	imond=/usr/local/bin/imond-dev
	ipopt=''
        for idx in `seq 1 $IP_NET_N`
	do
	    eval iptmp='$IP_NET_'$idx''
            ipaddr=`echo $iptmp | sed -e 's/\/.*//'`
	    ipopt="$ipopt -ip $ipaddr"
	done
    fi
 	
    if [ "$IMOND_LOG" = yes ]
    then
        if [ ! -d $IMOND_LOGDIR ]
	then
	    mkdir -p $IMOND_LOGDIR
	fi
	if [ ! -d $telmond_logdir ]
	then
	    mkdir -p $telmond_logdir
	fi
        $imond    $ipopt $syslog_opt $opt "$IMOND_LOGDIR"  \
                  "$telmond_logdir" "$mgetty_logdir"
    else
        $imond    $ipopt $syslog_opt $opt ""             \
                  "$telmond_logdir" "$mgetty_logdir"
    fi

    sleep 2                                            # wait for output
    cat /etc/imond.conf

    end_script
fi
