#!/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=gphoto2
V=2.5.20
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc libgphoto2-dev libexif-dev popt-dev \
libjpeg-turbo-dev readline-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://sourceforge.net/projects/gphoto/files/gphoto/$V/$SRC.tar.gz/download    "  $USER
mkdir $P
tar xvf download
cd $SRC
./configure 
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
mv $P/usr/local/share $P-doc/usr/local/share
cp $SRC/AUTHORS $P-doc/usr/local/share/doc/$P/
cp $SRC/COPYING $P-doc/usr/local/share/doc/$P/

# no dev
#####

# 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 'gphoto2.tcz' > $P-locale.tcz.dep
echo 'man-db.tcz' > $P-doc.tcz.dep

# echo 'libgphoto2.tcz
readline.tcz
popt.tcz 
' > $P.tcz.dep

echo 'Title:          gphoto2.tcz
Description:    CLI for libgphoto2 
Version:        2.5.20
Author:         Lutz Mueller, Hans Ulrich, Christophe Barbe, Hubert Figuiere,
                      Colin Marquardt, Marcus Messner, Theodore Kilgore
Original-site:   http://gphoto.org
Copying-policy: GPL v2
Size:           52K                  		
Extension_by:   aus9 at gmx dot com
Tags:           camera  
Comments:       For cameras
                Online help is here
                http://gphoto.org/doc/manual/
                http://gphoto.org/doc/manual/permissions.html

                Alternative TCE shotwell and similar

                QUICK START commands
                $ gphoto2 --auto-detect
                 >> must show a camera
                 If not, power cycle your camera until you see one in above command
                $ gphoto2 --get-all-files
                >> copies images to current dir.
                
               $ gphoto2 --summary
               (If you see Device Capabilities)
	       >       File Download, File Deletion, File Upload
	       >      No Image Capture, No Open Capture, No vendor specific capture

               Then following command will fail
               $ gphoto2 --capture-image-and-download
                             
               Compiled on 9x 
Change-log:     2018/11/17 first version
Current:        2018/11/17  ' > $P.tcz.info

echo 'Title:          gphoto2-doc.tcz
Description:    docs  
Version:        2.5.20
Author:         Lutz Mueller, Hans Ulrich, Christophe Barbe, Hubert Figuiere,
                      Colin Marquardt, Marcus Messner, Theodore Kilgore
Original-site:   http://gphoto.org
Copying-policy: GPL v2
Size:           20K     		
Extension_by:   aus9
Tags:           camera  
Comments:       docs and man page

Change-log:     2018/11/17 first version
Current:        2018/11/17  ' > $P-doc.tcz.info

echo 'Title:          gphoto2-locale.tcz
Description:    locales  
Version:        2.5.20
Author:         Lutz Mueller, Hans Ulrich, Christophe Barbe, Hubert Figuiere,
                      Colin Marquardt, Marcus Messner, Theodore Kilgore
Original-site:   http://gphoto.org
Copying-policy: GPL v2
Size:           312K     		
Extension_by:   aus9
Tags:           camera  
Comments:       for non-English users untested by me

Change-log:     2018/11/17 first version
Current:        2018/11/17  ' > $P-locale.tcz.info

submitqc --libs
