#!/bin/sh

# Copyright (C) 2016  Etersoft
# Copyright (C) 2016  Danil Mikhailov <danil@etersoft.ru>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

myinit(){
    etersoft_updates_site="http://updates.etersoft.ru/pub/Etersoft/Sisyphus/$($DISTRVENDOR -e)/"
    download_dir="/tmp"
}

download_epm(){
    download_link=$etersoft_updates_site$(wget -qO- $etersoft_updates_site/ | grep -m1 -Eo "eepm[^\"]+\.$($DISTRVENDOR -p)" | tail -n1) #"
    eepm_package="$download_dir/$(basename $download_link)"
    wget -O $eepm_package $download_link
}

epm_epm_install(){
    myinit
    download_epm || fatal "Error. Check download link: $download_link"
    epm i $eepm_package || fatal
    rm -fv $eepm_package
}