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

P=sway-dot
USER=`cat /etc/sysconfig/tcuser`
LIST="submitqc "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
mkdir -p $P/usr/local/share/$P

# create template
##############
echo '#!/bin/sh
tce-load -i sway
[ -f /var/run/dbus/pid ] || sudo /usr/local/etc/init.d/dbus start
GDK_BACKEND=wayland
XDG_SESSION_TYPE=wayland
export $GDK_BACKEND
export $XDG_SESSION_TYPE
XDG_RUNTIME_DIR=/run/user/1001 dbus-run-session sway

' > $P/usr/local/share/$P/z

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

echo '#!/bin/sh
USER=`cat /etc/sysconfig/tcuser`
LOOP=/tmp/tcloop/sway-dot/usr/local/share/sway-dot/z
DOT=/home/$USER/.local/bin
if [ ! -x $DOT/z ] ; then
   cp $LOOP $DOT/
   chmod 755 $DOT/z
   chown "$USER":staff $DOT/z
fi   ' > $P/usr/local/tce.installed/$P 

chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $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

ls -hal

echo 'Title:          sway-dot.tcz 
Description:    local bin file to start sway
Version:        1.0
Author:         aus9
Original-site:  Tinycore
Copying-policy: open source 
Size:           4.0K	
Extension_by:   aus9 at gmx dot com
Tags:           sway
Comments:       startx is used to start a libX or Xorg DE or WM
                sway runs on Wayland so to allow people to try sway
                I have elected to give them a dot local bin file called
                z.....to use at the exit at prompt to launch sway

                See sway info on how to exit sway and then you can run
                startx to start your preferred DE/WM if you do not like sway.

                That means this app is a download ONLY and not to be added to 
                your boot list file. It is run ONLY once by 
                $ tce-load -i sway-dot
      
                Compiled for 10.x 
Change-log:     2019/05/17 first version 
Current:        2019/05/17  ' > $P.tcz.info

submitqc --libs
