#!/sbin/sh
#Tag 0x00000f00
#
# CMW Configuration checks.
#
# $Revision: 1.8 $
#

IS_ON=/sbin/chkconfig

#
# turn(option, on/off)
#
# This function is used to deal with /etc/config entries which are
# not root writable. At least one (desktop) of the option flag files
# is installed thus.
#
turn ()
{
    /sbin/suattr -C CAP_DAC_WRITE+ep -c "/sbin/chkconfig $1 $2"
}

#
# remove(path)
#
# This function is used to deal with ill-behaved scripts which cause
# errors in the Trix environment.  it should be called with the full
# path of the appropriate rc?.d link; do not call it with the init.d path.
# Whenever possible, turning off chkconfig options is preferred over
# removing links.
# 
remove()
{
    if [ -f "$1" ]; then
       /usr/bin/rm "$1"
       echo "$1 removed for the CMW environment."
    else
       :
    fi
}

cronmaccheck ()
{
    if test "`sysconf MAC`" -eq 1; then
        if test ! -d $1; then
            /sbin/suattr -m -C all=eip -c "rm -rf $1"
            mkdir $1
            /sbin/suattr -C all=eip -c "chlabel msenmldlow/minthigh $1"
        fi
    fi
}

if $IS_ON verbose ; then        # For a verbose startup and shutdown
    ECHO=echo
else
    if $IS_ON CMWquiet ; then   # For a verbose startup and shutdown
        ECHO=:
    else                        # For a quiet startup and shutdown
        ECHO=echo
    fi
fi

case "$1" in
  'start')
        $ECHO 'CMW Configuration checks...'
        if $IS_ON xdm ; then
            $ECHO CMW: xdm cannot be used.
            turn xdm off
        fi
        if $IS_ON visuallogin ; then
            $ECHO CMW: visuallogin cannot be used.
            turn visuallogin off
        fi
        if $IS_ON objectserver ; then
            $ECHO CMW: objectserver cannot be used.
            turn objectserver off
        fi
        if $IS_ON directoryserver ; then
            $ECHO CMW: directoryserver cannot be used.
            turn directoryserver off
        fi
        if $IS_ON desktop ; then
            $ECHO CMW: desktop cannot be used.
            turn desktop off
        fi
        if $IS_ON lockd ; then
            $ECHO CMW: lockd cannot be used.
            turn lockd off
        fi
        if $IS_ON audit ; then
            : OKay
	else
            $ECHO Note: audit should be used in the CMW environment.
        fi
        if $IS_ON timed ; then
            : OKay
	else
            $ECHO Note: timed should be used in the CMW environment.
        fi
        if $IS_ON lockd ; then
            $ECHO CMW: lockd cannot be used.
            turn lockd off
        fi
# checks added for Irix 6.5se
        if $IS_ON autoconfig_ipaddress ; then
            $ECHO CMW: DHCP cannot be used.
            turn autoconfig_ipaddress off
        fi
        if $IS_ON sdpd ; then
            $ECHO CMW: sdpd cannot be used.
            turn sdpd off
        fi
        if $IS_ON ns_admin ; then
            $ECHO CMW: ns_admin cannot be used.
            turn ns_admin off
        fi
        if $IS_ON ns_fasttrack ; then
            $ECHO CMW: ns_fasttrack cannot be used.
            turn ns_fasttrack off
        fi
        if $IS_ON webface ; then
            $ECHO CMW: webface cannot be used.
            turn webface off
        fi
# remove these rc2.d links to prevent broken scripts (or unavailable 
# functionality) from confusing customers.
	remove /etc/rc2.d/S95availmon    # availmon doesn't work under Trix
	remove /etc/rc0.d/K05availmon    # availmon doesn't work under Trix
	remove /etc/rc2.d/S98xdm         # chkconfig tests broken for Trix/CMW
        remove /etc/rc2.d/S60ns_admin    # runs $CONFIGURE when chkconfig'd off
	remove /etc/rc2.d/S98pcp         # no chkconfig option.  doesn't work.
	remove /etc/rc0.d/K02pcp         #  no chkconfig option.  doesn't work.
	remove /etc/rc0.d/K30ns_admin    # chkconfig off doesn't fix entirely
	remove /etc/rc0.d/K30ns_fasttrack # chkconfig off doesn't fix entirely
	remove /etc/rc0.d/K35webface      # chkconfig off doesn't fix entirely
# create moldy directories for cron
        cronmaccheck /var/spool/cron/crontabs/:mac
        cronmaccheck /var/spool/cron/atjobs/:mac
# hist file gets written after attrinit runs.  needed for configmsg script.
        /sbin/suattr -C CAP_MAC_READ,CAP_DAC_READ_SEARCH,CAP_DAC_WRITE,CAP_MAC_WRITE,CAP_DEVICE_MGT+ip -c "/sbin/attrinit -type=t -mac=dblow var/inst"
        $ECHO 'done.'
        ;;
  'stop')
        ;;
  *)
        echo "usage: /etc/init.d/CMWchkconfig {start|stop}"
        ;;
esac
