#!/bin/sh

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

test -e /etc/rc.d/init.d/switchev && /etc/rc.d/init.d/switchev restart

#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 -a -e /usr/bin/lightnpower.py ]; then
    lightnpower.py --loadandquit
fi

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

HARDWARE=`cat /proc/cpuinfo | grep 'Hardware' | cut -d':' -f2 | cut -d' ' -f3`
echo "pdaXrom [${HARDWARE}]"

test -f /etc/X11/kb/${HARDWARE}/xmodmap && xmodmap /etc/X11/kb/${HARDWARE}/xmodmap

test -f /etc/X11/kb/userdefined.xmodmap && xmodmap /etc/X11/kb/userdefined.xmodmap

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

test -e /proc/power_key_off && echo "1" >/proc/power_key_off 2>/dev/null
