#!/bin/sh

SWAP_ON=0
SWAP_PATH=/media/hdd
SWAP_SIZE=128
SWAP_FILE=/swapfile
SWAP_BSIZE=1

SWAPNAME=$SWAP_PATH$SWAP_FILE

case "$1" in
    start)
	if [ $SWAP_ON -ne 0 ]; then
		if [ -f $SWAPNAME ]; then
			echo -n "starting SWAP... "
			/sbin/swapon $SWAPNAME
			echo "done."
		else
			echo "ERROR: $SWAPNAME is missing."
		fi
	fi
	;;
    stop)
	echo -n "stopping SWAP... "
	/sbin/swapoff $SWAPNAME
	echo "done."
	;;
    create)
	if [ ! -f $SWAPNAME ]; then
		echo -n "create SWAP... "
		dd if=/dev/zero of=$SWAPNAME bs=1048576 count=$SWAP_SIZE
		mkswap $SWAPNAME
		echo "done."
	fi
	$0 start
	;;
    delete)
	$0 stop
	if [ -f $SWAPNAME ]; then
		echo -n "delete SWAP... "
		rm -rf $SWAPNAME
		echo "done."
	fi
	;;
    *)
	echo "Usage: $0 {start|stop|delete|create}"
	exit 1
	;;
esac

exit 0
