#!/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-volman
V=0.9.0
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc intltool 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/$P/0.9/$P-$V.tar.bz2 " $USER
mkdir $P
tar jxvf $P*bz2
cd $P-$V 
./configure --disable-debug --enable-notifications
############################################################
# Build Configuration:
# Mount notifications: yes
# Debug Support:       no
########################################################### 
make -j5
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/$P
cp $P-$V/AUTHORS $P-doc/usr/local/share/doc/$P
cp $P-$V/COPYING $P-doc/usr/local/share/doc/$P

# dev  none created
#####

# main
#####
# no need for desktop
rm -rf $P/usr/local/share/applications
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

echo 'thunar-volman.tcz' > $P-locale.tcz.dep

echo 'thunar-volman.tcz
intltool.tcz 
exo-dev.tcz 
libnotify-dev.tcz' > $P-dev.tcz.dep

echo 'exo.tcz
libnotify.tcz
startup-notification.tcz' > $P.tcz.dep

echo 'Title:          thunar-volman.tcz  
Description:    thunar volume manager 
Version:        0.9.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 removeable drives and media 
                command=thunar-volman-settings 
                allows varies auto mount options
                I have been unable to test most
                devices as I do not own them.

                optional dependencies
                #####################
                various media or printing TCZs 
                depending on what device you wish
                to interact with eg 
                bluray=libbluray.tcz
                some cameras=libgphoto2.tcz
                some printers=cups/avahi/hplip                   
 
                Compiled for 64 9.x
Change-log:     2018/04/11  First version 
Current:        2018/04/11
' > $P.tcz.info

echo 'Title:          thunar-volman-doc.tcz
Description:    docs
Version:        0.9.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:       Some docs

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

echo 'Title:          thunar-volman-locale.tcz
Description:    locales
Version:        0.9.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
