home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-User.iso / usr / template / client / etc / rc.boot.standard < prev    next >
Text File  |  1996-02-27  |  4KB  |  157 lines

  1. #!/bin/sh -u
  2. #
  3. # This script sets up the machine enough to run single-user
  4. #
  5. # Copyright (C) 1993 by NeXT Computer, Inc.  All rights reserved.
  6. #
  7. # Note that all "echo" commands are in parentheses so that
  8. # the main shell does not open a tty and get its process group set.
  9.  
  10. #
  11. # Initialize the path to be used and inherited by all the commands herein
  12. #
  13. if [ -f /.path ]; then
  14.     . /.path
  15. else
  16.     PATH=/usr/ucb:/bin:/usr/bin:/etc:/usr/etc; export PATH
  17.     HOME=/; export HOME
  18. fi
  19.  
  20. iscdrom=0
  21.  
  22. (echo)                                 >> /dev/console
  23.  
  24. # Start with some -- any! -- reasonable hostname
  25. hostname localhost
  26.  
  27. # Are we booting from a CD-ROM?  If so, make a note of the fact.
  28.  
  29. if [ -d /NextCD -a -f /private/etc/rc.cdrom ]; then
  30.   (echo "Root device is mounted read-only.")    >>/dev/console
  31.   (echo "Filesystem checks skipped.")        >>/dev/console
  32.   iscdrom=1
  33. fi
  34.  
  35. swapfile=/private/vm/swapfile
  36. swapdir=/private/vm
  37.  
  38. # We must fsck here before we touch anything in the filesystems.
  39. fsckerror=0
  40.  
  41. # Output the date for reference.
  42. date                                >>/dev/console
  43.  
  44. # Don't fsck if we're single-user, or if we're on a CD-ROM.
  45.  
  46. if [ $1x = singleuserx -a $iscdrom -ne 1 ]; then
  47.     (echo "Singleuser boot -- fsck not done")        >>/dev/console
  48.     # Ensure that the root filesystem is mounted read-write.
  49.     mount -o remount /                    >>/dev/console
  50.     # Is there a swapfile?  Print a warning if not.
  51.     if [ ! -f $swapfile ]; then
  52.         (echo "No default swapfile present!")        >>/dev/console
  53.     fi
  54. elif [ $iscdrom -ne 1 ]; then
  55.     # We're neither single-user nor on a CD-ROM.
  56.     # Erase the rom's old-style login panel
  57.     fbshow -B -E
  58.     fbshow -B -I "Checking disk" -z 5
  59.     (echo Checking disks)                    >>/dev/console
  60.     # Benignly clean up ("preen") any dirty filesystems. 
  61.     # fsck -p will skip disks which were properly unmounted during
  62.     # a normal shutdown.
  63.     fsck -p                         >>/dev/console 2>&1
  64.     # fsck's success is reflected in its status.
  65.     case $? in
  66.         0)
  67.             # No problems
  68.         ;;
  69.         2) 
  70.             # Request was made (via SIGQUIT, ^\) to complete fsck
  71.         # but prevent going multi-user.
  72.         (echo "Request to remain single-user received.") >>/dev/console
  73.         fsckerror=1
  74.         ;;
  75.         
  76.         4)
  77.         # The root filesystem was checked and fixed.  Let's reboot.
  78.         # Note that we do NOT sync the disks before rebooting, to
  79.         # ensure that the filesystem versions of everything fsck fixed
  80.         # are preserved, rather than being overwritten when in-memory
  81.         # buffers are flushed.
  82.         (echo "Root fixed - rebooting.")        >>/dev/console
  83.         reboot -q -n
  84.         ;;
  85.         8)
  86.         # Serious problem was found.
  87.         (echo "Reboot failed...help!")            >>/dev/console
  88.         fsckerror=1
  89.         ;;
  90.         12)
  91.         # fsck was interrupted by SIGINT (^C)
  92.         (echo "Reboot interrupted.")            >>/dev/console
  93.         fsckerror=1
  94.         ;;
  95.         *)
  96.         # Some other error condition ocurred.
  97.         (echo "Unknown error in reboot fsck.")        >>/dev/console
  98.         fsckerror=1
  99.         ;;
  100.     esac
  101.     # Ensure root filesystem is mounted read-write.
  102.     mount -o remount /                    >>/dev/console
  103.     # Make sure the swapfile exists
  104.     if [ ! -f $swapfile ]; then
  105.         (echo -n "Creating default swapfile")        >>/dev/console
  106.         mkdirs -o root -g wheel -m 755 $swapdir
  107.         touch $swapfile
  108.         # Swapfile needs to have the "sticky" bit set.
  109.         chmod 1600 $swapfile
  110.         (echo " - rebooting")                >>/dev/console
  111.         reboot -q
  112.     fi
  113. fi
  114.  
  115. # Read in configuration information.
  116. . /etc/hostconfig
  117.  
  118. # Fake mount entries for root and private filesystems (i.e., ensure that
  119. # they appear in /etc/mtab; filesystems mounted by the kernel aren't yet
  120. # recorded in mtab).
  121.  
  122. if [ $iscdrom -ne 1 ]; then
  123.     (echo "Setting up root mount entries")            >>/dev/console
  124.     # Clean out /etc/mtab.
  125.     > /etc/mtab
  126.     mount -f /
  127.     mount -f /private
  128. fi
  129.  
  130. sync
  131.  
  132. # If booted into single-user mode from a CD-ROM, print out some hints 
  133. # about how to fake up /tmp and get to other disks.
  134.  
  135. if [ $1x = singleuserx -a $iscdrom -eq 1 ]; then
  136.     (( 
  137.         echo ""
  138.     echo "You are now in single-user mode while booted from a CD-ROM."
  139.     echo "Since the root disk is read-only, some commands may not work as"
  140.     echo "they normally do.  In particular, commands that try to create"
  141.     echo "files in /tmp will probably fail.  One way to avoid this problem"
  142.     echo "is to mount a separate hard disk or floppy on /tmp using the"
  143.     echo "mount command.  For example,'/etc/mount -n /dev/fd0a /tmp' puts"
  144.     echo "/tmp on the internal floppy disk. (The -n option prevents mount"
  145.     echo "from trying to record the mount in /etc/mtab.)"
  146.     echo ""
  147.     ) >> /dev/console )
  148. fi
  149.  
  150. # Exit with error if failed above.
  151.  
  152. if [ $fsckerror -ne 0 ]; then
  153.     exit 1
  154. fi
  155.  
  156. exit 0
  157.