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

[ -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
	if "mkdir -p $ARBUSERDATA"; 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
	else
	  ARBUSERDATA=""
	fi
    fi
fi
if [ _"$ARBUSERDATA" != _"" ] ; then
    cd $ARBUSERDATA
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 include user $USER into the group of users which have full
	 privilegs to run arb.

EOF
fi

export ARB_PROP ARB_LOCAL_PTS ARB_XTERM ARB_TEXTEDIT
export ARBHOME=/usr/lib/arb
exec ${ARBHOME}/bin/arb "$@"
