#!/bin/bash

CONFIG=/etc/nrclientconfig

if test -e $CONFIG; then
  source $CONFIG
  mount -t "$FSTYPE" "$SWAPFILEDEV" /mnt
    
else
  OK=n
  echo 'this is the first time this client boots.'
  echo 'will ask you some questions now, but they will'
  echo 'be saved to the server /tftpboot/$IP/etc/nrclientconfig'
  echo 'directory, so you will only need to do this once.'
  echo '  (if you want all later clients to have the config, do on the server:'
  echo ' cp /tftpboot/$IP/etc/nrclientconfig /etc/nfsroot/default/etc'
  echo
  while test "$mksw" != "1" -o "$mksw" != "1"; do
    echo Total current memory usage:
    free
    echo "Check memory usage above; total mem should be at least 6M (or more)"
    echo "Do you want to:"
    echo "  1 mount a partition (msdos or otherwise), and make a"
    echo "    swapfile on it"
    echo "  2 continue, don't create a swapfile"
    echo "(type 1 or 2 to continue)"
    read mksw
  done
  case "$mksw" in
    "1" 
	while test "$DEVERR" != "0" -a "$ANS" != "q"; do
          echo "Enter device you want to use for swapping, like /dev/hda1 (for DOS C:)
	  echo "or /dev/hda2 for second partition on first disk, or /dev/hdb1 for second disk"
  	  echo  '(or "q" to quit mounting partition altogether) '
	  echo -n 'Devicename: '
	  read ANS
	  SWAPFILEDEV="$ANS"
	  dd if="$SWAPFILEDEV" of=/dev/null count=1
	  DEVERR=$?
	  if test "$DEVERR" != "0"; then
	    echo "something seems to be wrong with the device"
	    echo "(eigher kernel support hasn't been added for this device,"
	    echo "or the /dev entry doesn't exist on the server, or???)"
	  fi
        done
	while test "$DEVERR" != "0" -a "$ANS" != "q"; do
	  echo "what's the filesystem type on this device?"
	  echo " (type 'msdos' for MSDOS FAT; 'q' to quit)"
	  echo -n "fs type: "
	  read ANS
	  FSTYPE="$ANS"
	  mount -t "$FSTYPE" "$DEV" /mnt
	  DEVERR=$?
	  if test "$DEVERR" != "0"; then
            echo "something went wrong when mounting the fs -- please try again"
	  fi
	done
      ;;
  esac
