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

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

L=https://excellmedia.dl.sourceforge.net/project/lxde/LXTerminal%20%28terminal%20emulator%29/LXTerminal%200.3.2
P=lxterminal
V=0.3.2
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
# lxterminal for pixmap, xterm and install script
LIST="compiletc submitqc wget xz gtk3-dev vte-dev intltool lxterminal"
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 $L/$SRC.tar.xz    " $USER 
xz -d $SRC*xz && tar xvf $SRC*tar
cd $SRC
./configure --enable-gtk3 --enable-man
make -j5
mkdir -p /tmp/$P
make install-strip 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/doc/lxterminal
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P
cp $SRC/COPYING $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/man $P-doc/usr/local/share/

# main 
####
LOOP=/tmp/tcloop/$P
#####
LOOP1=usr/local/share/applications
rm -rf $P/$LOOP1/$P.desktop
cp $LOOP/$LOOP1/$P.desktop $P/$LOOP1

mkdir $P/usr/local/share/pixmaps
LOOP2=usr/local/share/pixmaps/$P.png
cp $LOOP/$LOOP2 $P/usr/local/share/pixmaps/

# tce.installed 
mkdir -p $P/usr/local/tce.installed
LOOP3=usr/local/tce.installed/$P
cp $LOOP/$LOOP3  $P/usr/local/tce.installed/
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

# xterm
LOOP4=usr/local/bin/$P-xterm
cp $LOOP/$LOOP4 $P/usr/local/bin
chmod 755 $P/usr/local/bin/lxterminal-xterm

# TCZ them
###########
LIST2="$P $P-doc $P-locale"
for Z in $LIST2
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 "gtk3.tcz
vte.tcz
gnutls.tcz
adwaita-icon-theme.tcz
Xorg-fonts.tcz
xcursor-themes.tcz
libepoxy.tcz   " > $P.tcz.dep

echo "lxterminal.tcz" > $P-locale.tcz.dep
echo 'man-db.tcz' > $P-doc.tcz.dep

# info files 
######

echo "Title:           lxterminal.tcz
Description:     terminal from LXDE
Version:         0.3.2
Author:          7 authors see doc/AUTHORS
Original-site:   http://sourceforge.net/projects/lxde/files
Copying-policy:  GPL v2
Size:            76K
Extension_by:    aus9
Tags:            terminal utf8
Comments:        This is a gtk3 terminal capable of UTF-8 display.
                 Allows multiple tabs.

                 If not in Xorg, to adjust fontname or its size edit
                  .config/lxterminal/lxterminal.conf

                 Optional deps:  More font TCZs, load fontconfig
                 then load lxterminal please.

                 If you run lxterminal from another terminal, ignore 
                 warning 'GtkDialog mapped without a transient 
                 parent. This is discouraged'

                 Compiled for 9x 
Change-log:      2015/08/01 first version (gordon64) 
                 2016/06/16 adjusted lxterminal-xterm (juanito)
                 2017/04/13 updated 0.20 -> 0.30 (juanito)
Current:         2018/10/14 0.3 -> 0.3.2 (aus9) " > $P.tcz.info

echo "Title:          lxterminal-doc.tcz
Description:    docs  for lxterminal
Version:        0.3.2
Author:         7 see doc 
Original-site:  http://sourceforge.net/projects/lxde/files
Copying-policy: GPL v2
Size:	           12K	
Extension_by:   aus9
Tags:           terminal 
Comments:       Contains man page and  AUTHORS

                Compiled for 9x
Change-log:     2015/08/01 First version (gordon64) 
Current:        2018/10/14 0.3 -> 0.3.2 (aus9) " > $P-doc.tcz.info

echo "Title:          lxterminal-locale.tcz
Description:    locales for lxterminal
Version:        0.3.2
Author:         7 see doc
Original-site:  http://sourceforge.net/projects/lxde/files
Copying-policy: GPL v2
Size:		           128K
Extension_by:   aus9
Tags:           terminal locale 
Comments:       For non-English users of lxterminal.

                Compiled for 9x
Change-log:     2015/08/01 First version  (gordon64)
Current:        2018/10/14 0.3 -> 0.3.2 (aus9) " > $P-locale.tcz.info

submitqc --libs