#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

P=xfce4-session
cd /tmp
[ -f $P.tcz ] || ( echo "pls place the tcz into tmp exitting now" && exit 1)

USER=`cat /etc/sysconfig/tcuser`
LIST="squashfs-tools"
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

unsquashfs $P.tcz
rm -rf $P.tcz
mv squashfs-root $P
TI=$P/usr/local/tce.installed/$P
rm -rf $TI

# fix tce.installed
##############

cat > $TI << 'EOF'
#!/bin/sh
# home Dir stuff
#################
USER=`cat /etc/sysconfig/tcuser`
LOOP=/tmp/tcloop/xfce4-session/usr/local/share/doc/xfce4-session/template
# test file exists - add if not found
[ -f /home/$USER/Zsession ] || ( cp $LOOP /home/$USER/Zsession && chown $USER /home/$USER/Zsession )

# create XFCE xsession 
cp -f /home/$USER/Zsession /home/$USER/.xsession
chown $USER /home/$USER/.xsession
chmod 755 /home/$USER/.xsession

# start daemon if not running already
#############
[ -f /var/run/dbus/pid ] || /usr/local/etc/init.d/dbus start

# refresh hicolor icons  
######################
sh /usr/local/tce.installed/hicolor-icon-theme
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 755 $P/usr/local/tce.installed


# TCZ them
#######
LIST="$P "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

