#!/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.9
SRC=$P-$V
LIST="compiletc submitqc cmake vte-2.91-dev perl5 "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
https://launchpad.net/sakura/trunk/3.8.9/+download/sakura-3.8.9.tar.bz2 \
https://i.postimg.cc/vB18D4y1/sakura.png 
chown root:root $P.png
tar jxvf $SRC*bz2
cd $SRC
cmake . # seconds for cmake and make
make -j5 # seconds
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 . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          sakura-locale.tcz
Description:    locales
Version:        3.8.9
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
                2024/04/03 v 3.8.7 on 15x
Current:        2025/11/10 v 3.8.9 on 16x ' > $P-locale.tcz.info
echo 'sakura.tcz' > $P-locale.tcz.dep

echo 'Title:          sakura.tcz
Description:    gtk3 virtual terminal
Version:        3.8.9
Author:         David Gomez Espinosa
Original-site:  https://launchpad.net/sakura
Copying-policy: GPL v2
Size:           36K                   		
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 $HOME/.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/sakura 
                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

                I recommend you try mononoki-ttf-fonts, restart sakura to see new loaded fonts
               
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 
                2024/04/03 v 3.8.7 on 15x
Current:        2025/11/10 v 3.8.9 on 16x ' > $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 vte-2.91-gtk3
#libharfbuzz.so.0]harfbuzz vte-2.91-gtk3   
#libatk-1.0.so.0]at-spi2-core vte-2.91-gtk3
#libcairo-gobject.so.2]libcairo.so.2] cairo vte-2.91-gtk3
#libgdk_pixbuf-2.0.so.0] gdk-pixbuf2 vte-2.91-gtk3
#libgio-2.0.so.0]libgobject-2.0.so.0]libglib-2.0.so.0]glib2 vte-2.91-gtk3
#libvte-2.91.so.0] vte-2.91-gtk3
#libX11.so.6]libX11 vte-2.91-gtk3

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

submitqc --libs
rm -rf *.zsync
