home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / private / etc / rc.swap < prev    next >
Text File  |  1993-08-23  |  4KB  |  115 lines

  1. #!/bin/sh -u
  2. #
  3. # This script mounts and initializes the internal swapdisk which we mount
  4. # on /tmp.
  5. #
  6. # Copyright (C) 1992 by NeXT Computer, Inc.  All rights reserved.
  7. #
  8. # This script is invoked automatically when booted from a CD-ROM.
  9. # Trying to run it directly will probably not do what you expect.
  10.  
  11. NEWSWAPDIR=/private/swapdisk/vm
  12. NEWSWAPFILE=$NEWSWAPDIR/swapfile
  13.  
  14. # Find out which devices to check.  The result of this command will
  15. # be a list of the SCSI disks installed (specifically, the A partitions
  16. # of all these disks).
  17.  
  18. DRIVES=`echo /dev/sd?a | sed -e 's/\/dev\///g'`
  19.  
  20. useswap=0
  21. for SWAPDEV in $DRIVES
  22. do
  23.     # checkswap looks to see if a swapdisk is there.  In the cases for
  24.     # 1 and 2, below, the echos are commented out because these are
  25.     # normal conditions (especially case 2).
  26.     /usr/etc/checkswap -f /dev/r${SWAPDEV}
  27.     swapstatus=$?
  28.     case $swapstatus in
  29.         0)
  30.         # No such disk was actually connected.
  31. #        break;
  32.         ;;
  33.         1)
  34.         # Disk was there, but didn't have any label.
  35. #        (echo "No valid label on ${SWAPDEV}.")        >/dev/console
  36.         ;;
  37.         2)
  38.         # Disk was there, it had a label, and it's not a swapdisk
  39. #        (echo "/dev/$SWAPDEV is not a swapdisk!")    >/dev/console
  40.         ;;
  41.         3)
  42.         # We have a swapdisk (or, a disk labeled swapdisk).
  43.         if [ $1x = autobootx ]; then
  44.             # If we did a normal boot, do an fsck on the swapdisk
  45.             fbshow -B -I "Checking swapdisk" -z 20
  46.             (echo "Checking swapdisk ${SWAPDEV}") > /dev/console
  47.             /usr/etc/fsck -p /dev/r${SWAPDEV} >/dev/console 2>&1 \
  48.                 && useswap=1
  49.         else
  50.             useswap=1
  51.         fi
  52.         break
  53.         ;;
  54.         *)
  55.         # swapdisk said something unintelligible.
  56.         (echo "Unknown error from checkswap, error=$swapstatus") \
  57.                                 >/dev/console
  58.         ;;
  59.     esac
  60. done
  61.  
  62. # We have a swap disk, set things up to use it.
  63. if [ $useswap -eq 1 ]; then
  64.     # Mount the swapdisk on /private/swapdisk
  65.     fbshow -B -I "Mounting swapdisk" -z 21
  66.     /usr/etc/mount -o rw,noquota,noauto /dev/${SWAPDEV} /private/swapdisk \
  67.                             >/dev/console 2>&1
  68.     # Set up swapping on it.  We need the SWAPDIR and the SWAPFILE.
  69.     # If we make the file anew, we turn on its sticky bit, and ensure
  70.     # that only root can read it.
  71.     if [ ! -d $NEWSWAPDIR ]; then
  72.         (echo "Creating vm directory on swapdisk")    >/dev/console
  73.         mkdir $NEWSWAPDIR
  74.         chmod 755 $NEWSWAPDIR
  75.     fi
  76.     if [ ! -f $NEWSWAPFILE ]; then
  77.         (echo "Creating swapfile on swapdisk")        >/dev/console
  78.         touch $NEWSWAPFILE
  79.         chmod 1600 $NEWSWAPFILE
  80.     fi
  81.     # Turn on paging to the swapdisk.  Note the high water mark (hiwat):
  82.     # this helps ensure the swapdisk doesn't get full.
  83.     /usr/etc/mach_swapon -v -o prefer,lowat=16777216,hiwat=31457280 \
  84.                         $NEWSWAPFILE >/dev/console 2>&1
  85.  
  86.     # Make sure there is a tmp directory.  Note the sticky bit, which
  87.     # is critical for security.
  88.     if [ ! -d /private/swapdisk/tmp ]; then
  89.         (echo "Creating tmp directory on swapdisk")    >/dev/console
  90.         mkdir /private/swapdisk/tmp
  91.         chmod 1777 /private/swapdisk/tmp
  92.     fi
  93.  
  94.     # Point /private/tmp to the swapdisk's tmp directory.  We assume
  95.     # that if /private/tmp is a symlink, then either it references
  96.     # the swapdisk already or the user who modified it knew what
  97.     # he or she was doing.
  98.     if [ ! -h /private/tmp ]; then
  99.         (echo "Linking /private/tmp to /private/swapdisk/tmp") \
  100.                                 >/dev/console
  101.         rm -rf /private/tmp
  102.         (cd /private; ln -s swapdisk/tmp)
  103.     fi
  104. else
  105.     # No swapdisk; ensure /private/tmp is a directory.
  106.     if [ ! -d /private/tmp ]; then
  107.         (echo "Creating /private/tmp directory")    >/dev/console
  108.         rm -f /private/tmp
  109.         mkdir /private/tmp
  110.         chmod 1777 /private/tmp
  111.     fi
  112. fi
  113.  
  114. exit 0
  115.