#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe "

P=Thunar
V=1.7.0
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc intltool libX11-dev exo-dev libnotify-dev"
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://mirror.vinahost.vn/xfce/src/xfce/thunar/1.7/$P-$V.tar.bz2 " $USER
mkdir $P
tar jxvf $P*bz2
cd $P-$V 
./configure --disable-debug --enable-static=no --enable-exif \
--enable-gudev --enable-gio-unix --disable-tpa-plugin
##################################################################
# Build Configuration:

# GIO UNIX features:                  yes
# GUDev (required for thunar-volman): yes
# Mount notification support:         yes
# Debug Support:                      no
# GObject Instrospection support:     no

# Additional Plugins:

# Advanced Properties:                yes
# Simple Builtin Renamers:            yes
# Trash Panel Applet:                 no
# User Customizable Actions:          yes
# Wallpaper support:                  yes
################################################################
# the trash can will be problematic IMHO with varying persistence
##################################################################
make check
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
#####
TT=$P-$V/plugins/thunar
mkdir -p $P-doc/usr/local/share/doc/$P
cp $P-$V/AUTHORS $P-doc/usr/local/share/doc/$P
cp $P-$V/COPYING $P-doc/usr/local/share/doc/$P
mv $P/usr/local/share/man $P-doc/usr/local/share
mv $P/usr/local/share/doc/$P/README* $P-doc/usr/local/share/doc/$P/
mv $P/usr/local/share/gtk-doc $P-doc/usr/local/share 
cp $TT-apr/README $P-doc/usr/local/share/doc/$P/README-apr
cp $TT-sbr/README $P-doc/usr/local/share/doc/$P/README-sbr
cp $TT-uca/README $P-doc/usr/local/share/doc/$P/README-uca
cp $TT-sendto-email/README $P-doc/usr/local/share/doc/$P/README-email

# dev
#####
mkdir -p $P-dev/usr/local/lib/xfce4/panel/plugins
mkdir -p $P-dev/usr/local/lib/thunarx-3
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a 
mv $P/usr/local/lib/thunarx-3/*a $P-dev/usr/local/lib/thunarx-3/
chmod 644 $P-dev/usr/local/lib/thunarx-3/*a
mv $P/usr/local/lib/xfce4/panel/plugins/*a $P-dev/usr/local/lib/xfce4/panel/plugins
chmod 644 $P-dev/usr/local/lib/xfce4/panel/plugins/*a

# main......# desktops to appear in XFCE
#####
echo 'see doc tcz for license' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
#######
LIST="$P $P-doc $P-dev $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

echo 'Thunar.tcz' > $P-locale.tcz.dep

echo 'Thunar.tcz
intltool.tcz
libX11-dev.tcz
exo-dev.tcz
libnotify-dev.tcz' > $P-dev.tcz.dep

echo 'man-db.tcz ' $P-doc.tcz.dep

echo 'exo.tcz
gudev-lib.tcz 
libnotify.tcz
thunar-volman.tcz ' > $P.tcz.dep

echo 'Title:          Thunar.tcz  
Description:    xfce file manager
Version:        1.7.0
Author:         see doc for authors  
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce thunar file manager
Comments:       A graphical File Manager dependent on xfce4-session running.
                If you are looking for a stand alone FM I suggest spacefm.tcz
 
                If you see mention of tca it means Trash Can Applet. Also 
                known as trash panel applet but not compiled this build. 
                Thunar has a warning box if you start it with root powers.

                See info for thunar-volman for device support. As a comment
                iphone support in Linux is limited, much better for Android

                Independent TCZs to provide functions
                #################################### 
                android-file-transfer.tcz for androids
                ifuse.tcz for iphones
         
                Compiled for 64 9.x
Change-log:     2018/04/11  First version 
Current:        2018/04/11
' > $P.tcz.info

echo 'Title:          Thunar-doc.tcz
Description:    docs and man pages
Version:        1.7.0
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Contains man page and some docs
                manpage renamed to Thunar

                Compiled for 64 9.x
Change-log:     2018/04/11  First version 
Current:        2018/04/11 
' > $P-doc.tcz.info

echo 'Title:          Thunar-dev.tcz
Description:    dev files for Thunar
Version:        1.7.0
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Development files

                Compiled for 64 9.x
Change-log:     2018/04/11  First version 
Current:        2018/04/11
' > $P-dev.tcz.info


echo 'Title:          Thunar-locale.tcz
Description:    locales
Version:        1.7.0
Author:         see doc for authors 
Original-site:  xfce.org
Copying-policy: GPL v2
Size:		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       for non-english users untested

                Compiled for 64 9.x
Change-log:     2018/04/11  First version 
Current:        2018/04/11
' > $P-locale.tcz.info

submitqc --libs

# loading Thunar -> insert usb stick or data cd
# clicking left pane of media item.....mounts media correctly
# RH click media and choosing unmount... can be confirmed using TC mount tool
# appears to use eject as without it startup notification just circles
