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

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti" 

P=swaylock
V=1.4
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc meson cmake scdoc-dev cairo-dev wayland-dev \
gdk-pixbuf2-dev libxkbcommon "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/swaywm/$P/archive/$V.tar.gz " $USER
tar xvf $V*gz
cd $SRC
mkdir build && cd build
meson --strip --prefix=/usr/local -Ddebug=false --buildtype=plain -Dfish-completions=false -Dpam=disabled
meson configure
# meson.build:140: WARNING: The swaylock binary must be setuid when compiled without libpam
# meson.build:141: WARNING: You must do this manually post-install: chmod a+s /path/to/swaylock
ninja 
DESTDIR=/tmp/$P ninja install
cd /tmp

# doc
#####
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share/

# main
######
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE  $P/usr/local/share/doc/$P/
chmod a+s $P/usr/local/bin/swaylock

# pam disabled remove its file
rm -rf $P/usr/local/etc

# TCZ them
#######
LIST="$P $P-doc "
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 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          swaylock.tcz 
Description:    screen locker for wayland 
Version:        1.4
Author:         Drew DeVault
Original-site:  https://github.com/swaywm/swaylock
Copying-policy: Accompanied 
Size:           28K		
Extension_by:   aus9 at gmx dot com
Tags:           wayland swaylock
Comments:       Before using you will need to create a password for 
                local login (tc?)
                Optional you may need to persist the password files over reboot?
                etc/passwd and etc/shadow 

                To LOCK
                $ swaylock -f
                which daemonises the locker and locks screen

                To UNLOCK
                <type passwd> You will see a circle appear and a change in indicator
                upon each press.......When you have typed full password, press Enter
                
                If you mistype ---a visual indicator appears you can try again
                man page show extra configs            
          
                Compiled for 10.1
Change-log:     2019/06/17 first version 
Current:        2019/06/17  ' > $P.tcz.info

echo 'Title:          swaylock-doc.tcz 
Description:    man page for swaylock
Version:        1.4
Author:         Drew DeVault
Original-site:  https://github.com/swaywm/swaylock
Copying-policy: Accompanied 
Size:           4.0K		
Extension_by:   aus9 at gmx dot com
Tags:           wayland man
Comments:       one man page

                Compiled for 10.1
Change-log:     2019/06/17 first version 
Current:        2019/06/17  ' > $P-doc.tcz.info

submitqc --libs
