#/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  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

P=weston.ini
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`
C=/home/$USER/.config
W=weston.ini
L=/tmp/tcloop/weston.ini/usr/local/share/$W/$W

# test if ini exists if not create it
[  -f $C/$W  ] || cp $L  $C/
chown $USER $C/$W
chmod 644 $C/$W
EOF

chown -R root:staff $P/usr/local/tce.installed
chmod -R 755 $P/usr/local/tce.installed
################################
S=$P/usr/local/share/$P
mkdir -p $S

echo '[keyboard]
keymap_layout=us

[shell]
background-image=/usr/local/share/weston/background.png

[launcher]
icon=/usr/local/share/weston/terminal.png
path=/usr/local/bin/weston-terminal

[launcher]
icon=/usr/local/share/pixmaps/gedit.png
path=/usr/local/bin/gedit

[launcher]
icon=/usr/local/share/pixmaps/org.gnome.Nautilus.png
path=/usr/local/bin/nautilus

[launcher]
icon=/usr/local/share/pixmaps/org.gnome.Epiphany.png
path=/usr/local/bin/epiphany

[launcher]
icon=/usr/local/share/pixmaps/exittc.png
path=/usr/local/bin/exittc

[core]
xwayland=true

[xwayland]
path=/usr/local/bin/Xwayland' > $S/$P

# 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

ls -hal

echo 'Title:          weston.ini.tcz  
Description:    Create a weston.ini 
Version:        1.0
Author:         aus9 
Original-site:  TC
Copying-policy: Open source
Size:	           4.0K	
Extension_by:   aus9 at gmx dot com
Tags:           weston
Comments:       The current weston TCE has no weston.ini
                This install script attempts to create one
                with mainly gnome apps. Do not have this in your 
                onboot list please. Designed to be run once.
                $ tce-load -i weston.ini

                After loading, edit .config/weston.ini to suit what apps you
                prefer to run instead.

                Be aware that you will get an icon that looks like
                X 
                if you have not loaded that app for a particular boot.

                fltk or gtk1/2 apps will neeed xwayland loaded to run them.
                The last icon is for exittc so likely to appear as X as its FLTK based.
                
                Compiled for 64 9.x
Change-log:     2018/11/27  First version 
Current:        2018/11/27 ' > $P.tcz.info

submitqc --libs