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

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe"
export LDFLAGS="-Wl,-O1"

P=swaylock
V=1.5
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc meson cmake scdoc-dev cairo-dev wayland-dev \
gdk-pixbuf2-dev libxkbcommon-dev "
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.zip " $USER
unzip $V*zip
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  # seconds
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 '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 
Tags:           wayland man
Comments:       one man page

Change-log:     2019/06/17 Original 1.4 on 10x 
Current:        2020/06/29 -> v 1.5 on 11x  
' > $P-doc.tcz.info

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 
Tags:           wayland swaylock
Comments:       Before using you will need to create a password for 
                local login.
                You may like 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
            
Change-log:     2019/06/17 Original 1.4 on 10x 
Current:        2020/06/29 -> v 1.5 on 11x
' > $P.tcz.info

echo 'man-db.tcz' > $P-doc.tcz.dep

submitqc --libs
