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

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

P=xfce4-TC
cd /tmp

# tce.installed
##############
mkdir -p $P/usr/local/tce.installed

cat > $P/usr/local/tce.installed/$P << 'EOF'
#/bin/sh
USER=`cat /etc/sysconfig/tcuser`
L=/tmp/tcloop/Xprogs/usr/local/share/applications
D=/home/$USER/Desktop

APPS=tinycore-apps.desktop
CPANEL=tinycore-cpanel.desktop
EXIT=tinycore-exittc.desktop
MNT=tinycore-mnttool.desktop
SVS=tinycore-services.desktop
RUN=tinycore-flrun.desktop
SNAP=tinycore-screenshot.desktop


# test if desktops exists if not create them
# they are not sym linked as I make changes
[  -f $D/$APPS   ] || cp $L/$APPS   $D/
[  -f $D/$CPANEL ] || cp $L/$CPANEL $D/
[  -f $D/$EXIT   ] || cp $L/$EXIT   $D/
[  -f $D/$MNT    ] || cp $L/$MNT    $D/
[  -f $D/$SVS    ] || cp $L/$SVS    $D/
[  -f $D/$RUN    ] || cp $L/$RUN    $D/
[  -f $D/$SNAP   ] || cp $L/$SNAP   $D/


# fix one gremlin in case in my testing
rm -rf $D/applications

chown $USER -R $D
chmod 755   -R $D

# now fix up some icons
cd $D
sed '/OnlyShowIn=Old;/d' -i $RUN
sed '/OnlyShowIn=Old;/d' -i $SNAP

# as all icon themes are loaded lets improve icon?
sed s'|Icon=services|Icon=preferences-desktop|' -i $SVS
sed s'|/usr/local/share/pixmaps/services.png|/tmp/tcloop/adwaita-icon-theme/usr/local/share/icons/Adwaita/48x48/categories/applications-utilities.png|' -i $SVS

EOF

chown -R root:staff $P/usr/local/tce.installed
chmod -R 755 $P/usr/local/tce.installed

# copyright
mkdir -p $P/usr/local/share/doc/
echo 'TinyCore Linux Team have the 
same copyright to this TCZ
as Xprogs ' > $P/usr/local/share/doc/copyright
# submitqc does not like this but I am OK with it

# 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

echo 'Xprogs.tcz
adwaita-icon-theme.tcz ' > $P.tcz.dep

echo 'Title:          xfce4-TC.tcz  
Description:    TC desktops for XFCE
Version:        1.0
Author:         TC team, roberts and others 
Original-site:  TC
Copying-policy: Open source
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       The TC desktops mainly for exit 
                as I have deleted the XFCE exit menu.
                

                Compiled for 64 9.x
Change-log:     2018/04/22  First version 
Current:        2018/04/22 ' > $P.tcz.info

submitqc --libs