#!/bin/sh
#
# Copyright (C) 2012-2020  Etersoft
# Copyright (C) 2012-2020  Vitaly Lipatov <lav@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/>.
#


epm_print_install_files_command()
{
    # print out low level command by default (wait --low-level for control it)
    #[ -z "$1" ] && return
    [ -z "$1" ] && [ -n "$pkg_names" ] && return
    case $PMTYPE in
        *-rpm)
            echo "rpm -Uvh --force $nodeps $*"
            ;;
        *-dpkg)
            echo "dpkg -i $*"
            ;;
        pkgsrc)
            echo "pkg_add $*"
            ;;
        pkgng)
            echo "pkg add $*"
            ;;
        emerge)
            # need be placed in /usr/portage/packages/somewhere
            echo "emerge --usepkg $*"
            ;;
        pacman)
            echo "pacman -U --noconfirm $nodeps $*"
            ;;
        slackpkg)
            echo "/sbin/installpkg $*"
            ;;
        npackd)
            echo "npackdcl add --package=$*"
            ;;
        opkg)
            echo "opkg install $*"
            ;;
        eopkg)
            echo "eopkg install $*"
            ;;
        android)
            echo "pm install $*"
            ;;
        termux-pkg)
            echo "pkg install $*"
            ;;
        aptcyg)
            echo "apt-cyg install $*"
            ;;
        tce)
            echo "tce-load -wi $*"
            ;;
        xbps)
            echo "xbps-install -y $*"
            ;;
        appget|winget)
            echo "$PMTYPE install -s $*"
            ;;
        homebrew)
            # FIXME: sudo and quote
            echo "brew install $*"
            ;;

        *)
            fatal "Have no suitable appropriate install command for $PMTYPE"
            ;;
    esac
}

epm_print_install_names_command()
{
    # check for pkg_files to support print out command without pkg names in args
    #[ -z "$1" ] && [ -n "$pkg_files" ] && return
    [ -z "$1" ] && return
    case $PMTYPE in
        apt-rpm)
            echo "apt-get -y --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS install $*"
            return ;;
        apt-dpkg)
            # this command  not for complex use. ACCEPT_EULA=y DEBIAN_FRONTEND=noninteractive
            echo "apt-get -y --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS install $*"
            return ;;
        aptitude-dpkg)
            echo "aptitude -y install $*"
            return ;;
        yum-rpm)
            echo "yum -y $YUMOPTIONS install $*"
            return ;;
        dnf-rpm)
            echo "dnf -y $YUMOPTIONS --allowerasing install $*"
            return ;;
        urpm-rpm)
            echo "urpmi --auto $URPMOPTIONS $*"
            return ;;
        zypper-rpm)
            echo "zypper --non-interactive $ZYPPEROPTIONS install $*"
            return ;;
        packagekit)
            echo "pkcon --noninteractive $*"
            return ;;
        pacman)
            echo "pacman -S --noconfirm $*"
            return ;;
        choco)
            echo "choco install $*"
            return ;;
        nix)
            echo "nix-env --install $*"
            return ;;
        eopkg)
            echo "eopkg install $*"
            return ;;
        termux-pkg)
            echo "pkg install $*"
            return ;;
        appget|winget)
            echo "$PMTYPE install $*"
            return ;;
        *)
            fatal "Have no suitable appropriate install command for $PMTYPE"
            ;;
    esac
}