#!/bin/sh
CONF=/etc/arb/arb.conf
USERCONF=${HOME}/.arb.conf
USERPROP=${HOME}/.arb_prop

[ -s $CONF ]     && . $CONF
# override general settings with user specific settings
[ -s $USERCONF ] && . $USERCONF

# Try to make user working directory for arb data
if [ _"$ARBUSERDATA" != _"" ] ; then
    if [ ! -d $ARBUSERDATA ] ; then
	mkdir -p $ARBUSERDATA || ARBUSERDATA=""
    fi
fi
if [ _"$ARBUSERDATA" != _"" ] ; then
    cd $ARBUSERDATA
    if [ ! -s demo.arb ] ; then
	if [ -s /usr/share/doc/arb/examples/demo.arb.gz ] ; then
	    cp -a /usr/share/doc/arb/examples/demo.arb.gz .
	    gunzip demo.arb.gz
	fi
    fi
fi

# if user has no arb input masks just symlink to the sample masks
[ -d "$USERPROP/inputMasks" ] || mkdir -p "$USERPROP/inputMasks"
MASKS=`ls "$USERPROP/inputMasks" | wc -l`
if [ $MASKS -eq 0 ] ; then
    cd "$USERPROP/inputMasks"
    for mask in `ls /usr/lib/arb/lib/inputMasks/*.mask` ; do
	ln -s $mask .
    done
fi

# Save files as group readable
umask 002

# Warn if the user is not member of group arb and thus not allowed to write
# to /var/lib/arb subdirectories
if ! groups | grep -q -w arb ; then
    cat <<EOF
Warning: User $USER is no member of group arb and thus not allowed to write to
         /var/lib/arb.  This might restrict the functionality of arb.
	 Please ask your system administrator to run
	 
	    dpkg-reconfigure arb-common
	
	 to incllude user $USER into the group of users which have full
	 privilegs to run arb.

EOF
fi

export ARBHOME=/usr/lib/arb
${ARBHOME}/bin/arb
