#!/bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin
swapfile="SwapFile"
machine=`cat /proc/cpuinfo |grep Hardware | sed s/Hardware.*:.SHARP.//`
devs="/media/cf /media/card"
defaultswap="/media/card"
defswapsize=16

if [ $machine = "Akita" ]; then
  for dev in $devs
  do
    echo "$dev"
    if [ -e "$dev/$swapfile" ]; then
       devswap=$dev
       echo "Swap : $dev/$swapfile"
    fi
  done
fi

# if no swap
if [ ! $devswap ]; then
  echo -n "Voulez vous creer une swap ? [Y/n] : "
  read a
  if [ "$a" != "n" ]; then
	echo "Creation swap"
        echo "Sur quel peripherique ?"
	for dev in $devs
	do
	   echo $dev
	done
	echo -n "Defaut $defaultswap :"
	read b
	devswap=$defaultswap
	if [ "$b" ]; then
	   devswap=$b
        fi
        echo -n "Taille de la swap en Mo : [$defswapsize] :"
	read size
	swapsize=$defswapsize
	if [ "$size" ]; then
	   swapsize=$size
        fi
	echo "Creation d'une swap de $swapsize Mo sur $devswap"
	echo "Patientez ..."
	/bin/dd if=/dev/zero of=$devswap/$swapfile bs=1M count=$swapsize
	/sbin/mkswap $devswap/$swapfile
  fi
fi

echo "Montage de la swap"
/sbin/swapon $devswap/$swapfile

echo "$devswap/$swapfile" > /etc/.swapfile


