#!/bin/sh
#
# bestcrypt         Encrypted File Systems.
#
# Version:      1.2
#
# Revision:  $Id: bcrypt,v 1.9 2004/02/10 10:06:23 nail Rel-1.6-2 $
#
# Author:       Jetico Inc. (support@jetico.com)
#

# chkconfig: 2345 85 98
# description: BestCrypt init script


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

# See how we were called.

KERNEL_VERSION=`uname -r|sed 's/\(.\..\).*/\1/'`
INSMOD=modprobe
DEPMOD=depmod

MAJOR=188
MINOR=0

case "$1" in
  start)
	echo "Initializing BestCrypt."
	rm -rf /dev/bcrypt?* 2>/dev/null
        if [ $KERNEL_VERSION = "2.2" ]; then
	    MAJOR=7
	    MINOR=128
	fi
	
	for (( x=0 ; x<16 ; x++)) ; do
	    mknod -m 666 /dev/bcrypt$x b $MAJOR $(( MINOR+x )) ;
	done

	$DEPMOD -a
	
	$INSMOD bc
	$INSMOD bc_blowfish
	$INSMOD bc_des
	$INSMOD bc_gost
	$INSMOD bc_twofish
	$INSMOD bc_bf448
	$INSMOD bc_bf128
	$INSMOD bc_3des
	$INSMOD bc_idea
	$INSMOD bc_rijn
	$INSMOD bc_cast
        touch /var/lock/subsys/bcrypt
	echo
	;;
  stop)
	echo -n "Unmounting encrypted filesystems."
	grep BestCrypt /etc/mtab |awk '{print $2}'|xargs -r -n 1 bctool umount 
	for i in `lsmod |egrep "^bc_.*" |awk '{print $1}' `; do rmmod $i; done
	rmmod bc
	rm -f /dev/bcrypt?* 2>/dev/null
	rm -f /var/lock/subsys/bcrypt
	echo
	;;
  status)
	if [ -f /proc/bcrypt/bc.stat ] ; then
	    cat /proc/bcrypt/bc.stat	
	else
		echo "/proc filesystem unavailable"
	fi
	;;
  restart)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit 0

