#! /bin/bash

set -e
DIR=/var/cache/siguibui
SUBDIR=$DIR/shellserver-tasks
if [ ! -d $SUBDIR ] ; then 
	mkdir -p $SUBDIR
fi
chmod uog+rwx $DIR $SUBDIR
F1=/etc/init.d/siguibui.dpkg-dist
F2=/etc/init.d/siguibui
if [ -f $F1 -a ! -f $F2 ] ; then
	mv $F1 $F2
fi

F3=/etc/siguibui/sidu-shellserver.conf
if ! grep -q "^CONSOLE=" $F3 ; then
	CONSOLE=
	if which konsole ; then
		CONSOLE=konsole
	elif which lxterminal ; then
		CONSOLE=lxterminal
	elif which xfce4-terminal ; then
		CONSOLE=xfce4-terminal
	elif which xterm ; then
		CONSOLE=xterm
	else
		CONSOLE=x-terminal-emulator
	fi
	test -n "$CONSOLE" && sed -i -e "s/^#CONSOLE=.*/CONSOLE=$CONSOLE/;" $F3
fi
function MkLink2(){
	if [ ! -L $2 ] ; then
		ln -s $1 $2
	fi
}
PUBLIC=/var/cache/siguibui/public
if [ ! -d $PUBLIC ] ; then
	mkdir $PUBLIC
fi
MkLink2 $PUBLIC /usr/share/siguibui
chmod uog+rw $PUBLIC

if grep -q ":1000:" /etc/passwd ; then
	home=$(grep ":1000:" /etc/passwd | head -n 1 | cut -d: -f6)
	sed -i -e "s%^START_GUI_HOME2=.*%START_GUI_HOME2=$home%;" /etc/siguibui/sidu-shellserver.conf
fi

#DEBHELPER#
exit 0