#!/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"
export LDFLAGS="-Wl,-O1"

P=gphoto2
V=2.5.23
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc submitqc libgphoto2-dev libexif-dev popt-dev \
libjpeg-turbo-dev readline-dev aalib-dev"
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp  # download very slow
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://sourceforge.net/projects/gphoto/files/gphoto/$V/$SRC.tar.bz2"  $USER
mkdir $P
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local
# Compiler:                      gcc
# Use translations:              yes
# libgphoto2:                    yes
# pthread support:               yes (-lpthread)
# Interactive config support:    no (http://dickey.his.com/cdk/cdk.html)
# JPEG support:                  yes
# libexif:                       yes
# Text preview support:          yes
# use popt library:              yes
# popt libs:                     -L/usr/ -lpopt
# popt cppflags:                 -I/usr/include
# Readline support:              yes (doesn't require explicit -lncurses)
make -j5 # takes seconds
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/
rm -rf $P-doc/usr/local/share/doc/$P/test-hook.sh

# 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 'Title:          gphoto2-doc.tcz
Description:    docs 
Version:        2.5.23
Author:         see AUTHORS
Original-site:  http://gphoto.org
Copying-policy: GPL v2
Size:           20K
Extension_by:   aus9
Tags:           camera
Comments:       Mainly man page  
Change-log:     2018/11/17 first version 2.5.20 on 9x
Current:        2020/05/31 v 2.5.23 for 11x
' > $P-doc.tcz.info

echo 'Title:          gphoto2-locale.tcz
Description:    locales 
Version:        2.5.23
Author:         see doc AUTHORS
Original-site:  http://gphoto.org
Copying-policy: GPL v2
Size:           304K
Extension_by:   aus9
Tags:           camera
Comments:       for non-English users untested by me   
Change-log:     2018/11/17 first version 2.5.20 on 9x
Current:        2020/05/31 v 2.5.23 for 11x
' > $P-locale.tcz.info
     
echo 'Title:          gphoto2.tcz
Description:    command line frontend to libgphoto2 
Version:        2.5.23
Author:         see doc AUTHORS
Original-site:  http://gphoto.org
Copying-policy: GPL v2
Size:           48K
Extension_by:   aus9
Tags:           camera
Comments:       Mainly to copy images or movies from camera to PC
                TC mount tool/usb-utils not needed and online help =
                http://gphoto.org/doc/manual/
                Supported cameras list
                http://www.gphoto.org/proj/libgphoto2/support.php
                Mine=Fuji T500 is unlisted but image copy works OK
                
                $ gphoto2 --auto-detect # must show a camera or phone
                (My phone did not need usb debug enabled)
                eg USB PTP Class Camera usb:001,005
                Huawei Nova             usb:001,008
                If not, power cycle your camera until you see one.
                $ gphoto2 --get-all-files
                eg Saving file as DSCF1462.JPG                                                    
                   Saving file as DSCF1464.AVI  

                $ gphoto2 -a  # shows with example
                Abilities for camera: USB PTP Class Camera                        
                Serial port support: no
                USB support: yes 
                Capture choices: : 
                (on my phone Capture not supported by the driver)
                                 : Image
                                 : Preview
                Configuration support: yes
                Delete selected files on camera: yes
                Delete all files on camera: no
                File preview (thumbnail) support: yes
                File upload support: yes 
                (I have not found an use for ~/.gphoto/settings)
                And this fails for me, $ gphoto2 --capture-image
             
Change-log:     2018/11/17 first version 2.5.20 on 9x
Current:        2020/05/31 v 2.5.23 for 11x
' > $P.tcz.info 


echo 'gphoto2.tcz' > $P-locale.tcz.dep
echo 'man-db.tcz' > $P-doc.tcz.dep
echo 'libgphoto2.tcz
readline.tcz
popt.tcz
aalib.tcz ' > $P.tcz.dep

submitqc --libs
