#!/bin/sh
#
# Copyright (C) 2012  Etersoft
# Copyright (C) 2012  Vitaly Lipatov <lav@etersoft.ru>
#
# This file 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
#

# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
epm_reinstall_names()
{
	[ -n "$1" ] || return
	case $PMTYPE in
		apt-rpm|apt-dpkg)
			docmd $SUDO apt-get --reinstall install $@
			return ;;
		yum-rpm)
			docmd $SUDO yum install $@
			return ;;
		urpm-rpm)
			docmd $SUDO urpmi $@
			return ;;
		zypper-rpm)
			docmd $SUDO zypper install $@
			return ;;
		pkg_add)
			docmd $SUDO pkg_add -r $@
			return ;;
		pacman)
			docmd $SUDO pacman -U $@
			return ;;
		slackpkg)
			docmd $SUDO slackpkg reinstall $@
			return ;;
		*)
			fatal "Do not known install command for $PMTYPE"
			;;
	esac
}

epm_reinstall_files()
{
    [ -z "$1" ] && return

    case $PMTYPE in
        apt-rpm)
            docmd $SUDO rpm -Uvh --force $@ && return
            docmd $SUDO apt-get --reinstall install $@
            return ;;
        apt-pkg)
            docmd $SUDO dpkg -i $@
            return ;;
        slackpkg)
            docmd $SUDO installpkg $@
            return ;;
    esac

    # other systems can install file package via ordinary command
    epm_reinstall_names $@
}


epm_reinstall()
{
    [ -n "$pkg_filenames" ] || fatal "Run install without packages"

    epm_reinstall_names $pkg_names
    epm_reinstall_files $pkg_files
}