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

CFLAGS="-mtune=generic -Os -pipe"
CXX="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti" 

P=sakura
V=3.8.7
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc cmake vte-2.91-dev perl5 "
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://launchpad.net/$P/trunk/$V/+download/$SRC.tar.bz2 \
https://i.postimg.cc/vB18D4y1/sakura.png "  $USER
chown root:root $P.png

tar jxvf $SRC*bz2
cd $SRC
cmake . # seconds for cmake and make
make -j5
make install DESTDIR=/tmp/$P # strip fails
cd /tmp

# no doc
#########
rm -rf $P/usr/local/share/doc
rm -rf $P/usr/local/share/man

# locale 
######
mkdir -p $P-locale/usr/local/share
mv $P/usr/local/share/locale $P-locale/usr/local/share  

# main 
#####
strip --strip-unneeded $P/usr/local/bin/*

# icon is svg - old adwaita png is now gone so use download
rm -rf $P/usr/local/share/pixmaps/*
mv $P.png $P/usr/local/share/pixmaps/$P.png

APP=$P/usr/local/share/applications/$P.desktop
sed 's|terminal-tango|sakura|' -i $APP
sed 's|X-Ubuntu-Gettext-Domain=sakura||' -i $APP
echo 'X-FullPathIcon=/usr/local/share/pixmaps/sakura.png' >> $APP

mkdir -p $P/usr/local/share/doc/$P
echo 'GPL v2' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST="$P $P-locale "
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:          sakura-locale.tcz
Description:    locales
Version:        3.8.7
Author:         David Gomez Espinosa
Original-site:  https://launchpad.net/sakura
Copying-policy: GPL v2
Size:           48K                   		
Extension_by:   aus9
Tags:           terminal locale
Comments:       untested by me 
                there was no 14x update

Change-log:     2019/01/03 v 3.6.0
                2020/04/17 v 3.7.0 on 11x 
                2023/03/18 v 3.8.6 on 14x
Current:        2024/04/03 v 3.8.7 on 15x ' > $P-locale.tcz.info
echo 'sakura.tcz' > $P-locale.tcz.dep

echo 'Title:          sakura.tcz
Description:    gtk3 virtual terminal
Version:        3.8.7
Author:         David Gomez Espinosa
Original-site:  https://launchpad.net/sakura
Copying-policy: GPL v2
Size:           32K                   		
Extension_by:   aus9
Tags:           terminal 
Comments:       Online man page also offer help info
                https://www.mankier.com/1/sakura (Also) it shows key bindings +
                $ sakura --help +
                http://www.troubleshooters.com/linux/sakura.htm

                Can support UTF-8. Does not have a menu bar 
                but has a context menu (GUI)
                First run creates the config file at 
                ~/.config/sakura/sakura.conf 
                or to start afresh by delete config and re-run sakura.
               
                Do not edit that file for font names or sizes please.
                I noticed a diff in font names so I recommend you use
                context menu -> options -> select font
                eg Sans Regular 16 
                config will be autogenerated under ~/.config/sway 
                Actual config line reads Sans 16

                The config file does not mention that the action keys
                for certain keyboard combos is hold Ctrl and Shift = C+S
                Toggle on/off scroll  C+S s  (or use GUI)
                Copy = C+S  c (or use GUI)
                Paste = C+S v (or use GUI)

                The "+" or hypehn sign is used for next line.
                Increase/decrease font size = C "+" / C -

                Remember with CS w (will close sakura tab) or
                $ exit (on each tab) if you do not use a mouse

                To use arrow key up/down in mc run in same tab
                $ export TERM=xterm && mc
                Better still try vifm TCE
                               
Change-log:     2019/01/03 v 3.6.0
                2020/04/17 v 3.7.0 on 11x 
                2023/03/18 v 3.8.6 on 14x 
Current:        2024/04/03 v 3.8.7 on 15x ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED' # ignore TCBs
#libgtk-3.so.0]libgdk-3.so.0] gtk3 ->vte-2.91-gtk3
#libpangocairo-1.0.so.0]libpango-1.0.so.0] pango -> gtk3 ->vte-2.91-gtk3
#libharfbuzz.so.0]harfbuzz    
#libatk-1.0.so.0]at-spi2-core->gtk3 ->vte-2.91-gtk3
#libcairo-gobject.so.2]libcairo.so.2] cairo -> pango -> gtk3 -> vte-2.91-gtk3
#libgdk_pixbuf-2.0.so.0] gdk-pixbuf2 -> gtk3 -> ->vte-2.91-gtk3
#libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0]glib2->at-spi2-core->gtk3 ->vte-2.91-gtk3
#libvte-2.91.so.0] vte-2.91-gtk3
#libX11.so.6]libX11 -> gdk-pixbuf2 -> gtk3 -> vte-2.91-gtk3

echo 'vte-2.91-gtk3.tcz 
harfbuzz.tcz' > $P.tcz.dep

# not using any icon TCE

submitqc --libs
rm -rf *.zsync
