#!/bin/sh
#
# $Id: dtconfig.src,v 1.7 1997/04/23 00:25:59 vic Exp $
#
# This version of the TED dtconfig script is for use in the Linux
# operating environment.
#
#  TriTeal Enterprise Desktop
#
#  (c) Copyright 1995-1997  TriTeal Corporation
#  (c) Copyright 1993, 1994 Hewlett-Packard Company
#  (c) Copyright 1993, 1994 International Business Machines Corp.
#  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
#  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
#      Novell, Inc.
#
# This script can be run after TED installation to configure TED within
# the host platforms operating environment.  For example, when auto-start
# is selected, the TED desktop login window will be displayed at end of the
# workstation\'s power up boot cycle.
#
# Location:     /usr/dt/bin/dtconfig

mode=$1
arg_count=$#

usage_error() {
       echo " "
       echo " TED configuration utility"
       echo " "
       echo "  $0 -d    (disable auto-start)"
       echo "  $0 -e    (enable auto-start)"
       echo "  $0 -kill (kill dtlogin)"
       echo "  $0 -reset (reset dtlogin)"
       echo "  $0 -p    (printers - update app manager folder)"
       echo " "
}

#
# Allow for configured and factory versions of dtlogin.rc
#

if [ -f /etc/dt/config/dtlogin.rc ]
then
 RC_MASTER=/etc/dt/config/dtlogin.rc
elif [ -f /usr/dt/config/dtlogin.rc ]
then
 RC_MASTER=/usr/dt/config/dtlogin.rc
fi

RC_COPY=/etc/rc.d/init.d/dtlogin

LEVEL_0_KILL=/etc/rc.d/rc0.d/K10dtlogin
LEVEL_6_KILL=/etc/rc.d/rc6.d/K10dtlogin
LEVEL_3_START=/etc/rc.d/rc3.d/S99dtlogin


set `/usr/bin/id`
if [ $1 != "uid=0(root)" ]; then
       echo "$0: this script must be run as root"
       exit 1
fi


if [ $arg_count -ne 1 ]; then
       echo " "
#
# Display error message for too many arguments
#
       if [ $arg_count -gt 1 ]; then
               echo "Usage: Too many arguments"

#
# Display error message for NULL arguments passed
#
       elif [ $arg_count -eq 0 ]; then
               echo "Usage: Needs one argument"

       fi
       usage_error
       exit 1
fi


rc_master_check() {
       if [ ! -x $RC_MASTER ]; then
          echo "option failed"
          echo "could not execute $RC_MASTER"
          exit 1
       fi
}

case "$mode" in
'-d')
       echo "done"
       echo "desktop auto-start disabled."
            \rm -f $RC_COPY
            \rm -f $LEVEL_0_KILL
            \rm -f $LEVEL_3_KILL
            \rm -f $LEVEL_6_KILL
       ;;

'-e')
       if [ -f $RC_MASTER ]; then
           \rm -f $RC_COPY
       fi

       if [ ! -x $RC_COPY ]; then
          if [ ! -f $RC_MASTER ]; then
             echo "enable failed"
             echo "could not find $RC_MASTER"
             exit 1
          fi

          \cp $RC_MASTER $RC_COPY
          \chmod 0555 $RC_COPY

          if [ ! -x $RC_COPY ]; then
             echo "enable failed"
             echo "could not create $RC_COPY"
             exit 1
          fi
       fi

       \rm -f $LEVEL_0_KILL
       \ln -s $RC_COPY $LEVEL_0_KILL

       \rm -f $LEVEL_6_KILL
       \ln -s $RC_COPY $LEVEL_6_KILL

       \rm -f $LEVEL_3_START
       \ln -s $RC_COPY $LEVEL_3_START

       if [ ! -f $LEVEL_3_START ]; then
          echo "enable failed"
          echo "could not create $LEVEL_3_START"
          exit 1
       fi

       echo "done"
       echo "desktop auto-start enabled."
       ;;

'-kill')
       rc_master_check

       $RC_MASTER stop

       echo "done"
       echo "dtlogin kill complete."
       ;;

'-reset')
       rc_master_check

       $RC_MASTER reset

       echo "done"
       echo "dtlogin reset complete."
       ;;

'-p')
       rc_master_check

       $RC_MASTER update_printers

       echo "done"
       echo "printer application group update complete."
       ;;

*)
       echo " "
       echo "Usage:"
       usage_error
       exit 1
       ;;

esac

exit 0