#!/bin/sh
# 
# runlevel script of the cryptobox package
#
# Copyright (c) 02006, senselab
#
# see LICENSE file in this package for details
#

# check if the cryptobox is installed
[ -e "/usr/lib/cryptobox/cbox-manage.sh" ] || exit 0

# read the default setting file, if it exists
[ -e /etc/default/cryptobox ] && source /etc/default/cryptobox

# startup switch defaults to zero (enabled)
NO_START=${NO_START:-0}

#if [ "$NO_START" = "1" ]
#  then	[ $# -eq 0 ] && exit 0
#	[ "$1" = "status" ] && exit 1
#	[ "$1" = "stop" ] && exit 0
#	echo "CryptoBox is disabled by default"
#	exit 0
# fi

# set CONF_FILE to default value, if not configured in /etc/default/cryptobox
CONF_FILE=${CONF_FILE:-/etc/cryptobox/cryptobox.conf}

# parse config file
if [ -e "$CONF_FILE" ]
  then	source "$CONF_FILE"
  else	echo "[$(basename $0)] - configuration file ($CONF_FILE) not found!" >&2
	exit 1
 fi

case "$1" in
	start )
		# nothing to be done
		;;
	stop )
		# unmount all active containers
		"/usr/lib/cryptobox/cbox-manage.sh" umount_all
		;;
	force-reload | restart )
		"$0" stop 
		"$0" start
		;;
	* )
		echo "invalid action specified - try { start | stop | restart }" >&2
		exit 1
		;;
 esac