#!/bin/bash
: << _COMMENT_
    ===========================================================================
    This file is part of ffDiaporama
    ffDiaporama is a tools to make diaporama as video
    Copyright (C) 2011-2014 Dominique Levray <domledom@laposte.net>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

    ===========================================================================

    This script will install or update ffDiaporama on your computer

    This script make, create and install RPM packages on the following systems:
      Fedora:   19/20
      openSUSE: 12.3/13.1

    This script make, create and install DEB packages on the following systems:
      Ubuntu:   12.04/12.10/13.10/14.04

      Remarks:
        If no folder is given at command line parameters, the script create devel version packages which is composed of 5 packages:
            ffDiaporama_bin which contains binary and configuration files (have dependencies to QT, Exiv2 libraries)
            ffDiaporama_rsc which contains data files (have no dependency)
            ffDiaporama which is a virtual package (have dependencies to ffDiaporama_bin and ffDiaporama_rsc)
            ffDiaporama_texturemate which contains texturemate extension (have dependency to ffDiaporama)
            ffDiaporama_openclipart which contains openclipart extension (have dependency to ffDiaporama)
        If a folder is given at command line parameters and this folder contains stable version, This script create stable version packages which is composed of 3 packages:
            ffDiaporama which contains binary, configuration files and data files(have dependencies to QT, Exiv2 libraries)
            ffDiaporama_texturemate which contains texturemate extension (have dependency to ffDiaporama)
            ffDiaporama_openclipart which contains openclipart extension (have dependency to ffDiaporama)

    This script make and install each packages on the following systems:
        Manjaro:  Linux
        Mageia:   3
        Ubuntu:   12.04/12.10/13.10/14.04

    To use this script:
        Copy this script to your home folder (~)
        Give execute right to the script: chmod +r ~/install_ffDiaporama_devel_<version>.bash
        Execute the script:
            On debian based systems (Like Ubuntu), execute the script with users privileges:
            On other systems (Like Fedora, openSUSE, etc...), execute the script with administrator privileges: sudo ~/install_ffDiaporama_devel_<version>.bash

    Remarks:
        *A the end of the process, version files, .tar.gz files and RPM packages are stored in /opt/ffDiaporama
        *The full process (processing all packages) may take up to 10 minutes
        *It's possible to specify a source folder to allow installation without downloading any files
          Syntax: sudo ./install_ffDiaporama_devel_<version>.bash [folder]
          In that case, [folder] must contain a Stable and a Devel folder which contains xxxVERSION.TXT files, SPEC files and .tar.gz files

    ===========================================================================

    SCRIPT DATE VERSION: Version 2.2_devel.2014.0503

    ===========================================================================

    Changelog:
        2014.0503
            Replaces SDL by QTMultimedia

        2014.0413
            Add dependency to libSDL_mixer-devel for openSuse systems
            Fix a bug of determine need of update or not for bin package

        2014.0406
            Fixed troubles on OpenSuse packages creation

        2014.0216
            Fixed troubles on Ubuntu packages

        2014.0215
            Modify installation process for Ubuntu to create DEB packages instead of directly installing files
            Remove Ubuntu 13.04 which is no longer supported by Ubuntu team

        2014.0211
            Change dependency of extension to ffDiaporama instead of ffDiaporama_bin and add creation of virtual ffDiaporama package for devel version
            Add the possibility to create stable version packages

        2014.0209
            Improves error management during obtention of redirected address from ffDiaporama website
            Fixes an error in dependencies installation
            Adds the possibility to give a path to the sources files instead of downloading them

        2014.0207
            Remove date from filenames of SPEC files

        2014.0205
            For openSUSE and Fedora: Modify installation process to create RPM packages instead of directly installing files
                The use of RPM packages allows to create a much cleaner installation and allows uninstallation
            Store .tar.gz and produced RPM package to /opt/ffDiaporama
            /opt/ffDiaporama is no longer removed at the installation end, so packages stay available
            Use openclipart Fedora package instead of download zip file on Fedora

        2014.0201
            Add Ubuntu 14.04/13.10/13.04/12/12.04 operating systems

        2014.0130
            Replace wget with curl
            Use php script from ffDiaporama web site to get correct package address
            Use openclipart openSUSE package instead of download zip file on openSUSE

        2014.0129
            Add Mageia operating system
            Add texturemate and openclipart extensions installation

    ===========================================================================
_COMMENT_

CHECKLIBINSTALL() {
  if [[ -e /usr/bin/$1 ]]; then
    echo === $2 already installed
  elif [[ -e /usr/lib/$1 ]]; then
    echo === $2 already installed
  elif [[ -e /usr/lib64/$1 ]]; then
    echo === $2 already installed in 64 bits version
  elif [[ -e /usr/lib/i386-linux-gnu/$1 ]]; then
    echo === $2 already installed
  elif [[ -e /usr/lib/x86_64-linux-gnu/$1 ]]; then
    echo === $2 already installed in 64 bits version
  else
    echo Install $2
    ${SUCMD}${PACKAGEINSCMD} $2
  fi
}

CHECKINSTALL() {
  if [[ -e $1 ]]; then
    echo === $2 already installed
  else
    echo === Install $2
    ${SUCMD}${PACKAGEINSCMD} $2
  fi
}

GETADDRESS() {
    #$1 Package name
    if [ -f /opt/ffDiaporama/getaddress.txt ]; then
        ${SUCMD} rm /opt/ffDiaporama/getaddress.txt
    fi
    curl -s -o /opt/ffDiaporama/getaddress.txt http://ffdiaporama.tuxfamily.org/script/GetAddress.php?f=$1
    if [ ! -f /opt/ffDiaporama/getaddress.txt ]; then
        ${SUCMD} curl -s -o /opt/ffDiaporama/getaddress.txt http://ffdiaporama.tuxfamily.org/script/GetAddress.php?f=$1
    fi
    address=`cat /opt/ffDiaporama/getaddress.txt| grep ffdiaporama | sed 's/\/$1//g'`
    if [[ "$address" == "" ]]; then
        ${SUCMD} curl -s -o /opt/ffDiaporama/getaddress.txt http://ffdiaporama.tuxfamily.org/script/GetAddress.php?f=$1
        address=`cat /opt/ffDiaporama/getaddress.txt| grep ffdiaporama | sed 's/\/$1//g'`
    fi
    if [[ "$address" == "" ]]; then
        echo Impossible to get package download address for $1
        exit 1
    fi
    if [ -f /opt/ffDiaporama/getaddress.txt ]; then
        ${SUCMD} rm /opt/ffDiaporama/getaddress.txt
    fi
}

CHECKTARGZ() {
    if [[ $USEFOLDER == "" ]] && [[ $1 == *.tar.gz ]] && [ -f $1 ]; then
        filetype=`file -ib $1`
        if [[ ! $filetype == *x-gzip* ]]; then
            ${SUCMD} rm $1
        fi
    fi
    if [[ $USEFOLDER == "" ]] && [[ $1 == *.DEBIAN ]] && [ -f $1 ]; then
        filetype=`file -ib $1`
        if [[ ! $filetype == *x-gzip* ]]; then
            ${SUCMD} rm $1
        fi
    fi
}

