#!/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.7.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/$P/trunk/$V/+download/$SRC.tar.gz  "  $USER

mkdir $P
tar xvf $SRC*gz
cd $SRC
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

mkdir -p $P/usr/local/share/doc/$P
echo 'see doc tcz for license' > $P/usr/local/share/doc/$P/COPYING

# 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.7.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 (GUI)
                First run creates the config file at ~/.config/sakura/sakura.conf 
                or to start afresh delete config and re-run the term.
               
                NO font dep has been set, but a default has been attempted.
                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 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 "+" sign is used for next line.
                Increase/decrease font size = C "+" / C -
                
                online help
                http://www.troubleshooters.com/linux/sakura.htm

                Optional dep for GUI is adwaita-icon-theme to get - and + buttons 

Change-log:     2019/01/03 v 3.6.0
Current:        2020/04/17 v 3.7.0 on 11x 
 ' > $P.tcz.info

echo 'Title:          sakura-doc.tcz
Description:    docs  
Version:        3.7.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 v 3.6.0
Current:        2020/04/17 v 3.7.0 on 11x  
 ' > $P-doc.tcz.info

echo 'Title:          sakura-locale.tcz
Description:    locales  
Version:        3.7.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 v 3.6.0
Current:        2020/04/17 v 3.7.0 on 11x   
' > $P-locale.tcz.info

submitqc --libs
