home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / private / etc / rc.boot < prev    next >
Text File  |  1992-05-12  |  8KB  |  231 lines

  1. #!/bin/sh -u
  2. #
  3. # This script sets up the machine enough to run single-user
  4. #
  5. # Copyright (C) 1992 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. HOME=/; export HOME
  11. PATH=/etc:/usr/etc:/bin:/usr/bin; export PATH
  12.  
  13. iscdrom=0
  14.  
  15. (echo)                                 > /dev/console
  16.  
  17. # Are we booting from a CD-ROM?  If so, make a note of the fact.
  18.  
  19. if [ -d /NextCD ]; then
  20.   (echo "Root device is a CD-ROM.  Filesystem checks skipped.") > /dev/console
  21.   iscdrom=1
  22. fi
  23.  
  24. swapfile=/private/vm/swapfile
  25. swapdir=/private/vm
  26.  
  27. # We must fsck here before we touch anything in the filesystems.
  28. fsckerror=0
  29.  
  30. # Output the date for reference.
  31. date                                >/dev/console
  32.  
  33. # Don't fsck if we're single-user, or if we're on a CD-ROM.
  34.  
  35. if [ $1x = singleuserx -a $iscdrom -ne 1 ]; then
  36.     (echo "Singleuser boot -- fsck not done")        >/dev/console
  37.     # Ensure that the root filesystem is mounted read-write.
  38.     mount -o remount /                    >/dev/console
  39.     # Is there a swapfile?  Print a warning if not.
  40.     if [ ! -f $swapfile ]; then
  41.         (echo "No default swapfile present!")        >/dev/console
  42.     fi
  43. elif [ $iscdrom -ne 1 ]; then
  44.     # We're neither single-user nor on a CD-ROM.
  45.     fbshow -A -B -E -I "Checking*Disk..."
  46.     (echo Checking disks)                    >/dev/console
  47.     # Benignly clean up ("preen") any dirty filesystems. 
  48.     # fsck -p will skip disks which were properly unmounted during
  49.     # a normal shutdown.
  50.     fsck -p                         >/dev/console 2>&1
  51.     # fsck's success is reflected in its status.
  52.     case $? in
  53.         0)
  54.             # No problems
  55.         ;;
  56.         2) 
  57.             # Request was made (via SIGQUIT, ^\) to complete fsck
  58.         # but prevent going multi-user.
  59.         (echo "Request to remainD8Pgle-user received.") > /dev/console
  60.         fsckerror=1
  61.         ;;
  62.         
  63.         4)
  64.         # The root filesystem was checked and fixed.  Let's reboot.
  65.         # Note that we do NOT sync the disks before rebooting, to
  66.         # ensure that the filesystem versions of everything fsck fixed
  67.         # are preserved, rather than being overwritten when in-memory
  68.         # buffers are flushed.
  69.         (echo "Root fixed - rebooting.")        >/dev/console
  70.         reboot -q -n
  71.         ;;
  72.         8)
  73.         # Serious problem was found.
  74.         (echo "Reboot failed...help!")            >/dev/console
  75.         fsckerror=1
  76.         ;;
  77.         12)
  78.         # fsck was interrupted by SIGINT (^C)
  79.         (echo "Reboot interrupted.")            >/dev/console
  80.         fsckerror=1
  81.         ;;
  82.         *)
  83.         # Some other error condition ocurred.
  84.         (echo "Unknown error in reboot fsck.")        >/dev/console
  85.         fsckerror=1
  86.         ;;
  87.     esac
  88.     # Ensure root filesystem is mounted read-write.
  89.     mount -o remount /                    >/dev/console
  90.     # Make sure the swapfile exists
  91.     if [ ! -f $swapfile ]; then
  92.         (echo -n "Creating default swapfile")        >/dev/console
  93.         mkdirs -o root -g wheel -m 755 $swapdir
  94.         touch $swapfile
  95.         # Swapfile needs to have the "sticky" bit set.
  96.         chmod 1600 $swapfile
  97.         (echo " - rebooting")                >/dev/console
  98.         reboot -q
  99.     fi
  100. fi
  101.  
  102. # Read in configuration information.
  103. . /etc/hostconfig
  104.  
  105. # Fake mount entries for root and private filesystems (i.e., ensure that
  106. # they appear in /etc/mtab; filesystems mounted by the kernel aren't yet
  107. # recorded in mtab).
  108.  
  109. if [ $iscdrom -ne 1 ]; then
  110.     (echo "Faking root mount entries")            >/dev/console
  111.     # Clean out /etc/mtab.
  112.     > /etc/mtab
  113.     mount -f /
  114.     mount -f /private
  115. fi
  116.  
  117. # Configure network interfaces, based on the /etc/hostconfig parameters.
  118. # We're going to build the arguments for ifconfig, to turn on the default
  119. # network interface.  The complete command (depending on the hostconfig
  120. # parameters) will look something like this:
  121. #
  122. #   ifconfig en0 INETADDR netmask IPNETMASK broadcast IPBROADCAST -trailers up 
  123. #
  124. # where the uppercase words are replaced by their respecitve hostconfig
  125. # variables.  Note that ifconfig and hostname place special meaning on
  126. # -AUTOMATIC-.
  127.  
  128. ifconfigerror=0
  129.  
  130. # If INETADDR isn't -NO-, we'll configure the en0 interface to the
  131. # specified IP address.  If INETADDR is -AUTOMATIC-, ifconfig will
  132. # broadcast a BOOTP request to determine our IP address.
  133.  
  134. if [ "${INETADDR=-AUTOMATIC-}" != "-NO-" ]; then
  135.     (echo "Configuring ethernet interface to $INETD8Q")    >/dev/console
  136.     # If IPNETMASK is empty, no "netmask" clause will be included in the
  137.     # ifconfig. This corresponds to the "Default" setting in HostManager's
  138.     # Local Configuration panel, and results in a network mask based on
  139.     # class of the machine's IP address.  If IPNETMASK is -AUTOMATIC-,
  140.     # ifconfig will broadcast an ICMP Address Mask Request, asking the
  141.     # machines on the network to provide the netmask.
  142.     #
  143.     # Note that if you specify an explicit netmask, it will be combined
  144.     # (using the logical OR operation) with the default netmask based on
  145.     # the class of your network.
  146.     if [ -n "${IPNETMASK=}" ]; then
  147.         IFFLAGS="netmask $IPNETMASK"
  148.     else
  149.         IFFLAGS=
  150.     fi
  151.     # If IPBROADCAST is empty, no "broadcast" clause will be included
  152.     # in the ifconfig, and the default broadcast address will be used.
  153.     # The default broadcast address is obtained by performing a logical
  154.     # OR operation on our IP address and the logical NOT of the netmask.
  155.     # (E.g., an IP address 192.42.172.1 and a netmask of ffffff00 will
  156.     # yield a broadcast address of 192.42.172.255.)
  157.     if [ "${IPBROADCAST=-AUTOMATIC-}" != "-AUTOMATIC-" -a \
  158.         -n "${IPBROADCAST}" ]; then
  159.         IFFLAGS="$IFFLAGS broadcast $IPBROADCAST"
  160.         (echo "Setting broadcast address to $IPBROADCAST.") > /dev/console
  161.     else
  162.         (echo "Using default broadcast address") > /dev/console
  163.     fi
  164.     fbshow -A -B -E -I "Checking*for*Network..."
  165.     # Run ifconfig with the specified parameters, bringing the interface
  166.     # up (and not using trailers!).
  167.     ifconfig en0 $INETADDR $IFFLAGS -trailers up    >/dev/console 2>&1
  168.     ifconfigerror=$?
  169.     # If we got an error, don't bother trying to do automatic hostname
  170.     # acquisition (if that's specified).
  171.     if [ $ifconfigerror -ne 0 -a \
  172.         "${HOSTNAME=-AUTOMATIC-}" = "-AUTOMATIC-" ]; then
  173.         HOSTNAME=-NO-
  174.     fi
  175. else
  176.     (echo "Skipping ethernet interface configuration")    >/dev/console
  177. fi
  178.  
  179. # Turn on the loopback interface.  This one's much easier...
  180. ifconfig lo0 127.0.0.1 up
  181.  
  182. hosterror=0
  183.  
  184. # If HOSTNAME is -AUTOMATIC-, the hostname command broadcasts a BOOTP
  185. # request to determine its hostname.
  186.  
  187. if [ "${HOSTNAME=-AUTOMATIC-}" != "-NO-" ]; then
  188.     if [ $HOSTNAME != -AUTOMATIC- ]; then
  189.         (echo "Configuring hostname to $HOSTNAME")    >/dev/console
  190.     fi
  191.     # hostname knows about -AUTOMATIC-
  192.     hostname $HOSTNAME                >/dev/console 2>&1
  193.     hosterror=$?
  194. else
  195.     # This is NOT the place to change yoD8Rostname.  Change it 
  196.     # using the HostManager application.
  197.     (echo "Setting hostname to localhost")        >/dev/console
  198.     /bin/hostname localhost
  199. fi
  200.  
  201. sync
  202.  
  203. # If booted into single-user mode from a CD-ROM, print out some hints 
  204. # about how to fake up /tmp and get to other disks.
  205.  
  206. if [ $1x = singleuserx -a $iscdrom -eq 1 ]; then
  207.     (( 
  208.         echo ""
  209.     echo "You are now in single-user mode while booted from a CD-ROM."
  210.     echo "Since the root disk is read-only, some commands may not work as"
  211.     echo "they normally do.  In particular, commands that try to create"
  212.     echo "files in /tmp will probably fail.  One way to avoid this problem"
  213.     echo "is to mount a separate hard disk or floppy on /tmp using the"
  214.     echo "mount command.  For example,'/etc/mount -n /dev/fd0a /tmp' puts"
  215.     echo "/tmp on the internal floppy disk of a NeXTstation. (The -n"
  216.     echo "option prevents mount from trying to record the mount in"
  217.     echo "/etc/mtab.)"
  218.     echo ""
  219.     ) > /dev/console )
  220. fi
  221.  
  222. # Exit with error if failed above.  ifconfig exits 1 if the error is 
  223. # a showstopper and 2 if it is not.  The only non-showstopper is the network
  224. # being down.
  225.  
  226. if [ $fsckerror -ne 0 -o $ifconfigerror -eq 1 -o $hosterror -ne 0 ]; then
  227.     exit 1
  228. fi
  229.  
  230. exit 0
  231.