#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# https://sourceforge.net/projects/gtkrawgallery/
# Packager Michelino Chionchio - Thanks to www.slacky.eu

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-gtkrawgallery
NAME=gtkrawgallery
VERSION=0.9.3
ARCH=${ARCH:-i486}
BUILD=2mch

if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
 mkdir -p $PKG
fi

mkdir -p $PKG/usr/share
cd $PKG/usr/share
tar xvjf $CWD/$NAME-$VERSION.tar.bz2
chmod 777 -R $NAME-$VERSION
cd $NAME-$VERSION

chown -R root:root .
chmod -R u+w,go+r-w,a-s .

mkdir -p $PKG/usr/bin
cp -a $CWD/gtkrawgallery $PKG/usr/bin
chmod 755 $PKG/usr/bin/gtkrawgallery
chmod 777 $PKG/usr/share/$NAME-$VERSION

mkdir -p  $PKG/usr/share/applications

cat << EOF > $PKG/usr/share/applications/$NAME.desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=gtkrawgallery
GenericName=Image viewer
GenericName[it]=Visualizzatore di immagini
Comment=Image viewer with camera raw files support written in Python
Comment[it]=Visualizzatore di immagini con supporto ai file raws scritto in Python
Icon=/usr/share/gtkrawgallery-0.9.1/icons/logo.png
Exec=gtkrawgallery
Terminal=false
Categories=GTK;Application;Graphics;Viewer
EOF

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a README COPYING $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
cp -a $CWD/doinst.sh $PKG/install
cd $PKG
ADD=$(ls /var/log/packages/ | sed -ne 's/\(exiftool\)-\([^-]\+-[^-]\+-[^-]\+\)/\1 >= \2,/p' \
-e 's/\(dcraw\)-\([^-]\+-[^-]\+-[^-]\+\)/\1 >= \2,/p' \
-e 's/\(numpy\)-\([^-]\+-[^-]\+-[^-]\+\)/\1 >= \2,/p' \
-e 's/\(imaging\)-\([^-]\+-[^-]\+-[^-]\+\)/\1 >= \2,/p') \
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
