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

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

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

LIST="submitqc compiletc cmake glib2-dev gtk3-dev vte-2.91-dev \
perl5 gettext adwaita-icon-theme"
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.gz  "  $USER

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

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

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

# icon is svg 
rm -rf $P/usr/local/share/pixmaps/*

ICON=/usr/local/share/icons/Adwaita/48x48/apps/utilities-terminal-symbolic.symbolic.png
cp $ICON $P/usr/local/share/pixmaps/$P.png
chmod 644 $P/usr/local/share/pixmaps/$P.png

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

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

# 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:          sakura.tcz
Description:    gtk3 terminal
Version:        3.8.6
Author:         David Gomez Espinosa
Original-site:  https://launchpad.net/sakura
Copying-policy: GPL v2
Size:           36K                   		
Extension_by:   aus9
Tags:           terminal 
Comments:       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 -
                
                online help
                http://www.troubleshooters.com/linux/sakura.htm
                
Change-log:     2019/01/03 v 3.6.0
                2020/04/17 v 3.7.0 on 11x 
Current:        2023/03/18 v 3.8.6 on 14x  ' > $P.tcz.info

readelf -d $P/usr/local/bin/$P | grep 'NEEDED'
#0x0000000000000001 (NEEDED) Shared library: [libgtk-3.so.0]            gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libgdk-3.so.0]             gtk3 "
#0x0000000000000001 (NEEDED) Shared library: [libz.so.1]                 TCB
#0x0000000000000001 (NEEDED) Shared library: [libpangocairo-1.0.so.0] pango gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libpango-1.0.so.0]       pango "
#0x0000000000000001 (NEEDED) Shared library: [libharfbuzz.so.0]       harfbuzz    
#0x0000000000000001 (NEEDED) Shared library: [libatk-1.0.so.0]         atk gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libcairo-gobject.so.2]  cairo pango gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libcairo.so.2]          cairo "
#0x0000000000000001 (NEEDED) Shared library: [libgdk_pixbuf-2.0.so.0] gdk-pixbuf2 gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libgio-2.0.so.0]        glib2 cairo gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libgobject-2.0.so.0]              "    
#0x0000000000000001 (NEEDED) Shared library: [libglib-2.0.so.0]    glib2 cairo gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libvte-2.91.so.0]     vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libX11.so.6]          gdk-pixbuf2 gtk3 vte-2.91
#0x0000000000000001 (NEEDED) Shared library: [libm.so.6]             TCB
#0x0000000000000001 (NEEDED) Shared library: [libc.so.6]              "

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

submitqc --libs
