#!/bin/sh


name="masterpdfeditor5"
source=$(pwd)
directory=""
directory1="../../master-pdf-editor/usr/share/applications/"
directory2="../../usr/share/applications/"
directory3="usr/share/applications/"


isExist=0

foo_directory () {
    cd ${1} 2>/dev/null
    local res=$?
    if [ $res -ne 0 ] || [ $isExist -eq 1 ]; then
        return 1
    fi
    directory=${1}
    isExist=1
}

foo_directory ${directory1}
foo_directory ${directory2}
foo_directory ${directory3}

if [ $isExist -eq 0 ]; then
    echo "Needed directories doesn't exist"
    exit 1
fi

icon_path="${source}/${name}.png"
file="net.code-industry.masterpdfeditor5.desktop"
sed -i -e "s!.*Path=.*!Path=$source/!" -e "s!.*Exec=.*!Exec=$source/$name!" -e "s!.*Icon=.*!Icon=$icon_path!" ${file}
cd ../../../
cp -R usr/ / -v
