#!/bin/sh
# Start or stop the cryptohome mount
# Written by Andreas Dehmel, GPL
# http://home.t-online.de/~zarquon

cryptomount=/usr/local/sbin/cryptomount

if [ ! -x ${cryptomount} ]; then
  echo "can't execute ${cryptomount}"
  exit
fi

imagefile=ENTER-YOUR-IMAGEFILE
mountpoint=ENTER-YOUR-MOUNTPOINT

case $1 in
  start|restart|force-reload)
    mountspec=`grep "^[^ ]* ${mountpoint}" /etc/mtab`
    if [ ! "${mountspec}" ]; then
      cryptoparams=""
      read -e -t 30 -p "Enter cipher[:bits] to mount ${mountpoint}... " cryptoparams
      if [ $? -eq 0 ]; then
        cipher=${cryptoparams%%:*}
	if [ "$cipher" ]; then
	  keybits=${cryptoparams##*:}
	  if [ "$keybits" ] && [ "$keybits" != "$cryptoparams" ]; then
	    keyswitch="-k ${keybits}"
	  else
	    keyswitch=""
	  fi
          #echo ${cryptomount} -e ${cipher} ${keyswitch} ${imagefile} ${mountpoint}
          ${cryptomount} -e ${cipher} ${keyswitch} ${imagefile} ${mountpoint}
	else
	  echo "No cipher."
	fi
      else
        echo "Timeout."
      fi
    fi
    ;;
  stop)
    ${cryptomount} -u ${mountpoint}
    ;;
esac
