#!/bin/sh
#
#
#    See the file COPYING.GPL.txt, included in this distribution,
#    for details about the copyright.
#
#    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.
#
#    "install" Copyright (c) by "Fedoramedia team". Is free software,  This
#    works in GNU/Linux, FreeBSD and others, is freed under the terms of the
#    GPL (GNU GENERAL PUBLIC LICENSE). More information can be found in :
#
#    http://www.fedoramedia.cf
#    _________________________________________________________
#
#    You can support this project by sending a donation to :
#
#    Paypal [http://mklauncher.osdn.io/en/donate.html]
#
#

##### Vars #####

Error=""
Platform_folder="$(pwd)"

##### Functions #####

previous_folder()
{
    ##### Change to previous folder #####

    cd ..
}

platform_folder()
{
    ##### Change to platform folder #####

    cd $Platform_folder    
}

check_dependencies()
{
    echo "--- Check dependencies ---"
    
    ##### ./mklauncher #####

    if test -e "./mklauncher"; then
    
       true
    else
       echo "Error: \"mklauncher\" not found."
       exit 1
    fi
    
    ##### iconrb #####

    if test -e "$Platform_folder/iconrb"; then
    
       true
    else
       echo "Error: \"iconrb\" not found."
       exit 1
    fi

    ##### xdg-utils #####

    if which xdg-open; then
    
       echo "- OK Package \"xdg-utils\" found."
    else
       echo "Note: It is recommended to install the \"xdg-utils\" package,"
       echo "in order to use the \"xdg-open\" command."
    fi

    ##### gksu #####

    if which gksu; then
    
       echo "- OK Package \"gksu\" found"
    else
       echo "Note: It is recommended to install the \"gksu\" package,"
       echo "in order to use the \"gksu\" command."
    fi

    ##### ImageMagick #####

    if which convert; then
    
       echo "- OK Package \"ImageMagick\" found."
    else
       echo "Note: It is recommended to install the \"ImageMagick\" package,"
       echo "in order to use the \"iconrb\" command."
    fi
}

preinstall()
{
    echo "--- Preinstall tasks ---"
    check_dependencies
}

install()
{
    echo "--- Install ---"

    #### mklauncher ####
    
    cp ./mklauncher /usr/local/bin

    #### /usr/share/icons ####
    
    if test -d "/usr/share/icons"; then 
       cp ./icons/mk-*.png /usr/share/icons
    fi

    #### /usr/local/share/icons ####

    if test -d "/usr/local/share/icons"; then 
       cp ./icons/mk-*.png /usr/local/share/icons
    fi

    #### iconrb ####

    cp $Platform_folder/iconrb /usr/local/bin
}

posinstall()
{
    echo "--- Posinstall tasks ---"
    echo "--- OK Installation completed ---"
}

##### Main #####

previous_folder
preinstall
install
posinstall
platform_folder

