#!/bin/sh

if [ -e /etc/profile ]; then
    . /etc/profile
fi

#DESKTOP=matchbox
DESKTOP=rox

if [ ! -d ~/.icewm ]; then
    mkdir -p ~/.icewm
    cp -a /usr/share/icewm/defconfig/* ~/.icewm
    echo "gtk-font-name = \"Verdana 12\"" >~/.gtkrc-2.0
fi

makeicemenu

if [ ! -d $HOME/Choices/common ]; then
    mkdir -p $HOME/Choices/common
fi

if [ -f $HOME/Choices/lightnpower.cfg ]; then
    lightnpower.py --loadandquit
fi

if [ -f /usr/bin/gconfd-2 ]; then
    /usr/bin/gconfd-2 15 &
fi

MODEL=`cat /proc/deviceinfo/product`
case "$MODEL" in
    SL-C860|SL-C760) 
	test -f /etc/X11/kb/corgi.xmodmap && xmodmap /etc/X11/kb/corgi.xmodmap
	;;
    SL-6000)
	test -f /etc/X11/kb/tosa.xmodmap && xmodmap /etc/X11/kb/tosa.xmodmap
	;;
    *)
	cat /proc/cpuinfo | grep 'Sharp-Collie' 2>/dev/null >/dev/null && test -f /etc/X11/kb/collie.xmodmap && xmodmap /etc/X11/kb/collie.xmodmap
	;;
esac

test -f /etc/X11/kb/userdefined.xmodmap && xmodmap /etc/X11/kb/userdefined.xmodmap
test -f /usr/bin/chkhinge && /usr/bin/chkhinge 2>/dev/null >/dev/null
test -f /usr/bin/xkeymouse && /usr/bin/xkeymouse 2>/dev/null >/dev/null &

case $DESKTOP in
    rox)
	ROX=`which rox`
	test $ROX && $ROX --pinboard=mypin 2>/dev/null >/dev/null
	;;
    matchbox)
	MATCHBOX=`which matchbox-desktop`
	if [ ! "x$MATCHBOX" = "x" ]; then
	    if [ -f $HOME/.matchbox/mb-desktop-background ]; then
		MBBGND=`cat $HOME/.matchbox/mb-desktop-background`
	    else
		MBBGND=""
	    fi
	    eval "$MATCHBOX $MBBGND" 2>/dev/null >/dev/null &
	fi
	;;
    *)
	;;
esac

icewm 2>/dev/null >/dev/null

GCONF2_PID=`pidof gconfd-2`
if [ ! "$GCONF2_PID" = "" ]; then
    kill $GCONF2_PID
fi
