home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / sbin / rc0 / rc0~
Text File  |  1998-08-19  |  4KB  |  170 lines

  1. #!/sbin/sh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11. #ident    "@(#)initpkg:i386/cmd/initpkg/rc0.sh    1.15.21.15"
  12.  
  13. #    "Run Commands" for init state 0, 5 or 6
  14. #    Leaves the system in a state where it is safe to turn off the power
  15. #    or reboot. 
  16. #
  17. #    Takes an optional argument of off, firm or reboot
  18. #    to specify if this is being run for init 0, init 5, or init 6.
  19. #
  20. #    In SVR4.0, inittab has been changed to no longer do the
  21. #    uadmin to shutdown or enter firmware.  Instead, this script
  22. #    is responsible.  By using an optional argument,
  23. #    compatibility is maintained while still providing the needed
  24. #    functionality to perform the uadmin call.
  25.  
  26. # make sure /usr is mounted before proceeding since init scripts
  27. # and this shell depend on things on /usr file system
  28. if [ ! -d /usr/bin ]
  29. then
  30.     /sbin/mount /usr >/dev/null 2>&1
  31.     /sbin/initprivs 2> /dev/null
  32. fi
  33.  
  34. if [ -z "$LC_ALL" -a -z "$LC_MESSAGES" ]
  35. then
  36.     if [ -z "$LANG" ]
  37.     then
  38.         LNG=`defadm locale LANG 2>/dev/null`
  39.         if [ "$?" != 0 ]
  40.         then LANG=C
  41.         else eval $LNG
  42.         fi
  43.     fi
  44.     LC_MESSAGES=/etc/inst/locale/$LANG
  45.     export LANG LC_MESSAGES
  46. fi
  47. LABEL="UX:$0"
  48.  
  49. CAT=uxrc; export CAT
  50.  
  51. ARG="$1"  # save arg for later
  52.  
  53. set -- `LC_ALL=C /sbin/who -r`
  54. _CURR_RL=$7 _CURR_NTIMES=$8 _PREV_RL=$9 export _CURR_RL _CURR_NTIMES _PREV_RL
  55. if [ "$ARG" = shutdown_s ]
  56. then
  57.     # We are run from shutdown.
  58.  
  59.     _AUTOKILL=true export _AUTOKILL
  60. else
  61.     # We are run from inittab.
  62.  
  63.     case "$_PREV_RL" in
  64.     2 | 3 )
  65.         case "$_CURR_RL" in
  66.         0 | 5 | 6 )
  67.             AUTOKILL=true export _AUTOKILL
  68.             ;;
  69.         esac
  70.     esac
  71. fi
  72.  
  73. pfmt -l $LABEL -s info -g $CAT:71 "The system is coming down.  Please wait.\n"
  74.  
  75. #INFO messages should not appear in screen, save them in shut.log
  76. exec 4>&2 3>&1 2>/dev/null >/var/adm/shut.log
  77. exec 2>&4
  78. chmod 664 /var/adm/shut.log
  79.  
  80. umask 022
  81.  
  82. #    The following segment is for historical purposes.
  83. #    There should be nothing in /etc/shutdown.d.
  84. cd /etc/shutdown.d 2>/dev/null
  85. if [ $? -eq 0 ]
  86. then
  87.     for f in *
  88.     {
  89.         case $f in
  90.         \* ) ;;
  91.         * ) /sbin/sh ${f} ;;
  92.         esac
  93.     }
  94. fi
  95. #    End of historical section
  96.  
  97. cd /etc/rc0.d 2>/dev/null
  98. if [ $? -eq 0 ]
  99. then
  100.     for f in K*
  101.     {
  102.         case $f in
  103.         K\* )
  104.             ;;
  105.         * )
  106.             /sbin/sh ${f} stop
  107.             ;;
  108.         esac
  109.     }
  110.  
  111.     #    system cleanup functions ONLY (things that end fast!)    
  112.  
  113.     for f in S*
  114.     {
  115.         case $f in
  116.         S\* ) ;;
  117.         * ) /sbin/sh ${f} start ;;
  118.         esac
  119.     }
  120. fi
  121.  
  122. # Note that S* scripts had better terminate synchronously, or they will
  123. # get caught here.
  124.  
  125. /usr/sbin/killall&
  126.  
  127. # PC 6300+ Style Installation - execute shutdown scripts from driver packages
  128. cd /etc/idsd.d 2>/dev/null
  129. if [ $? -eq 0 ]
  130. then
  131.     for f in *
  132.     {
  133.         case $f in
  134.         \* ) ;;
  135.         * ) /sbin/sh ${f} ;;
  136.         esac
  137.     }
  138. fi
  139. exec 1>&3
  140.  
  141. trap "" 15
  142. if [ -f /etc/conf/.copy_unix -a -f /etc/conf/cf.d/unix ]
  143. then
  144.     /etc/conf/bin/idcpunix
  145. fi
  146.  
  147. wait    # for killall
  148.  
  149. # Check if user wants machine brought down or reboot.
  150. # umountall will be done in uadmin if we are shutting down.
  151. case "$ARG" in
  152.     off)
  153.         /sbin/uadmin 2 0
  154.         ;;
  155.  
  156.     firm)
  157.         /sbin/uadmin 2 2
  158.         ;;
  159.  
  160.     reboot)
  161.         /sbin/uadmin 2 1
  162.         ;;
  163.     * )
  164.         sleep 10    # for killall to work
  165.         /sbin/umountall >/dev/null 2>&1
  166.         ;;
  167. esac
  168.  
  169. pfmt -l $LABEL -s warn -g $CAT:72 "\n\tUser level file systems may still be mounted.\n\tMake sure to umount those file systems if you\n\tare going to powerdown the system. Otherwise,\n\tthe file systems may be corrupted.\n\n"
  170.