DOWNLOAD() {
    #$1 filename
    #$2 dest folder
    #$3 source url folder
    #$4 if == force then force new downloading even if file already exist
    #$5 if == hide then use silent mode instead of display progress bar
    if [[ $USEFOLDER == "" ]]; then
        if [[ $4 == "force" ]]; then
            if [ -f $2/$1 ]; then
                ${SUCMD} rm $2/$1
            fi
        fi
        if [[ $5 == "hide" ]]; then
            PARAM="-s"
        else
            PARAM="-#"
            echo Download $1 from Website
        fi
        CHECKTARGZ $2/$1
        if [ ! -f $2/$1 ]; then
            ${SUCMD} curl $PARAM -o $2/$1 $3/$1
            CHECKTARGZ $2/$1
            if [ ! -f $2/$1 ]; then
                ${SUCMD} curl $PARAM -o $2/$1 $3/$1
                CHECKTARGZ $2/$1
                if [ ! -f $2/$1 ]; then
                    echo Impossible to get $1 from ffDiaporama Web site after retry: stop job
                    exit 1
                fi
            fi
            if [[ $1 == *.tar.gz ]]; then
                ${SUCMD} curl -s http://ffdiaporama.tuxfamily.org/script/GetPackage.php?f=PrepOnly$1
                echo
            fi
        fi
    else
        if [[ -f $USEFOLDER/$1 ]]; then
            echo Use $1 from $USEFOLDER
            ${SUCMD} cp $USEFOLDER/$1 $2/$1
        else
            if [[ "$ISDEVEL" == "1" ]] && [[ -f $USEFOLDER/Devel/$1 ]]; then
                echo Use $1 from $USEFOLDER/Devel
                ${SUCMD} cp $USEFOLDER/Devel/$1 $2/$1
            elif [[ "$ISDEVEL" == "0" ]] && [[ -f $USEFOLDER/Stable/$1 ]]; then
                echo Use $1 from $USEFOLDER/Stable
                ${SUCMD} cp $USEFOLDER/Stable/$1 $2/$1
            fi
        fi
    fi
    if [[ ! -f $2/$1 ]]; then
        echo Impossible to get $2/$1
        exit 1
    fi
}

