# SliTaz package receipt.

PACKAGE="boxbackup-client"
VERSION="0.11.1"
CATEGORY="network"
SHORT_DESC="Client for the BoxBackup on-line backup system"
MAINTAINER="domcox@users.sourceforge.net"
DEPENDS="db libedit libssl perl zlib gcc-lib-base"
SOURCE="boxbackup"
WANTED="boxbackup-server"
WEB_SITE="http://www.boxbackup.org/"
TAGS="backup automatic client"

# Configuration variables                                                                                                    
CONF_DIR="/etc/box"
DATA_DIR="/var/lib/bbackupd"
RUN_DMON=0

# Rules to gen a SliTaz package suitable for Tazpkg
genpkg_rules()
{
	mkdir -p $fs/usr/bin
	cp -a $_pkg/boxbackup-${VERSION}-backup-client-linux-gnu/bb* $fs/usr/bin
	rm -f $fs/usr/bin/*.*
	mkdir -p $fs/etc/init.d
	cp -a $stuff/bbackupd $fs/etc/init.d
}

# Pre and post install commands for Tazpkg

pre_install()
{
	# Stop daemon
	if [ -e /var/run/bbackupd.pid ]; then
		/etc/init.d/bbackupd stop
		RUN_DMON=1
	fi
}

post_install()
{
	# Creating conf dir
	if [ ! -e $1/$CONF_DIR ]; then
	    mkdir -p $1/$CONF_DIR && chmod 755 $1/$CONF_DIR
	fi
	if [ ! -e $1/$DATA_DIR ]; then
	    mkdir -p $1/$DATA_DIR && chmod 700 $1/$DATA_DIR
	fi
	if [ -z $1 ]; then
		# Start daemon (if stopped by install)
		if [ $RUN_DMON -eq 1 ]; then
			/etc/init.d/bbackupd start
		fi
	fi
}

# Pre and post remove commands for Tazpkg

pre_remove()
{
    # Stop daemon
	if [ -z $1 ]; then
		if [ -e /var/run/bbackupd.pid ]; then
			/etc/init.d/bbackupd stop
		fi
	fi
}

post_remove()
{
	# Delete DATA directory
	rm -rf $1/$DATA_DIR

	# Delete Client config files
	rm -rf $1/$CONF_DIR/bbackupd*

	# Delete CONF dir (if empty)
	if [ `ls -lA $CONF_DIR | wc -l` -eq 0 ]; then
		echo -n "Removing $CONF_DIR..."
		rm -rf $1/$CONF_DIR
		status
	fi
	# Delete PID, sock files
	rm -f $1/var/run/bbackupd.*
}