home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / darwin / darwinx86.iso / private / etc / rc.boot < prev    next >
Encoding:
Text File  |  2001-09-20  |  3.6 KB  |  147 lines

  1. #!/bin/sh
  2.  
  3. ##
  4. # Copyright 1997-2001 Apple Computer, Inc.
  5. #
  6. # This script sets up the machine enough to run single-user
  7. ##
  8.  
  9. ##
  10. # Set shell to ignore Control-C, etc.
  11. # Prevent lusers from shooting themselves in the foot.
  12. ##
  13. stty intr  undef
  14. stty kill  undef
  15. stty quit  undef
  16. stty susp  undef
  17. stty start undef
  18. stty stop  undef
  19. stty dsusp undef
  20.  
  21. . /etc/rc.common
  22.  
  23. PATH=/bin:/sbin
  24.  
  25. ##
  26. # Arguments
  27. ##
  28. BootType=${1-Multiuser}
  29.  
  30. ##
  31. # Start with some a reasonable hostname
  32. ##
  33. hostname localhost
  34.  
  35. ##
  36. # Are we booting from a CD-ROM?  If so, make a note of the fact.
  37. ##
  38. if [ -d /System/Installation ] && [ -f /private/etc/rc.cdrom ]; then
  39.     ConsoleMessage "Root device is mounted read-only"
  40.     ConsoleMessage "Filesystem checks skipped"
  41.     iscdrom=1
  42. else
  43.     iscdrom=0
  44. fi
  45.  
  46. ##
  47. # Output the date for reference.
  48. ##
  49. date
  50.  
  51. ##
  52. # We must fsck here before we touch anything in the filesystems.
  53. ##
  54. fsckerror=0
  55.  
  56. # Don't fsck if we're single-user, or if we're on a CD-ROM.
  57. if [ ${iscdrom} -ne 1 ]; then
  58.     if [ "${BootType}" = "singleuser" ]; then
  59.     ConsoleMessage "Singleuser boot -- fsck not done"
  60.     ConsoleMessage "Root device is mounted read-only"
  61.     ConsoleMessage "If you want to make modifications to files,"
  62.     ConsoleMessage "run '/sbin/fsck -y' first and then '/sbin/mount -uw /' "
  63.     else
  64.     # We're neither single-user nor on a CD-ROM.
  65.     # Erase the rom's old-style login panel
  66.     ConsoleMessage "Checking disk"
  67.  
  68.     # Benignly clean up ("preen") any dirty filesystems. 
  69.     # fsck -p will skip disks which were properly unmounted during
  70.     # a normal shutdown.
  71.     fsck -p
  72.  
  73.     # fsck's success is reflected in its status.
  74.     case $? in
  75.       0)
  76.         # No problems
  77.         ;;
  78.       2) 
  79.         # Request was made (via SIGQUIT, ^\) to complete fsck
  80.         # but prevent going multi-user.
  81.         ConsoleMessage "Request to remain single-user received"
  82.         fsckerror=1
  83.         ;;
  84.       4)
  85.         # The root filesystem was checked and fixed.  Let's reboot.
  86.         # Note that we do NOT sync the disks before rebooting, to
  87.         # ensure that the filesystem versions of everything fsck fixed
  88.         # are preserved, rather than being overwritten when in-memory
  89.         # buffers are flushed.
  90.         ConsoleMessage "Root filesystem fixed - rebooting"
  91.         reboot -q -n
  92.         ;;
  93.       8)
  94.         # Serious problem was found.
  95.         ConsoleMessage "Reboot failed - serious errors"
  96.         fsckerror=1
  97.         ;;
  98.       12)
  99.         # fsck was interrupted by SIGINT (^C)
  100.         ConsoleMessage "Reboot interrupted"
  101.         fsckerror=1
  102.         ;;
  103.       *)
  104.         # Some other error condition ocurred.
  105.         ConsoleMessage "Unknown error while checking disks"
  106.         fsckerror=1
  107.         ;;
  108.     esac
  109.     fi
  110. fi
  111.  
  112. ##
  113. # Syncronize memory with filesystem
  114. ##
  115. sync
  116.  
  117. ##
  118. # If booted into single-user mode from a CD-ROM, print out some hints 
  119. # about how to fake up /tmp and get to other disks.
  120. ##
  121. if [ "${BootType}" = "singleuser" ] && [ ${iscdrom} -eq 1 ]; then
  122.     echo ""
  123.     echo "You are now in single-user mode while booted from a CD-ROM."
  124.     echo "Since the root disk is read-only, some commands may not work as"
  125.     echo "they normally do.  In particular, commands that try to create"
  126.     echo "files in /tmp will probably fail.  One way to avoid this problem"
  127.     echo "is to mount a separate hard disk or floppy on /tmp using the"
  128.     echo "mount command. For example,'/sbin/mount /dev/fd0a /tmp' puts"
  129.     echo "/tmp on the internal floppy disk."
  130.     echo ""
  131. fi
  132.  
  133. ##
  134. # Try fsck -y and reboot if the above fails horribly.
  135. # This may create a neverending cycle if your root disk is unrecoverably
  136. #  frobbed, and the only recourse them is to power down or boot single
  137. #  user and hope you know what you're doing.
  138. ##
  139. if [ ${fsckerror} -ne 0 ]; then
  140.     fsck -y && reboot
  141. fi
  142.  
  143. ##
  144. # Exit
  145. ##
  146. exit 0
  147.