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

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

P=feh
V=3.4
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc libX11-dev imlib2-dev curl-dev libexif-dev Xorg-7.7-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://feh.finalrewind.org/$SRC.tar.bz2"  $USER

mkdir $P
tar jxvf $SRC*bz2
cd $SRC
make exif=1
make install DESTDIR=/tmp/$P
cd /tmp

# running of man page reveals 
# Compile-time switches in this build:
#   remote file support: libcurl enabled
#   natural sorting option available
#   Xinerama multi-monitor support enabled
#   builtin EXIF reader available
#   inotify-based auto-reload of changed files disabled

# 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/

# main + remove svg files
######
strip --strip-unneeded $P/usr/local/bin/$P
mkdir -p $P/usr/local/share/pixmaps
cp $P/usr/local/share/icons/hicolor/48x48/apps/$P.png $P/usr/local/share/pixmaps
echo 'X-FullPathIcon=/usr/local/share/pixmaps/feh.png' >> $P/usr/local/share/applications/$P.desktop
rm -rf $P/usr/local/share/feh/images/feh.svg
rm -rf $P/usr/local/share/icons/hicolor/scalable

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

# tce.install
#############
mkdir -p $P/usr/local/tce.installed

cat << EOF >> $P/usr/local/tce.installed/$P 
#!/bin/sh
gtk-update-icon-cache -q -f -t /usr/local/share/icons/hicolor
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775 $P/usr/local/tce.installed

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

echo 'imlib2.tcz 
libexif.tcz
libXinerama.tcz 
curl.tcz
libjpeg-turbo-bin.tcz
jpegexiforient.tcz
gtk2.tcz' > $P.tcz.dep

echo 'Title:          feh.tcz
Description:    gtk2 image viewer 
Version:        3.4
Author:         many see doc AUTHORS
Original-site:  http://feh.finalrewind.org/
Copying-policy: MIT
Size:           132K          		
Extension_by:   aus9
Tags:           image viewer
Comments:       x11 image viewer aimed mostly at terminal users

                feh can view online images,  example
                $  feh https://i.imgur.com/w5a44h6.jpeg

                slideshow is the default mode so run feh in your
                photo/pictures dir without any switch. $ feh
            
Change-log:     2015/09/01 first version
                2017/06/19 updated 2.13.1 -> 2.9.0 (juanito)
                2018/09/06 v 2.9.0 -> 2.27.1 (aus9) 
Current:        2020/04/19 v 3.4 + gtk2 dep for icon cache updates
 ' > $P.tcz.info

echo 'Title:          feh-doc.tcz
Description:    documents 
Version:        3.4
Author:         many see AUTHORS
Original-site:  http://feh.finalrewind.org/
Copying-policy: MIT
Size:           84K      		
Extension_by:   aus9
Tags:           image viewer
Comments:       mainly man page
                $ man feh will reveal compile settings too.

                online man page is here
                https://man.finalrewind.org/1/feh/

Change-log:     2015/09/01 first version
                2017/06/19 updated 2.13.1 -> 2.9.0 (juanito)
                2018/09/06 v 2.9.0 -> 2.27.1 (aus9) 
Current:        2020/04/19 v 3.4 + gtk2 dep for icon cache updates
 ' > $P-doc.tcz.info

submitqc --libs
