#! /bin/bash
#
# Start the crypto device
#

# Source function library.
. /etc/init.d/functions

RETVAL=0

# See how we were called.
  

start() {
#	echo " : passphrase?" > /dev/console
	losetup /dev/loop0 /crypto.fs
	cryptsetup luksOpen /dev/loop0 homes && mount /home && exit 0
	echo "There is a problem with mounting the home directory." > /dev/console
	echo "Would you like to skip this step and finish booting (y/n)?" > /dev/console
	read -n 1 answer
	echo ""
	if [ $answer == "y" ]; then exit 1; fi
	cryptsetup luksClose homes
	losetup -d /dev/loop0
	start
}

stop() {
	cryptsetup luksClose homes
	losetup -d /dev/loop0
	echo
}	


case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/crond ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
	exit 1
esac

exit $?
