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