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

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

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

LIST="submitqc compiletc cmake glib2-dev gtk3-dev vte-dev \
perl5 gettext aterm"
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/sakura/trunk/3.6.0/+download/sakura-3.6.0.tar.bz2  "  $USER

# to avoid seeing this below  in running sakura from a terminal
# (sakura:24610): Vte-WARNING **: 13:37:48.376: (vtegtk.cc:1916):
# int vte_terminal_match_add_regex(VteTerminal*, VteRegex*, guint32): 
# runtime check failed: (_vte_regex_get_compile_flags(regex) & PCRE2_MULTILINE)
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://launchpadlibrarian.net/388733945/sakura-1790317.patch  "  $USER

mkdir $P
tar jxvf $SRC*bz2
cd $SRC/src
patch -p1 < ../../sakura-1790317.patch
cd ../
cmake .
make -j5
# install-strip fails
make install DESTDIR=/tmp/$P
cd /tmp

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

# doc
#####
mkdir -p $P-doc/usr/local/share
mv $P/usr/local/share/doc $P-doc/usr/local/share
mv $P/usr/local/share/man $P-doc/usr/local/share
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P
cp $SRC/GPL $P-doc/usr/local/share/doc/$P/LICENSE
mv $P-doc/usr/local/share/doc/$P/INSTALL $P-doc/usr/local/share/doc/$P/keyboard-combos

# no dev
#####

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

# icon is svg lets use aterm's png instead?
rm -rf $P/usr/local/share/pixmaps/*
ATERM=/tmp/tcloop/aterm/usr/local/share/pixmaps/aterm.png
cp $ATERM $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

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

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

echo 'Title:          sakura.tcz
Description:    gtk3 terminal
Version:        3.6.0
Author:         David Gomez Espinosa
Original-site:  https://launchpad.net/sakura
Copying-policy: GPL v2
Size:           36K                   		
Extension_by:   aus9
Tags:           terminal 
Comments:       Terminal for gtk3 users
                Can support UTF-8

                Does not have a menu bar but has a context menu
                eg for a RH mouse user ....click RH mouse button

                Increase font size = CTRL +
                copy = Crtl SHIFT  c
                paste = Crtl SHIFT v
                online help
                http://www.troubleshooters.com/linux/sakura.htm 

                To preset values eg font and sizes....load more fonts and
                 edit .config/sakura/sakura.conf
                
Change-log:     2019/01/03 first version
Current:        2019/01/03  ' > $P.tcz.info

echo 'Title:          sakura-doc.tcz
Description:    docs  
Version:        3.6.0
Author:         David Gomez Espinosa
Original-site:  https://launchpad.net/sakura
Copying-policy: GPL v2
Size:           16K     		
Extension_by:   aus9
Tags:           terminal
Comments:       docs and man page

                      contains keyboard combinations

Change-log:     2019/01/03 first version
Current:        2019/01/03  ' > $P-doc.tcz.info

echo 'Title:          sakura-locale.tcz
Description:    locales  
Version:        3.6.0
Author:         David Gomez Espinosa
Original-site:  https://launchpad.net/sakura
Copying-policy: GPL v2
Size:           44K     		
Extension_by:   aus9
Tags:           terminal
Comments:       for non-English users untested by me

Change-log:     2019/01/03 first version
Current:        2019/01/03  ' > $P-locale.tcz.info

submitqc --libs
