epm-simulate 2.58 KB
Newer Older
1 2 3 4 5
#!/bin/sh
#
# Copyright (C) 2012  Etersoft
# Copyright (C) 2012  Vitaly Lipatov <lav@etersoft.ru>
#
6 7 8
# 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
9 10 11 12 13
# (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
14
# GNU Affero General Public License for more details.
15
#
16 17
# 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/>.
18 19
#

20
load_helper epm-install
21
load_helper epm-search
22

23
_epm_do_simulate()
24
{
25 26 27
	local CMD
	local filenames=$@

Vitaly Lipatov's avatar
Vitaly Lipatov committed
28 29 30 31 32
    case $PMTYPE in
    	apt-rpm|apt-dpkg)
    		CMD="apt-get --simulate install"
    		;;
    	yum-rpm)
33 34 35 36
    		LC_ALL=C sudocmd yum --assumeno install $filenames
    		# FIXME: check only error output
    		LC_ALL=C sudocmd yum --assumeno install $filenames 2>&1 | grep "^No package" && return 1
    		return 0 ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
37 38 39 40 41 42
    	urpm-rpm)
    		CMD="urpmi --test --auto"
    		;;
    	zypper-rpm)
    		CMD="zypper --non-interactive install --dry-run"
    		;;
43 44 45
    	emerge)
    		echo "FIXME: Skip with emerge"
    		return ;;
46
    	pacman)
47 48
    		showcmd $SUDO pacman -v -S $filenames
    		echo no | $SUDO pacman -v -S $filenames
49
    		return ;;
50
    	slackpkg)
51 52
    		#docmd /usr/sbin/slackpkg -batch=on -default_answer=yes download
    		# just try search every package
53 54 55 56
    		# FIXME: epm_search have to return false status code if the package does not found
    		local pkg res
    		res=0
    		for pkg in $filenames ; do
57 58 59 60
    			pkg_filenames="$pkg-[0-9]" epm_search | grep -E "(installed|upgrade)" && continue
    			pkg_filenames="$pkg" epm_search | grep -E "(installed|upgrade)" && continue
    			res=1
    			echo "Does not found in repository."
61
    		done
62
    		return $res ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
63
    	*)
64
    		fatal "Do not known simulate command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
65 66 67
    		;;
    esac

68
    sudocmd $CMD $filenames
69 70
}

71 72 73 74 75 76
epm_simulate()
{
    [ -z "$pkg_filenames" ] && echo "Skip empty list" && return 2

    local filenames="$(echo $pkg_filenames | filter_out_installed_packages)"

77
    [ -z "$filenames" ] && echo "All packages are already installed" && return 0
78 79 80 81 82 83 84 85 86

    _epm_do_simulate $filenames
    local RES=$?
    if [ -z "$quiet" ] ; then
        [ "$RES" = 0 ] && echo "Result: $filenames package(s) CAN BE installed" || echo "Result: There are PROBLEMS with install some package(s)"
    fi
    return $RES
}