CREATERPM() {
    #$1 package type (bin+rsc,rsc,bin,tmt,oct)
    #$2 fileversion
    #$3 arch
    #$4 filename
    #$5 dist
    #$6 optionnal second .tar.gz
    if [ -d "/tmp/rpmbuild" ]; then
        rm -R /tmp/rpmbuild
    fi
    mkdir /tmp/rpmbuild
    mkdir /tmp/rpmbuild/SOURCES
    mkdir /tmp/rpmbuild/SPECS
    cd /tmp/rpmbuild/SOURCES
    if [[ $1 == "bin+rsc" ]]; then
        if [[ $ISDEVEL == "0" ]]; then
            mkdir ffDiaporama
            cd ffDiaporama
            tar -xzf /opt/ffDiaporama/$6
            tar -xzf /opt/ffDiaporama/$4
            DOWNLOAD ffDiaporama_binrsc.pro . http://download.tuxfamily.org/ffdiaporama/Packages/Stable
            cd ..
            mv /tmp/rpmbuild/SOURCES/ffDiaporama /tmp/rpmbuild/SOURCES/ffDiaporama-${2}
            tar -czf /tmp/rpmbuild/SOURCES/ffDiaporama-${2}.tar.gz *
            SPECFILENAME=ffDiaporama_${SPECNAME}_${2:0:-10}.SPEC
        else
            SPECFILENAME=ffDiaporama_devel_${SPECNAME}_${2:0:-10}.SPEC
            mkdir /tmp/rpmbuild/SOURCES/ffDiaporama-${2}
            tar -czf /tmp/rpmbuild/SOURCES/ffDiaporama-${2}.tar.gz *
        fi
    elif [[ $1 == "bin" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        mv /tmp/rpmbuild/SOURCES/ffDiaporama /tmp/rpmbuild/SOURCES/ffDiaporama_bin-${2}
        tar -czf /tmp/rpmbuild/SOURCES/ffDiaporama_bin-${2}.tar.gz *
        SPECFILENAME=ffDiaporama_bin_${SPECNAME}_${2:0:-10}.SPEC
    elif [[ $1 == "rsc" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        mv /tmp/rpmbuild/SOURCES/ffDiaporama_rsc /tmp/rpmbuild/SOURCES/ffDiaporama_rsc-${2}
        tar -czf /tmp/rpmbuild/SOURCES/ffDiaporama_rsc-${2}.tar.gz *
        SPECFILENAME=ffDiaporama_rsc_${SPECNAME}_${2:0:-10}.SPEC
    elif [[ $1 == "texturemate" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        mv /tmp/rpmbuild/SOURCES/ffDiaporama_texturemate /tmp/rpmbuild/SOURCES/ffDiaporama_texturemate-${2}
        tar -czf /tmp/rpmbuild/SOURCES/ffDiaporama_texturemate-${2}.tar.gz *
        SPECFILENAME=ffDiaporama_texturemate_${SPECNAME}_${2:0:-10}.SPEC
    elif [[ $1 == "openclipart" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        mv /tmp/rpmbuild/SOURCES/ffDiaporama_openclipart /tmp/rpmbuild/SOURCES/ffDiaporama_openclipart-${2}
        tar -czf /tmp/rpmbuild/SOURCES/ffDiaporama_openclipart-${2}.tar.gz *
        SPECFILENAME=ffDiaporama_openclipart_${SPECNAME}_${2:0:-10}.SPEC
    else
        echo Unknown package
        exit 1
    fi
    if [[ $ISDEVEL == "1" ]]; then
        DOWNLOAD logo.xpm /tmp/rpmbuild/SOURCES http://download.tuxfamily.org/ffdiaporama/Packages/Devel
        DOWNLOAD $SPECFILENAME /tmp/rpmbuild/SPECS http://download.tuxfamily.org/ffdiaporama/Packages/Devel
    else
        DOWNLOAD logo.xpm /tmp/rpmbuild/SOURCES http://download.tuxfamily.org/ffdiaporama/Packages/Stable
        DOWNLOAD $SPECFILENAME /tmp/rpmbuild/SPECS http://download.tuxfamily.org/ffdiaporama/Packages/Stable
    fi
    cd /tmp/rpmbuild
    rpmbuild --define '_topdir /tmp/rpmbuild' -bb SPECS/$SPECFILENAME
    if [[ $1 == "bin+rsc" ]]; then
        mv /tmp/rpmbuild/RPMS/${3}/ffDiaporama-${2}-${5}.${3}.rpm /opt/ffDiaporama
        $PACKAGEINSCMD /opt/ffDiaporama/ffDiaporama-${2}-${5}.${3}.rpm
    else
        mv /tmp/rpmbuild/RPMS/${3}/ffDiaporama_${1}-${2}-${5}.${3}.rpm /opt/ffDiaporama
        $PACKAGEINSCMD /opt/ffDiaporama/ffDiaporama_${1}-${2}-${5}.${3}.rpm
    fi
}

CREATEDEB() {
    #$1 package type (bin+rsc,rsc,bin,tmt,oct)
    #$2 fileversion
    #$3 arch
    #$4 filename
    #$5 dist
    #$6 optionnal second .tar.gz
    if [ -d "/tmp/debbuild" ]; then
        rm -Rf /tmp/debbuild
    fi
    mkdir /tmp/debbuild
    mkdir /tmp/debbuild/SOURCES
    cd /tmp/debbuild/SOURCES
    if [[ $1 == "bin+rsc" ]]; then
        if [[ $ISDEVEL == "0" ]]; then
            mkdir ffDiaporama
            cd ffDiaporama
            tar -xzf /opt/ffDiaporama/$6
            tar -xzf /opt/ffDiaporama/$4
            DOWNLOAD ffDiaporama_binrsc.pro . http://download.tuxfamily.org/ffdiaporama/Packages/Stable
            cd ..
            mv /tmp/debbuild/SOURCES/ffDiaporama /tmp/debbuild/SOURCES/ffDiaporama-${2}
            SPECFILENAME=ffDiaporama_${SPECNAME}_${2:0:-10}.DEBIAN
            cd /tmp/debbuild/SOURCES/ffDiaporama-${2}
        else
            mkdir ffDiaporama
            cd ffDiaporama
            SPECFILENAME=ffDiaporama_devel_${SPECNAME}_${2:0:-10}.DEBIAN
            mkdir /tmp/debbuild/SOURCES
            cd /tmp/debbuild/SOURCES/ffDiaporama
        fi
    elif [[ $1 == "bin" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        SPECFILENAME=ffDiaporama_bin_${SPECNAME}_${2:0:-10}.DEBIAN
        cd /tmp/debbuild/SOURCES/ffDiaporama
    elif [[ $1 == "rsc" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        SPECFILENAME=ffDiaporama_rsc_${SPECNAME}_${2:0:-10}.DEBIAN
        cd /tmp/debbuild/SOURCES/ffDiaporama_rsc
    elif [[ $1 == "texturemate" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        SPECFILENAME=ffDiaporama_texturemate_${SPECNAME}_${2:0:-10}.DEBIAN
        cd /tmp/debbuild/SOURCES/ffDiaporama_texturemate
    elif [[ $1 == "openclipart" ]]; then
        tar -xzf /opt/ffDiaporama/$4
        SPECFILENAME=ffDiaporama_openclipart_${SPECNAME}_${2:0:-10}.DEBIAN
        cd /tmp/debbuild/SOURCES/ffDiaporama_openclipart
    else
        echo Unknown package
        exit 1
    fi
    if [[ $ISDEVEL == "1" ]]; then
        DOWNLOAD $SPECFILENAME /tmp/debbuild/SOURCES http://download.tuxfamily.org/ffdiaporama/Packages/Devel
    else
        DOWNLOAD $SPECFILENAME /tmp/debbuild/SOURCES http://download.tuxfamily.org/ffdiaporama/Packages/Stable
    fi
    tar -xzf /tmp/debbuild/SOURCES/$SPECFILENAME
    debuild -i -us -uc -b
    cd /tmp/debbuild
    if [[ $1 == "bin+rsc" ]]; then
        if [[ "$3" == noarch ]]; then
            ${SUCMD} mv /tmp/debbuild/SOURCES/ffdiaporama_${2}-${5}_all.deb /opt/ffDiaporama
            ${SUCMD} dpkg -i /opt/ffDiaporama/ffdiaporama_${2}-${5}_all.deb
        else
            ${SUCMD} mv /tmp/debbuild/SOURCES/ffdiaporama_${2}-${5}_${3}.deb /opt/ffDiaporama
            ${SUCMD} dpkg -i /opt/ffDiaporama/ffdiaporama_${2}-${5}_${3}.deb
        fi
    else
        if [[ "$3" == noarch ]]; then
            ${SUCMD} mv /tmp/debbuild/SOURCES/ffdiaporama-${1}_${2}-${5}_all.deb /opt/ffDiaporama
            ${SUCMD} dpkg -i /opt/ffDiaporama/ffdiaporama-${1}_${2}-${5}_all.deb
        else
            ${SUCMD} mv /tmp/debbuild/SOURCES/ffdiaporama-${1}_${2}-${5}_${3}.deb /opt/ffDiaporama
            ${SUCMD} dpkg -i /opt/ffDiaporama/ffdiaporama-${1}_${2}-${5}_${3}.deb
        fi
    fi
}

#==============================================================================
# MAGEIA
#==============================================================================
MAGEIA_PREP() {
    #Ensure script was launched as root (with sudo)
    if [[ $EUID -ne 0 ]]; then
        echo "You must be a root user" 2>&1
        exit 1
    fi
    SUCMD=''
    PACKAGEINSCMD='urpmi'
    QMAKECMD='qmake'
    SPECNAME='mageia'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    if [[ $OSSYS_ARCH == "x86_64" ]]; then
    ARM="64"
    else
    ARM=""
    fi
    CHECKLIBINSTALL qt5/lib/libQt5Concurrent.so.5                           lib${ARM}qt5base5-devel
    CHECKINSTALL    /usr/lib${ARM}/qt5/include/QtHelp/qhelpcontentwidget.h  lib${ARM}qt5help-devel
    CHECKINSTALL    /usr/lib${ARM}/qt5/include/QtSvg/qtsvgversion.h         lib${ARM}qt5svg-devel
    CHECKLIBINSTALL qt5/plugins/sqldrivers/libqsqlite.so                    qtbase5-database-plugin-sqlite
    CHECKLIBINSTALL qt5/plugins/imageformats/libqtiff.so                    qtimageformats5
    CHECKINSTALL    /usr/bin/make                                           make
    CHECKINSTALL    /usr/bin/gcc                                            gcc
    CHECKINSTALL    /usr/bin/g++                                            gcc-c++
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                       lib${ARM}ffmpeg-devel
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                            lib${ARM}exiv2-devel
}
#==============================================================================
# ARCHLINUX
#==============================================================================
ARCHLINUX_PREP() {
    #Ensure script was launched as root (with sudo)
    if [[ $EUID -ne 0 ]]; then
        echo "You must be a root user" 2>&1
        exit 1
    fi
    SUCMD=''
    PACKAGEINSCMD='pacman -S'
    QMAKECMD='qmake-qt5'
    SPECNAME='archlinux'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    CHECKLIBINSTALL libQt5Concurrent.so.5                               qt5-base
    CHECKINSTALL    /usr/include/qt/QtHelp/qhelpcontentwidget.h         qt5-tools
    CHECKINSTALL    /usr/include/qt/QtSvg/qtsvgversion.h                qt5-svg
    CHECKLIBINSTALL qt/plugins/imageformats/libqtiff.so                 qt5-imageformats
    CHECKLIBINSTALL /usr/include/qt/QtMultimedia/qaudiooutput.h          qt5-multimedia
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                   ffmpeg
    CHECKINSTALL    /usr/bin/exiv2                                      exiv2
}
#==============================================================================
# FEDORA 19
#==============================================================================
FEDORA19_PREP() {
    #Ensure script was launched as root (with sudo)
    if [[ $EUID -ne 0 ]]; then
        echo "You must be a root user" 2>&1
        exit 1
    fi
    SUCMD=''
    PACKAGEINSCMD='yum -y install'
    QMAKECMD='qmake-qt5'
    ISCREATERPM='1'
    SPECNAME='Fedora19'
    DISTNAME='0.fc19'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKLIBINSTALL libQt5Concurrent.so.5                               qt5-qtbase
    CHECKINSTALL    /usr/include/qt5/QtConcurrent/qtconcurrent_global.h qt5-qtbase-devel
    CHECKINSTALL    /usr/include/qt5/QtHelp/qhelpcontentwidget.h        qt5-qttools-devel
    CHECKINSTALL    /usr/include/qt5/QtSvg/qtsvgversion.h               qt5-qtsvg-devel
    CHECKINSTALL    /usr/include/qt/QtMultimedia/qaudiooutput.h         qt5-qtmultimedia-devel
    #ffmpeg, Exiv2
    CHECKINSTALL    /usr/include/ffmpeg/libavcodec/avcodec.h            ffmpeg-devel
    CHECKINSTALL    /usr/bin/exiv2                                      exiv2
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        exiv2-devel
    #RPM creation
    CHECKINSTALL    /etc/rpmdevtools/rmdevelrpms.conf                   rpmdevtools
    CHECKINSTALL    /usr/bin/yum-builddep                               yum-utils
    CHECKINSTALL    /usr/bin/rpmlint                                    rpmlint
}
#==============================================================================
# FEDORA 20
#==============================================================================
FEDORA20_PREP() {
    #Ensure script was launched as root (with sudo)
    if [[ $EUID -ne 0 ]]; then
        echo "You must be a root user" 2>&1
        exit 1
    fi
    SUCMD=''
    PACKAGEINSCMD='yum -y install'
    QMAKECMD='qmake-qt5'
    ISCREATERPM='1'
    SPECNAME='Fedora20'
    DISTNAME='0.fc20'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKINSTALL    /usr/bin/g++                                        gcc-c++
    CHECKLIBINSTALL libQt5Concurrent.so.5                               qt5-qtbase
    CHECKINSTALL    /usr/include/qt5/QtConcurrent/qtconcurrent_global.h qt5-qtbase-devel
    CHECKINSTALL    /usr/include/qt5/QtHelp/qhelpcontentwidget.h        qt5-qttools-devel
    CHECKINSTALL    /usr/include/qt5/QtSvg/qtsvgversion.h               qt5-qtsvg-devel
    CHECKINSTALL    /usr/include/qt/QtMultimedia/qaudiooutput.h         qt5-qtmultimedia-devel
    #ffmpeg, Exiv2
    CHECKINSTALL    /usr/include/ffmpeg/libavcodec/avcodec.h            ffmpeg-devel
    CHECKINSTALL    /usr/bin/exiv2                                      exiv2
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        exiv2-devel
    #RPM creation
    CHECKINSTALL    /etc/rpmdevtools/rmdevelrpms.conf                   rpmdevtools
    CHECKINSTALL    /usr/bin/yum-builddep                               yum-utils
    CHECKINSTALL    /usr/bin/rpmlint                                    rpmlint
}
#==============================================================================
# OPENSUSE 12.3
#==============================================================================
SUZE123_PREPQT4() {
    #Ensure script was launched as root (with sudo)
    if [[ $EUID -ne 0 ]]; then
        echo "You must be a root user" 2>&1
        exit 1
    fi
    SUCMD=''
    PACKAGEINSCMD='zypper install -f'
    QMAKECMD='qmake'
    ISCREATERPM='1'
    SPECNAME='openSUSE123'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKLIBINSTALL libQtCore.so.4                                      libqt4
    CHECKLIBINSTALL libQtSql.so.4                                       libqt4-sql
    CHECKLIBINSTALL qt4/plugins/sqldrivers/libqsqlite.so                libqt4-sql-sqlite
    CHECKINSTALL    /usr/include/Qt/qconfig.h                           libqt4-devel
    #ffmpeg, Exiv2
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                   libffmpeg-devel
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        libexiv2-devel
    #RPM creation
    CHECKINSTALL    /usr/share/rpmlint/config                           rpmlint
    CHECKLIBINSTALL rpmrebuild/rpmrebuild.sh                            rpmrebuild
    CHECKLIBINSTALL librpm.so                                           rpm-devel
}
#==============================================================================
# OPENSUSE 13.1
#==============================================================================
SUZE131_PREPQT5() {
    #Ensure script was launched as root (with sudo)
    if [[ $EUID -ne 0 ]]; then
        echo "You must be a root user" 2>&1
        exit 1
    fi
    SUCMD=''
    PACKAGEINSCMD='zypper install -f'
    QMAKECMD='qmake-qt5'
    ISCREATERPM='1'
    SPECNAME='openSUSE131'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKLIBINSTALL libQt5Concurrent.so.5                               libqt5-qtbase
    CHECKLIBINSTALL libQt5Gui.so.5                                      libQt5Gui5
    CHECKLIBINSTALL libQt5Widgets.so.5                                  libQt5Widgets5
    CHECKLIBINSTALL libQt5Svg.so.5                                      libQt5Svg5
    CHECKLIBINSTALL libQt5Sql.so.5                                      libQt5Sql5
    CHECKLIBINSTALL libQt5Help.so.5                                     libqt5-qttools
    CHECKLIBINSTALL qt5/plugins/sqldrivers/libqsqlite.so                libqt5-sql-sqlite
    CHECKLIBINSTALL qt5/plugins/imageformats/libqtiff.so                libqt5-qtimageformats
    CHECKINSTALL    /usr/include/qt5/QtConcurrent/qtconcurrent_global.h libqt5-qtbase-devel
    CHECKINSTALL    /usr/include/qt5/QtHelp/qhelpcontentwidget.h        libqt5-qttools-devel
    CHECKINSTALL    /usr/include/qt5/QtMultimedia/qaudiooutput.h        libQt5Multimedia-devel
    #ffmpeg, Exiv2
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                   libffmpeg-devel
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        libexiv2-devel
    #RPM creation
    CHECKINSTALL    /usr/share/rpmlint/config                           rpmlint
    CHECKLIBINSTALL rpmrebuild/rpmrebuild.sh                            rpmrebuild
    CHECKLIBINSTALL librpm.so                                           rpm-devel
}
#==============================================================================
# UBUNTU 12.04
#==============================================================================
UBUNTU1204_PREPQT4() {
    SUCMD='sudo '
    QMAKECMD='qmake-qt4'
    PACKAGEINSCMD='apt-get install'
    SPECNAME='Ubuntu1204'
    ISCREATEDEB='1'
    DISTNAME='0ubuntu'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKINSTALL    /usr/share/build-essential/essential-packages-list  build-essential
    CHECKLIBINSTALL qmake-qt4                                           qt4-qmake
    CHECKINSTALL    /usr/include/qt4/Qt/qconfig.h                       libqt4-dev
    CHECKLIBINSTALL libQtHelp.so.4                                      libqt4-help
    CHECKLIBINSTALL qt4/plugins/sqldrivers/libqsqlite.so                libqt4-sql-sqlite
    CHECKLIBINSTALL /usr/include/QtMultimediaKit/qaudiooutput.h         qtmobility-dev
    CHECKINSTALL    /usr/include/libavutil/avutil.h                     libavutil-dev
    CHECKINSTALL    /usr/include/libavformat/avformat.h                 libavformat-dev
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                   libavcodec-dev
    CHECKINSTALL    /usr/include/libavdevice/avdevice.h                 libavdevice-dev
    CHECKINSTALL    /usr/include/libavfilter/avfilter.h                 libavfilter-dev
    CHECKINSTALL    /usr/include/libswscale/swscale.h                   libswscale-dev
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        libexiv2-dev
    CHECKINSTALL    /usr/include/taglib/taglib.h                        libtag1-dev
    #DEB creation
    CHECKINSTALL    /usr/bin/curl                                       curl
    CHECKINSTALL    /usr/bin/faked-sysv                                 fakeroot
    CHECKINSTALL    /usr/bin/pbuilder-dist                              ubuntu-dev-tools
    CHECKINSTALL    /etc/pbuilder/buildd-config.sh                      pbuilder
    CHECKINSTALL    /usr/bin/dh_make                                    dh-make
    CHECKINSTALL    /usr/bin/lintian                                    lintian
    CHECKINSTALL    /usr/bin/diff                                       diffutils
    CHECKINSTALL    /usr/bin/patch                                      patch
    CHECKINSTALL    /usr/bin/gpg                                        gnupg
    if [[ ! -e .pbuilderrc ]]; then
        echo "COMPONENTS=\"main restricted universe multiverse\"" >.pbuilderrc
        ${SUCMD} pbuilder create
    fi
}
#==============================================================================
# UBUNTU 12.10
#==============================================================================
UBUNTU1210_PREPQT4() {
    SUCMD='sudo '
    QMAKECMD='qmake-qt4'
    PACKAGEINSCMD='apt-get install'
    SPECNAME='Ubuntu1210'
    ISCREATEDEB='1'
    DISTNAME='0ubuntu'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKINSTALL    /usr/share/build-essential/essential-packages-list  build-essential
    CHECKLIBINSTALL qmake-qt4                                           qt4-qmake
    CHECKINSTALL    /usr/include/qt4/Qt/qconfig.h                       libqt4-dev
    CHECKLIBINSTALL libQtHelp.so.4                                      libqt4-help
    CHECKLIBINSTALL qt4/plugins/sqldrivers/libqsqlite.so                libqt4-sql-sqlite
    CHECKLIBINSTALL /usr/include/QtMultimediaKit/qaudiooutput.h         qtmobility-dev
    CHECKINSTALL    /usr/include/libavutil/avutil.h                     libavutil-dev
    CHECKINSTALL    /usr/include/libavformat/avformat.h                 libavformat-dev
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                   libavcodec-dev
    CHECKINSTALL    /usr/include/libavdevice/avdevice.h                 libavdevice-dev
    CHECKINSTALL    /usr/include/libavfilter/avfilter.h                 libavfilter-dev
    CHECKINSTALL    /usr/include/libswscale/swscale.h                   libswscale-dev
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        libexiv2-dev
    CHECKINSTALL    /usr/include/taglib/taglib.h                        libtag1-dev
    #DEB creation
    CHECKINSTALL    /usr/bin/curl                                       curl
    CHECKINSTALL    /usr/bin/faked-sysv                                 fakeroot
    CHECKINSTALL    /usr/bin/pbuilder-dist                              ubuntu-dev-tools
    CHECKINSTALL    /etc/pbuilder/buildd-config.sh                      pbuilder
    CHECKINSTALL    /usr/bin/dh_make                                    dh-make
    CHECKINSTALL    /usr/bin/lintian                                    lintian
    CHECKINSTALL    /usr/bin/diff                                       diffutils
    CHECKINSTALL    /usr/bin/patch                                      patch
    CHECKINSTALL    /usr/bin/gpg                                        gnupg
    if [[ ! -e .pbuilderrc ]]; then
        echo "COMPONENTS=\"main restricted universe multiverse\"" >.pbuilderrc
        ${SUCMD} pbuilder create
    fi
}
#==============================================================================
# UBUNTU 13.10
#==============================================================================
UBUNTU1310_PREPQT5() {
    SUCMD='sudo '
    QMAKECMD='qmake'
    PACKAGEINSCMD='apt-get install'
    SPECNAME='Ubuntu1310'
    DISTNAME='0ubuntu'
    ISCREATEDEB='1'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKINSTALL    /usr/share/build-essential/essential-packages-list  build-essential
    CHECKLIBINSTALL qt5/bin/qmake                                       qt5-qmake
    CHECKLIBINSTALL qtchooser/default.conf                              qt5-default
    CHECKINSTALL    /usr/include/qt5/QtCLucene/qtcluceneversion.h       qttools5-dev
    CHECKLIBINSTALL qt5/bin/lupdate                                     qttools5-dev-tools
    CHECKINSTALL    /usr/include/qt5/QtSvg/qgraphicssvgitem.h           libqt5svg5-dev
    CHECKLIBINSTALL libQt5Help.so.5                                     libqt5help5
    CHECKLIBINSTALL qt5/plugins/sqldrivers/libqsqlite.so                libqt5sql5-sqlite
    CHECKLIBINSTALL qt5/plugins/imageformats/libqmng.so                 qt5-image-formats-plugins
    CHECKINSTALL    /usr/include/qt5/QtMultimedia/qaudiooutput.h        qtmultimedia5-dev
    #ffmpeg, Exiv2
    CHECKINSTALL    /usr/include/libavutil/avutil.h                     libavutil-dev
    CHECKINSTALL    /usr/include/libavformat/avformat.h                 libavformat-dev
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                   libavcodec-dev
    CHECKINSTALL    /usr/include/libavdevice/avdevice.h                 libavdevice-dev
    CHECKINSTALL    /usr/include/libavfilter/avfilter.h                 libavfilter-dev
    CHECKINSTALL    /usr/include/libswscale/swscale.h                   libswscale-dev
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        libexiv2-dev
    CHECKINSTALL    /usr/include/taglib/taglib.h                        libtag1-dev
    CHECKINSTALL    /usr/include/pulse/pulseaudio.h                     libpulse-dev
    #DEB creation
    CHECKINSTALL    /usr/bin/curl                                       curl
    CHECKINSTALL    /usr/bin/faked-sysv                                 fakeroot
    CHECKINSTALL    /usr/bin/pbuilder-dist                              ubuntu-dev-tools
    CHECKINSTALL    /etc/pbuilder/buildd-config.sh                      pbuilder
    CHECKINSTALL    /usr/bin/dh_make                                    dh-make
    CHECKINSTALL    /usr/bin/lintian                                    lintian
    CHECKINSTALL    /usr/bin/diff                                       diffutils
    CHECKINSTALL    /usr/bin/patch                                      patch
    CHECKINSTALL    /usr/bin/gpg                                        gnupg
    if [[ ! -e .pbuilderrc ]]; then
        echo "COMPONENTS=\"main restricted universe multiverse\"" >.pbuilderrc
        ${SUCMD} pbuilder create
    fi
}
#==============================================================================
# UBUNTU 14.04
#==============================================================================
UBUNTU1404_PREPQT5() {
    SUCMD='sudo '
    QMAKECMD='qmake'
    PACKAGEINSCMD='apt-get install'
    SPECNAME='Ubuntu1404'
    DISTNAME='0ubuntu'
    ISCREATEDEB='1'
    echo ffDiaporama for $OSSYS_TYPE $OSSYS_VERS $OSSYS_ARCH
    echo
    echo Check dependencies ...
    #QT
    CHECKINSTALL    /usr/share/build-essential/essential-packages-list  build-essential
    CHECKLIBINSTALL qt5/bin/qmake                                       qt5-qmake
    CHECKLIBINSTALL qtchooser/default.conf                              qt5-default
    CHECKINSTALL    /usr/include/qt5/QtCLucene/qtcluceneversion.h       qttools5-dev
    CHECKLIBINSTALL qt5/bin/lupdate                                     qttools5-dev-tools
    CHECKINSTALL    /usr/include/qt5/QtSvg/qgraphicssvgitem.h           libqt5svg5-dev
    CHECKLIBINSTALL libQt5Help.so.5                                     libqt5help5
    CHECKLIBINSTALL qt5/plugins/sqldrivers/libqsqlite.so                libqt5sql5-sqlite
    CHECKLIBINSTALL qt5/plugins/imageformats/libqmng.so                 qt5-image-formats-plugins
    CHECKINSTALL    /usr/include/qt5/QtMultimedia/qaudiooutput.h        qtmultimedia5-dev
    #ffmpeg, Exiv2
    CHECKINSTALL    /usr/include/libavutil/avutil.h                     libavutil-dev
    CHECKINSTALL    /usr/include/libavformat/avformat.h                 libavformat-dev
    CHECKINSTALL    /usr/include/libavcodec/avcodec.h                   libavcodec-dev
    CHECKINSTALL    /usr/include/libavdevice/avdevice.h                 libavdevice-dev
    CHECKINSTALL    /usr/include/libavfilter/avfilter.h                 libavfilter-dev
    CHECKINSTALL    /usr/include/libswscale/swscale.h                   libswscale-dev
    CHECKINSTALL    /usr/include/libavresample/avresample.h             libavresample-dev
    CHECKINSTALL    /usr/include/exiv2/exiv2.hpp                        libexiv2-dev
    #DEB creation
    CHECKINSTALL    /usr/bin/curl                                       curl
    CHECKINSTALL    /usr/bin/faked-sysv                                 fakeroot
    CHECKINSTALL    /usr/bin/pbuilder-dist                              ubuntu-dev-tools
    CHECKINSTALL    /etc/pbuilder/buildd-config.sh                      pbuilder
    CHECKINSTALL    /usr/bin/dh_make                                    dh-make
    CHECKINSTALL    /usr/bin/lintian                                    lintian
    CHECKINSTALL    /usr/bin/diff                                       diffutils
    CHECKINSTALL    /usr/bin/patch                                      patch
    CHECKINSTALL    /usr/bin/gpg                                        gnupg
    if [[ ! -e .pbuilderrc ]]; then
        echo "COMPONENTS=\"main restricted universe multiverse\"" >.pbuilderrc
        ${SUCMD} pbuilder create
    fi
}
#==============================================================================
# MAIN
#==============================================================================
# Script init:
#   -Check command line parameters
if [[ ! "$1" == "" ]]; then
    USEFOLDER=$1
    ISDEVEL="0"
else
    ISDEVEL="1"
fi
#==============================================================================
# Environnement init:
#   -Get information about distribution, version and plateforme
OSSYS_TYPE=`cat /etc/os-release | grep ^NAME= | sed 's/NAME=//g' | sed 's/"//g'`
OSSYS_VERS=`cat /etc/os-release | grep ^VERSION_ID= | sed 's/VERSION_ID=//g' | sed 's/"//g'`
if [ -z "OSSYS_VERS" ]; then
    OSSYS_VERS=`cat /etc/os-release | grep ^PRETTY_NAME= | sed 's/PRETTY_NAME=//g' | sed 's/"//g'`
fi
OSSYS_ARCH=`uname -m`
#=========================
ISCREATERPM='0'
ISCREATEDEB='0'
DISTNAME=${OSSYS_TYPE}_$OSSYS_VERS
#==============================================================================
# Check dependencies: Depending on distribution, install all needed packages
if [[ $OSSYS_TYPE == "Fedora" ]];then
    if [[ $OSSYS_VERS == "19" ]];then
        FEDORA19_PREP
        if [[ $OSSYS_ARCH == "i686" ]]; then
            OSSYS_ARCH="i386"
        fi
    elif [[ $OSSYS_VERS == "20" ]];then
        FEDORA20_PREP
    else
        echo Unsupported Fedora version
        exit 1
    fi
elif [[ $OSSYS_TYPE == "openSUSE" ]];then
    if [[ $OSSYS_VERS == "12.3" ]];then
        SUZE123_PREPQT4
        if [[ $OSSYS_ARCH == "i686" ]]; then
            OSSYS_ARCH="i586"
        fi
    elif [[ $OSSYS_VERS == "13.1" ]];then
        SUZE131_PREPQT5
        if [[ $OSSYS_ARCH == "i686" ]]; then
            OSSYS_ARCH="i586"
        fi
    else
        echo Unsupported openSUSE version
        exit 1
    fi
elif [[ $OSSYS_TYPE == "Manjaro Linux" ]];then
    ARCHLINUX_PREP
elif [[ $OSSYS_TYPE == "Mageia" ]];then
    MAGEIA_PREP
elif [[ $OSSYS_TYPE == "Ubuntu" ]];then
    if [[ $OSSYS_VERS == "14.04" ]];then
        UBUNTU1404_PREPQT5
    elif [[ $OSSYS_VERS == "13.10" ]];then
        UBUNTU1310_PREPQT5
    elif [[ $OSSYS_VERS == "12.10" ]];then
        UBUNTU1210_PREPQT4
    elif [[ $OSSYS_VERS == "12.04" ]];then
        UBUNTU1204_PREPQT4
    else
        echo Unsupported Ubuntu version
        exit 1
    fi
    if [[ $OSSYS_ARCH == "i686" ]]; then
        OSSYS_ARCH="i386"
    else
        OSSYS_ARCH="amd64"
    fi
else
    echo Unsupported system
    exit 1
fi
#==============================================================================
# Check installed versions of ffdiaporama modules and determine which one must be installed
if [[ ! -d /opt/ffDiaporama ]]; then
    ${SUCMD} mkdir /opt/ffDiaporama
fi
#=========================
echo Check versions

DOWNLOAD RSCBUILDVERSION.txt /opt/ffDiaporama http://download.tuxfamily.org/ffdiaporama/Packages/Devel force hide
DOWNLOAD BUILDVERSION.txt /opt/ffDiaporama http://download.tuxfamily.org/ffdiaporama/Packages/Devel force hide
ISDEVEL="0"
DOWNLOAD TMTBUILDVERSION.txt /opt/ffDiaporama http://download.tuxfamily.org/ffdiaporama/Packages/Stable force hide
DOWNLOAD OCTBUILDVERSION.txt /opt/ffDiaporama http://download.tuxfamily.org/ffdiaporama/Packages/Stable force hide
#RSC
RSC_VERS=`cat /opt/ffDiaporama/RSCBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
RSC_DATE=`cat /opt/ffDiaporama/RSCBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
RSC_YEAR=${RSC_DATE:0:4}
RSC_MD=${RSC_DATE:4:4}
#FFD
FFD_VERS=`cat /opt/ffDiaporama/BUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
FFD_DATE=`cat /opt/ffDiaporama/BUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
FFD_YEAR=${FFD_DATE:0:4}
FFD_MD=${FFD_DATE:4:4}
#TMT
TMT_VERS=`cat /opt/ffDiaporama/TMTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
TMT_DATE=`cat /opt/ffDiaporama/TMTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
TMT_YEAR=${TMT_DATE:0:4}
TMT_MD=${TMT_DATE:4:4}
#OCT
OCT_VERS=`cat /opt/ffDiaporama/OCTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
OCT_DATE=`cat /opt/ffDiaporama/OCTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
OCT_YEAR=${OCT_DATE:0:4}
OCT_MD=${OCT_DATE:4:4}
echo === Latest ffDiaporama ressources version available on Web site: $RSC_VERS $RSC_YEAR.$RSC_MD
echo === Latest ffDiaporama bin version available on Web site: $FFD_VERS $FFD_YEAR.$FFD_MD
echo === Latest ffDiaporama texturemate version available on Web site: $TMT_VERS $TMT_YEAR.$TMT_MD
echo === Latest ffDiaporama openclipart version available on Web site: $OCT_VERS $OCT_YEAR.$OCT_MD
#====
SETUPRSC="0"
SETUPBIN="0"
SETUPTMT="0"
SETUPOCT="0"
#====
if [[ -e /usr/share/ffDiaporama/RSCBUILDVERSION.txt ]];then
    INSRSC_VERS=`cat /usr/share/ffDiaporama/RSCBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
    INSRSC_DATE=`cat /usr/share/ffDiaporama/RSCBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
    INSRSC_YEAR=${INSRSC_DATE:0:4}
    INSRSC_MD=${INSRSC_DATE:4:4}
    if [ ! $RSC_VERS == $INSRSC_VERS ] || [ ! $RSC_DATE == $INSRSC_DATE ];then
        echo === Installed ffDiaporama ressources version: $INSRSC_VERS $INSRSC_YEAR.$INSRSC_MD === to be updated
        SETUPRSC="1"
    else
        echo === Installed ffDiaporama ressources version: $INSRSC_VERS $INSRSC_YEAR.$INSRSC_MD === up to date
    fi
else
  INSRSC_VERS='false'
  INSRSC_DATE='false'
  INSRSC_YEAR='false'
  INSRSC_MD='false'
  echo === Installed ffDiaporama ressources version: not installed === to be installed
  SETUPRSC="1"
fi
#====
if [[ -e /usr/share/ffDiaporama/BUILDVERSION.txt ]];then
    INS_VERS=`cat /usr/share/ffDiaporama/BUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
    INS_DATE=`cat /usr/share/ffDiaporama/BUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
    INS_YEAR=${INS_DATE:0:4}
    INS_MD=${INS_DATE:4:4}
    if [ ! $FFD_VERS == $INS_VERS ] || [ ! $FFD_DATE == $INS_DATE ];then
        echo === Installed ffDiaporama bin version: $INS_VERS $INS_YEAR.$INS_MD === to be updated
        SETUPBIN="1"
    else
        echo === Installed ffDiaporama bin version: $INS_VERS $INS_YEAR.$INS_MD === up to date
    fi
else
  INS_VERS='false'
  INS_DATE='false'
  INS_YEAR='false'
  INS_MD='false'
  echo === Installed ffDiaporama bin version: not installed === to be installed
  SETUPBIN="1"
fi
#====
if [[ -e /usr/share/ffDiaporama/background/texturemate/TMTBUILDVERSION.txt ]];then
    INSTMT_VERS=`cat /usr/share/ffDiaporama/background/texturemate/TMTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
    INSTMT_DATE=`cat /usr/share/ffDiaporama/background/texturemate/TMTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
    INSTMT_YEAR=${INSTMT_DATE:0:4}
    INSTMT_MD=${INSTMT_DATE:4:4}
    if [ ! $TMT_VERS == $INSTMT_VERS ] || [ ! $TMT_DATE == $INSTMT_DATE ];then
        echo === Installed ffDiaporama texturemate version: $INSTMT_VERS $INSTMT_YEAR.$INSTMT_MD === to be updated
        SETUPTMT="1"
    else
        echo === Installed ffDiaporama texturemate version: $INSTMT_VERS $INSTMT_YEAR.$INSTMT_MD === up to date
    fi
else
    INSTMT_VERS='false'
    INSTMT_DATE='false'
    INSTMT_YEAR='false'
    INSTMT_MD='false'
    read -p "ffDiaporama-texturemate is not installed. Do you want to install it (y/n)?" -n 1 -r
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        SETUPTMT="1"
    fi
    echo
fi
#====
if [[ -e /usr/share/ffDiaporama/clipart/OCTBUILDVERSION.txt ]];then
    INSOCT_VERS=`cat /usr/share/ffDiaporama/clipart/OCTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f1 | sed 's/_/-/g'`
    INSOCT_DATE=`cat /usr/share/ffDiaporama/clipart/OCTBUILDVERSION.txt | grep ^Version | sed 's/Version //g' | cut -d' ' -f2`
    INSOCT_YEAR=${INSOCT_DATE:0:4}
    INSOCT_MD=${INSOCT_DATE:4:4}
    if [ ! $OCT_VERS == $INSOCT_VERS ] || [ ! $OCT_DATE == $INSOCT_DATE ];then
        echo === Installed ffDiaporama openclipart version: $INSOCT_VERS $INSOCT_YEAR.$INSOCT_MD === to be updated
        SETUPOCT="1"
    else
        echo === Installed ffDiaporama openclipart version: $INSOCT_VERS $INSOCT_YEAR.$INSOCT_MD === up to date
    fi
else
    INSOCT_VERS='false'
    INSOCT_DATE='false'
    INSOCT_YEAR='false'
    INSOCT_MD='false'
    read -p "ffDiaporama-openclipart is not installed. Do you want to install it (y/n)?" -n 1 -r
    if [[ $REPLY =~ ^[Yy]$ ]]; then
        SETUPOCT="1"
    fi
    echo
fi
#=========================
if [[ $FFD_VERS == *devel* ]]; then
    ISDEVEL="1"
    SETUPFULL="0"
else
    ISDEVEL="0"
    if [[ $SETUPRSC == "1" ]] || [[ $SETUPBIN == "1" ]]; then
        SETUPFULL="1"
    else
        SETUPFULL="0"
    fi
fi
#==============================================================================
# Do packages creations and/or installation
if [[ $SETUPFULL == "1" ]] && [[ $ISDEVEL == "0" ]];then
    DOTED=`echo $RSC_VERS | sed 's/-/./g'`
    filenamersc="ffdiaporama_rsc_$DOTED.$RSC_YEAR.$RSC_MD.tar.gz"
    #Call GETADDRESS to get full URL of package to download (address is return in $address)
    GETADDRESS $filenamersc
    DOWNLOAD $filenamersc /opt/ffDiaporama $address
    DOTED=`echo $FFD_VERS | sed 's/-/./g'`
    filenamebin="ffdiaporama_bin_$DOTED.$FFD_YEAR.$FFD_MD.tar.gz"
    #Call GETADDRESS to get full URL of package to download (address is return in $address)
    GETADDRESS $filenamebin
    DOWNLOAD $filenamebin /opt/ffDiaporama $address
    if [[ $ISCREATERPM == "1" ]];then
        echo
        echo Create RPM package for ffDiaporama ressources+bin version $FFD_VERS $FFD_YEAR.$FFD_MD
        CREATERPM bin+rsc ${DOTED}.$FFD_YEAR.$FFD_MD $OSSYS_ARCH $filenamebin $DISTNAME $filenamersc
    elif [[ $ISCREATEDEB == "1" ]];then
        echo
        echo Create DEB package for ffDiaporama ressources+bin version $FFD_VERS $FFD_YEAR.$FFD_MD
        CREATEDEB bin+rsc ${DOTED}.$FFD_YEAR.$FFD_MD $OSSYS_ARCH $filenamebin $DISTNAME $filenamersc
    else
        echo
        echo Install ffDiaporama ressources+bin version $FFD_VERS $FFD_YEAR.$FFD_MD
        cd /opt/ffDiaporama
        ${SUCMD} tar -xzf /opt/ffDiaporama/$filename
        cd ffDiaporama_rsc
        $QMAKECMD ffDiaporama_rsc.pro
        make
        ${SUCMD} make install
        cd ..
    fi
fi
#=========================
if [[ $SETUPRSC == "1" ]] && [[ $ISDEVEL == "1" ]];then
    DOTED=`echo $RSC_VERS | sed 's/-/./g'`
    filename="ffdiaporama_rsc_$DOTED.$RSC_YEAR.$RSC_MD.tar.gz"
    #Call GETADDRESS to get full URL of package to download (address is return in $address)
    GETADDRESS $filename
    DOWNLOAD $filename /opt/ffDiaporama $address
    if [[ $ISCREATERPM == "1" ]];then
        echo
        echo Create RPM package for ffDiaporama ressources version $RSC_VERS $RSC_YEAR.$RSC_MD
        CREATERPM rsc ${DOTED}.$RSC_YEAR.$RSC_MD noarch $filename $DISTNAME
    elif [[ $ISCREATEDEB == "1" ]];then
        echo
        echo Create DEB package for ffDiaporama ressources version $RSC_VERS $RSC_YEAR.$RSC_MD
        CREATEDEB rsc ${DOTED}.$RSC_YEAR.$RSC_MD noarch $filename $DISTNAME
    else
        echo
        echo Install ffDiaporama ressources version $RSC_VERS $RSC_YEAR.$RSC_MD
        cd /opt/ffDiaporama
        ${SUCMD} tar -xzf /opt/ffDiaporama/$filename
        cd ffDiaporama_rsc
        $QMAKECMD ffDiaporama_rsc.pro
        make
        ${SUCMD} make install
        cd ..
    fi
fi
#=========================
if [[ $SETUPBIN == "1" ]]  && [[ $ISDEVEL == "1" ]];then
    DOTED=`echo $FFD_VERS | sed 's/-/./g'`
    filename="ffdiaporama_bin_$DOTED.$FFD_YEAR.$FFD_MD.tar.gz"
    #Call GETADDRESS to get full URL of package to download (address is return in $address)
    GETADDRESS $filename
    DOWNLOAD $filename /opt/ffDiaporama $address
    if [[ $ISCREATERPM == "1" ]];then
        echo
        echo Create RPM package for ffDiaporama bin version $FFD_VERS $FFD_YEAR.$FFD_MD
        CREATERPM bin ${DOTED}.$FFD_YEAR.$FFD_MD $OSSYS_ARCH $filename $DISTNAME
    elif [[ $ISCREATEDEB == "1" ]];then
        echo
        echo Create DEB package for ffDiaporama bin version $FFD_VERS $FFD_YEAR.$FFD_MD
        CREATEDEB bin ${DOTED}.$FFD_YEAR.$FFD_MD $OSSYS_ARCH $filename $DISTNAME
    else
        echo
        echo Install ffDiaporama bin version $FFD_VERS $FFD_YEAR.$FFD_MD
        cd /opt/ffDiaporama
        ${SUCMD} mkdir ffDiaporama
        cd ffDiaporama
        ${SUCMD} tar -xzf ../$filename
        $QMAKECMD ffDiaporama.pro
        make
        ${SUCMD} make install
        cd ..
    fi
fi
#=========================
if [[ $SETUPRSC == "1" ]] || [[ $SETUPBIN == "1" ]]; then
    if [[ $ISDEVEL == "1" ]] && [[ $ISCREATERPM == "1" ]];then
        echo
        echo Create RPM package for ffDiaporama version $FFD_VERS $FFD_YEAR.$FFD_MD
        DOTED=`echo $FFD_VERS | sed 's/-/./g'`
        CREATERPM bin+rsc ${DOTED}.$FFD_YEAR.$FFD_MD noarch empty $DISTNAME
    elif [[ $ISDEVEL == "1" ]] && [[ $ISCREATEDEB == "1" ]];then
        echo
        echo Create DEB package for ffDiaporama version $FFD_VERS $FFD_YEAR.$FFD_MD
        DOTED=`echo $FFD_VERS | sed 's/-/./g'`
        CREATEDEB bin+rsc ${DOTED}.$FFD_YEAR.$FFD_MD noarch empty $DISTNAME
    fi
fi
#=========================
if [[ $SETUPTMT == "1" ]];then
    ISDEVEL="0"
    DOTED=`echo $TMT_VERS | sed 's/-/./g'`
    filename="ffdiaporama_texturemate_$DOTED.$TMT_YEAR.$TMT_MD.tar.gz"
    #Call GETADDRESS to get full URL of package to download (address is return in $address)
    GETADDRESS $filename
    DOWNLOAD $filename /opt/ffDiaporama $address
    if [[ $ISCREATERPM == "1" ]];then
        echo
        echo Create RPM package for ffDiaporama texturemate version $TMT_VERS $TMT_YEAR.$TMT_MD
        CREATERPM texturemate ${DOTED}.$TMT_YEAR.$TMT_MD noarch $filename $DISTNAME
    elif [[ $ISCREATEDEB == "1" ]];then
        echo
        echo Create DEB package for ffDiaporama texturemate version $TMT_VERS $TMT_YEAR.$TMT_MD
        CREATEDEB texturemate ${DOTED}.$TMT_YEAR.$TMT_MD noarch $filename $DISTNAME
    else
        echo
        echo Install ffDiaporama texturemate version $TMT_VERS $TMT_YEAR.$TMT_MD
        cd /opt/ffDiaporama
        ${SUCMD} tar -xzf $filename
        cd ffDiaporama_texturemate
        $QMAKECMD ffDiaporama_texturemate.pro
        make
        ${SUCMD} make install
        cd ..
    fi
fi
#=========================
if [[ $SETUPOCT == "1" ]];then
    ISDEVEL="0"
    DOTED=`echo $OCT_VERS | sed 's/-/./g'`
    filename="ffdiaporama_openclipart_$DOTED.$OCT_YEAR.$OCT_MD.tar.gz"
    #Call GETADDRESS to get full URL of package to download (address is return in $address)
    GETADDRESS $filename
    DOWNLOAD $filename /opt/ffDiaporama $address
    if [[ $ISCREATERPM == "1" ]];then
        if [[ $OSSYS_TYPE == "openSUSE" ]];then
            CHECKINSTALL /usr/share/clipart/openclipart-0.18/animals/architetto_francesco_ro_01.svg openclipart-svg
        elif [[ $OSSYS_TYPE == "Fedora" ]];then
            CHECKINSTALL /usr/share/clipart/openclipart/animals/2_dead_frogs_lumen_desig_01.svg openclipart
        fi
        echo
        echo Create RPM package for ffDiaporama openclipart version $OCT_VERS $OCT_YEAR.$OCT_MD
        CREATERPM openclipart ${DOTED}.$OCT_YEAR.$OCT_MD noarch $filename $DISTNAME
    elif [[ $ISCREATEDEB == "1" ]];then
        #if [[ $OSSYS_TYPE == "openSUSE" ]];then
        #    CHECKINSTALL /usr/share/clipart/openclipart-0.18/animals/architetto_francesco_ro_01.svg openclipart-svg
        #elif [[ $OSSYS_TYPE == "Fedora" ]];then
        #    CHECKINSTALL /usr/share/clipart/openclipart/animals/2_dead_frogs_lumen_desig_01.svg openclipart
        #fi
        echo
        echo Create DEB package for ffDiaporama openclipart version $OCT_VERS $OCT_YEAR.$OCT_MD
        CREATEDEB openclipart ${DOTED}.$OCT_YEAR.$OCT_MD noarch $filename $DISTNAME
    else
        cd /opt/ffDiaporama
        ${SUCMD} tar -xzf $filename
        cd ffDiaporama_openclipart
        ${SUCMD} chmod +x setup.bash
        ${SUCMD} ./setup.bash
        cd ..
    fi
fi
#==============================================================================
# Script end: cleaning
cd ~
if [ -d /tmp/rpmbuild ]; then
    rm -R /tmp/rpmbuild
fi
if [ -d /tmp/debbuild ]; then
    #rm -R /tmp/debbuild
    echo
fi
