epm-install 16.6 KB
Newer Older
Vitaly Lipatov's avatar
Vitaly Lipatov committed
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012-2017  Etersoft
# Copyright (C) 2012-2017  Vitaly Lipatov <lav@etersoft.ru>
Vitaly Lipatov's avatar
Vitaly Lipatov committed
5
#
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
Vitaly Lipatov's avatar
Vitaly Lipatov committed
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.
Vitaly Lipatov's avatar
Vitaly Lipatov committed
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/>.
Vitaly Lipatov's avatar
Vitaly Lipatov committed
18 19
#

20
load_helper epm-sh-altlinux
21
load_helper epm-query
22
load_helper epm-assure
23
load_helper epm-check_updated_repo
24
load_helper epm-sh-warmup
25

26 27 28 29 30 31 32 33 34 35
# TODO: use when run install with epm --skip-installed install
filter_out_installed_packages()
{
	[ -z "$skip_installed" ] && cat && return

	case $PKGFORMAT in
		"rpm")
			LANG=C LC_ALL=C xargs -n1 rpm -q 2>&1 | grep 'is not installed' |
				sed -e 's|^.*package \(.*\) is not installed.*|\1|g'
			;;
36 37 38 39 40
		# dpkg -l lists some non ii status (un, etc)
		#"deb")
		#	LANG=C LC_ALL=C xargs -n1 dpkg -l 2>&1 | grep -i 'no packages found matching' |
		#		sed -e 's|\.\+$||g' -e 's|^.*[Nn]o packages found matching \(.*\)|\1|g'
		#	;;
41
		*)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
42
			# shellcheck disable=SC2013
43 44 45
			for i in $(cat) ; do
				is_installed $i || echo $i
			done
46
			;;
47
	esac | sed -e "s|rpm-build-altlinux-compat[^ ]*||g" | filter_strip_spaces
48 49
}

50 51 52
# for zypper before SUSE/11.0
__use_zypper_no_gpg_checks()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
53
    a='' zypper install --help 2>&1 | grep -q -- "--no-gpg-checks" && echo "--no-gpg-checks"
54
}
55

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
# args: cmd_reinstall, cmd_install, packages
__separate_sudocmd_foreach()
{
    local cmd_re=$1
    local cmd_in=$2
    shift 2
    separate_installed $@
    if [ -n "$pkg_noninstalled" ] ; then
        sudocmd_foreach "$cmd_re" $pkg_noninstalled || return
    fi
    if [ -n "$pkg_installed" ] ; then
        sudocmd_foreach "$cmd_in" $pkg_installed || return
    fi
    return 0
}

# args: cmd_reinstall, cmd_install, packages
__separate_sudocmd()
{
    local cmd_re=$1
    local cmd_in=$2
    shift 2
    separate_installed $@
    if [ -n "$pkg_noninstalled" ] ; then
        sudocmd "$cmd_re" $pkg_noninstalled || return
    fi
    if [ -n "$pkg_installed" ] ; then
        sudocmd "$cmd_in" $pkg_installed || return
    fi
    return 0
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
88
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
89
epm_install_names()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
90
{
91 92 93 94
	[ -z "$1" ] && return

	warmup_hibase

95 96 97 98 99
	if [ -n "$non_interactive" ] ; then
		epm_ni_install_names "$@"
		return
	fi

100
	case $PMTYPE in
101
		apt-rpm|apt-dpkg)
102
			APTOPTIONS="$APTOPTIONS $(subst_option verbose "-o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
103
			sudocmd apt-get $APTOPTIONS $noremove install $@
104
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
105 106 107
		aptitude-dpkg)
			sudocmd aptitude install $@
			return ;;
108 109 110
		deepsolver-rpm)
			sudocmd ds-install $@
			return ;;
111
		urpm-rpm)
112
			sudocmd urpmi $URPMOPTIONS $@
113
			return ;;
114
		pkgsrc)
115
			sudocmd pkg_add -r $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
116
			return ;;
117 118 119
		pkgng)
			sudocmd pkg install $@
			return ;;
120
		emerge)
121
			sudocmd emerge -uD $@
122
			return ;;
123
		pacman)
124
			sudocmd pacman -S $force $nodeps $@
125
			return ;;
126 127 128
		aura)
			sudocmd aura -A $force $nodeps $@
			return ;;
129
		yum-rpm)
130
			sudocmd yum $YUMOPTIONS install $@
131
			return ;;
132 133 134
		dnf-rpm)
			sudocmd dnf install $@
			return ;;
135 136 137
		snappy)
			sudocmd snappy install $@
			return ;;
138
		zypper-rpm)
139
			sudocmd zypper install $ZYPPEROPTIONS $@
140 141
			return ;;
		mpkg)
142
			sudocmd mpkg install $@
143
			return ;;
144 145 146
		conary)
			sudocmd conary update $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
147
		npackd)
148 149
			# FIXME: correct arg
			__separate_sudocmd_foreach "npackdcl add --package=" "npackdcl update --package=" $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
150
			return ;;
151
		slackpkg)
152
			__separate_sudocmd_foreach "/usr/sbin/slackpkg install" "/usr/sbin/slackpkg upgrade" $@
153 154
			return ;;
		homebrew)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
155
			# FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
156
			SUDO='' __separate_sudocmd "brew install" "brew upgrade" "$@"
157 158 159 160
			return ;;
		ipkg)
			[ -n "$force" ] && force=-force-depends
			sudocmd ipkg $force install $@
161
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
162
		nix)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
163
			__separate_sudocmd "nix-env --install" "nix-env --upgrade" "$@"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
164
			return ;;
165 166 167
		apk)
			sudocmd apk add $@
			return ;;
168 169 170
		tce)
			sudocmd tce-load -wi $@
			return ;;
171 172 173
		guix)
			__separate_sudocmd "guix package -i" "guix package -i" $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
174
		android)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
175
			fatal "We still have no idea how to use package repository, ever if it is F-Droid."
176
			return ;;
177 178 179
		aptcyg)
			sudocmd apt-cyg install $@
			return ;;
180 181 182
		xbps)
			sudocmd xbps-install $@
			return ;;
183
		*)
184
			fatal "Have no suitable install command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
185
			;;
186 187 188
	esac
}

189
# Non interactive install
190 191
epm_ni_install_names()
{
Danil Mikhailov's avatar
Danil Mikhailov committed
192
	[ -z "$1" ] && return
193

194
	case $PMTYPE in
195
		apt-rpm|apt-dpkg)
196
			export DEBIAN_FRONTEND=noninteractive
197
			sudocmd apt-get -y $noremove --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" $APTOPTIONS install $@
198
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
199
		aptitude-dpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
200
			sudocmd aptitude -y install $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
201
			return ;;
202
		yum-rpm)
203
			sudocmd yum -y $YUMOPTIONS install $@
204
			return ;;
205 206 207
		dnf-rpm)
			sudocmd dnf -y $YUMOPTIONS install $@
			return ;;
208
		urpm-rpm)
209
			sudocmd urpmi --auto $URPMOPTIONS $@
210 211
			return ;;
		zypper-rpm)
212
			# FIXME: returns true ever no package found, need check for "no found", "Nothing to do."
213
			yes | sudocmd zypper --non-interactive $ZYPPEROPTIONS install $@
214
			return ;;
215
		pkgsrc)
216
			sudocmd pkg_add -r $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
217
			return ;;
218 219 220
		pkgng)
			sudocmd pkg install -y $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
221 222 223
		emerge)
			sudocmd emerge -uD $@
			return ;;
224
		pacman)
225
			sudocmd pacman -S --noconfirm $force $nodeps $@
226
			return ;;
227 228 229
		aura)
			sudocmd aura -A $force $nodeps $@
			return ;;
230 231
		npackd)
			#  npackdcl update --package=<package> (remove old and install new)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
232
			sudocmd npackdcl add --package="$*"
233
			return ;;
234 235 236
		chocolatey)
			docmd chocolatey install $@
			return ;;
237 238 239
		ipkg)
			sudocmd ipkg -force-defaults install $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
240 241 242
		nix)
			sudocmd nix-env --install $@
			return ;;
243 244 245
		apk)
			sudocmd apk add $@
			return ;;
246 247 248
		tce)
			sudocmd tce-load -wi $@
			return ;;
249 250 251
		xbps)
			sudocmd xbps-install -y $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
252 253
		homebrew)
			# FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
254
			SUDO='' __separate_sudocmd "brew install" "brew upgrade" $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
255
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
256 257 258
		#android)
		#	sudocmd pm install $@
		#	return ;;
259
		slackpkg)
260
			# FIXME: broken status when use batch and default answer
261
			__separate_sudocmd_foreach "/usr/sbin/slackpkg -batch=on -default_answer=yes install" "/usr/sbin/slackpkg -batch=on -default_answer=yes upgrade" $@
262
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
263
		*)
264
			fatal "Have no suitable appropriate install command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
265 266 267 268
			;;
	esac
}

269 270 271 272 273 274
__epm_check_if_rpm_already_installed()
{
	# Not: we can make optimize if just check version?
	LANG=C $SUDO rpm -Uvh $force $nodeps $@ 2>&1 | grep -q "is already installed"
}

275 276 277 278 279 280 281 282 283 284 285 286 287
# TODO: rewrite to convert (get some code from Korinf?)
__epm_check_if_try_install_deb()
{
	local pkg
	local debpkgs=""
	for pkg in $@ ; do
		[ "$(get_package_type "$pkg")" = "deb" ] || return 1
		[ -e "$pkg" ] || fatal "Can't read $pkg"
		debpkgs="$debpkgs $(realpath $pkg)"
	done
	[ -n "$debpkgs" ] || return 1

	assure_exists alien
288 289 290
	assure_exists dpkg
	# TODO: Для установки требует: /usr/share/debconf/confmodule но пакет не может быть установлен
	# assure_exists debconf
291 292

	local TDIR=$(mktemp -d)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
293
	cd $TDIR || fatal
294
	for pkg in $debpkgs ; do
295 296 297 298
		# TODO: fakeroot for non ALT?
		showcmd_store_output alien -r -k --scripts "$pkg" || fatal
		local RPMCONVERTED=$(grep "rpm generated" $RC_STDOUT | sed -e "s| generated||g")
		clean_store_output
299
		docmd epm install $force $nodeps $RPMCONVERTED
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
	done
	rm -f $TDIR/*
	rmdir $TDIR/

	return 0
}

# TODO: rewrite to convert (get some code from Korinf?)
__epm_check_if_try_install_rpm()
{
	local pkg
	local rpmpkgs=""
	for pkg in $@ ; do
		[ "$(get_package_type "$pkg")" = "rpm" ] || return 1
		[ -e "$pkg" ] || fatal "Can't read $pkg"
		rpmpkgs="$rpmpkgs $(realpath $pkg)"
	done
	[ -n "$rpmpkgs" ] || return 1

	assure_exists alien
320
	assure_exists fakeroot
321
	assure_exists rpm
322 323

	local TDIR=$(mktemp -d)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
324
	cd $TDIR || fatal
325
	for pkg in $rpmpkgs ; do
326 327 328
		showcmd_store_output fakeroot alien -d -k --scripts "$pkg"
		local DEBCONVERTED=$(grep "deb generated" $RC_STDOUT | sed -e "s| generated||g")
		clean_store_output
329
		docmd epm install $force $nodeps $DEBCONVERTED
330 331 332 333 334 335 336
	done
	rm -f $TDIR/*
	rmdir $TDIR/

	return 0
}

337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
__handle_direct_install()
{
    case "$DISTRNAME" in
        "ALTLinux")
            load_helper epm-download
            local pkg url
            for pkg in $pkg_names ; do
                url=$(__epm_get_altpkg_url $pkg)
                [ -n "$url" ] || continue
                # TODO: use estrlist
                pkg_urls="$pkg_urls $url"
            done
            # FIXME: need remove
            pkg_names=""
            ;;
    esac
}
354

355
epm_install_files()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
356
{
Danil Mikhailov's avatar
Danil Mikhailov committed
357
    [ -z "$1" ] && return
358

Vitaly Lipatov's avatar
Vitaly Lipatov committed
359 360 361 362
    # TODO: check read permissions
    # sudo test -r FILE
    # do not fallback to install_names if we have no permissions

363
    case $PMTYPE in
364
        apt-rpm)
365 366
            __epm_check_if_try_install_deb $@ && return

367 368 369
            # TODO: add --repack support, will force repack rpm

            # do not using low-level for install by file path (FIXME: reasons?)
370 371 372
            if ! is_dirpath "$@" || [ "$(get_package_type "$@")" = "rpm" ] ; then
                sudocmd rpm -Uvh $force $nodeps $@ && return
                local RES=$?
373
                # TODO: check rpm result code and convert it to compatible format if possible
374
                __epm_check_if_rpm_already_installed $@ && return
375

376
            # if run with --nodeps, do not fallback on hi level
377
            [ -n "$nodeps" ] && return $RES
378
            fi
379

380 381
            # use install_names
            ;;
382

Vitaly Lipatov's avatar
Vitaly Lipatov committed
383
        apt-dpkg|aptitude-dpkg)
384 385 386 387
            # the new version of the conf. file is installed with a .dpkg-dist suffix
            if [ -n "$non_interactive" ] ; then
                DPKGOPTIONS="--force-confdef --force-confold"
            fi
388 389 390

            __epm_check_if_try_install_rpm $@ && return

391
            # FIXME: return false in case no install and in case install with broken deps
392
            sudocmd dpkg $DPKGOPTIONS -i $@
393
            local RES=$?
394 395
            # if run with --nodeps, do not fallback on hi level

396
            [ -n "$nodeps" ] && return $RES
397
            # fall to apt-get -f install for fix deps
Vitaly Lipatov's avatar
Vitaly Lipatov committed
398 399
            # can't use APTOPTIONS with empty install args
            epm_install_names -f
400 401 402

            # repeat install for get correct status
            sudocmd dpkg $DPKGOPTIONS -i $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
403
            return
404
            ;;
405

406
        yum-rpm|dnf-rpm)
407 408
            __epm_check_if_try_install_deb $@ && return

409 410 411
            sudocmd rpm -Uvh $force $nodeps $@ && return
            # if run with --nodeps, do not fallback on hi level

412 413
            __epm_check_if_rpm_already_installed $@ && return

414 415 416 417
            [ -n "$nodeps" ] && return
            YUMOPTIONS=--nogpgcheck
            # use install_names
            ;;
418

419
        zypper-rpm)
420
            __epm_check_if_try_install_deb $@ && return
421
            sudocmd rpm -Uvh $force $nodeps $@ && return
422 423
            local RES=$?

424 425
            __epm_check_if_rpm_already_installed $@ && return

426 427
            # if run with --nodeps, do not fallback on hi level

428
            [ -n "$nodeps" ] && return $RES
429
            ZYPPEROPTIONS=$(__use_zypper_no_gpg_checks)
430 431
            # use install_names
            ;;
432

433
        urpm-rpm)
434
            __epm_check_if_try_install_deb $@ && return
435
            sudocmd rpm -Uvh $force $nodeps $@ && return
436 437
            local RES=$?

438 439
            __epm_check_if_rpm_already_installed $@ && return

440
            # if run with --nodeps, do not fallback on hi level
441
            [ -n "$nodeps" ] && return $RES
442 443

            URPMOPTIONS=--no-verify-rpm
444 445
            # use install_names
            ;;
446
        pkgsrc)
447
            sudocmd pkg_add $@
448
            return ;;
449 450 451 452 453 454 455 456 457 458 459
        pkgng)
            local PKGTYPE="$(get_package_type $@)"
            case "$PKGTYPE" in
                tbz)
                    sudocmd pkg_add $@
                    ;;
                *)
                    sudocmd pkg add $@
                    ;;
            esac
            return ;;
460 461 462
        android)
            sudocmd pm install $@
            return ;;
463
        emerge)
464 465
            load_helper epm-install-emerge
            sudocmd epm_install_emerge $@
466
            return ;;
467
        pacman)
468
            sudocmd pacman -U --noconfirm $force $nodeps $@ && return
469 470 471
            local RES=$?

            [ -n "$nodeps" ] && return $RES
472
            sudocmd pacman -U $force $@
473
            return ;;
474
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
475
            # FIXME: check for full package name
Vitaly Lipatov's avatar
Vitaly Lipatov committed
476
            # FIXME: broken status when use batch and default answer
477
            __separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $@
478
            return ;;
479 480
    esac

481
    # other systems can install file package via ordinary command
482
    epm_install_names "$@"
483 484
}

485 486
epm_print_install_command()
{
487 488 489
    # print out low level command by default (wait --low-level for control it)
    #[ -z "$1" ] && return
    [ -z "$1" ] && [ -n "$pkg_names" ] && return
490
    case $PMTYPE in
491
        apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
492
            echo "rpm -Uvh --force $nodeps $*"
493
            ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
494
        apt-dpkg|aptitude-dpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
495
            echo "dpkg -i $*"
496
            ;;
497
        pkgsrc)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
498
            echo "pkg_add $*"
499
            ;;
500
        pkgng)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
501
            echo "pkg add $*"
502
            ;;
503 504
        emerge)
            # need be placed in /usr/portage/packages/somewhere
Vitaly Lipatov's avatar
Vitaly Lipatov committed
505
            echo "emerge --usepkg $*"
506
            ;;
507
        pacman)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
508
            echo "pacman -U --noconfirm --force $nodeps $*"
509 510
            ;;
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
511
            echo "/sbin/installpkg $*"
512
            ;;
513
        npackd)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
514
            echo "npackdcl add --package=$*"
515
            ;;
516
        ipkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
517
            echo "ipkg install $*"
518
            ;;
519
        android)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
520
            echo "pm install $*"
521
            ;;
522
        aptcyg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
523
            echo "apt-cyg install $*"
524
            ;;
525
        tce)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
526
            echo "tce-load -wi $*"
527
            ;;
528
        xbps)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
529
            echo "xbps-install -y $*"
530
            ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
531 532
        homebrew)
            # FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
533
            echo "brew install $*"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
534
            ;;
535

536
        *)
537
            fatal "Have no suitable appropriate install command for $PMTYPE"
538 539 540 541
            ;;
    esac
}

542 543
epm_print_install_names_command()
{
544
	# check for pkg_files to support print out command without pkg names in args
545 546
	#[ -z "$1" ] && [ -n "$pkg_files" ] && return
	[ -z "$1" ] && return
547 548
	case $PMTYPE in
		apt-rpm|apt-dpkg)
549
			echo "apt-get -y --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS install $*"
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
			return ;;
		aptitude-dpkg)
			echo "aptitude -y install $*"
			return ;;
		yum-rpm)
			echo "yum -y $YUMOPTIONS install $*"
			return ;;
		dnf-rpm)
			echo "dnf -y $YUMOPTIONS install $*"
			return ;;
		urpm-rpm)
			echo "urpmi --auto $URPMOPTIONS $*"
			return ;;
		zypper-rpm)
			echo "zypper --non-interactive $ZYPPEROPTIONS install $*"
			return ;;
		pacman)
			echo "pacman -S --noconfirm $force $*"
			return ;;
		chocolatey)
			echo "chocolatey install $*"
			return ;;
		nix)
			echo "nix-env --install $*"
			return ;;
		*)
			fatal "Have no suitable appropriate install command for $PMTYPE"
			;;
	esac
}

581 582 583

epm_install()
{
584 585 586 587 588 589
    if tasknumber "$pkg_names" >/dev/null ; then
        assure_exists apt-repo
        sudocmd apt-repo test $(tasknumber "$pkg_names")
        return
    fi

590
    if [ -n "$show_command_only" ] ; then
591 592
        epm_print_install_command $pkg_files
        epm_print_install_names_command $pkg_names
593 594 595
        return
    fi

596 597 598 599
    if [ -n "$direct" ] ; then
        __handle_direct_install
    fi

600 601 602 603 604
    # if possible, it will put pkg_urls into pkg_files or pkg_names
    if [ -n "$pkg_urls" ] ; then
        load_helper epm-download
        __handle_pkg_urls_to_install
    fi
605

606
    [ -z "$pkg_files$pkg_names" ] && info "Skip empty install list" && return 22
607

608 609 610
    # to be filter happy
    warmup_lowbase

611
    local names="$(echo $pkg_names | exp_with_arch_suffix | filter_out_installed_packages)"
612
    local files="$(echo $pkg_files | filter_out_installed_packages)"
613

614 615 616 617 618 619
    # can be empty only after skip installed
    if [ -z "$files$names" ] ; then
        # TODO: assert $skip_installed
        [ -n "$verbose" ] && info "Skip empty install list"
        return 22
    fi
620

621
    if [ -z "$files" ] && [ -z "$direct" ] ; then
622 623 624
        # it is useful for first time running
        update_repo_if_needed
    fi
625

626
    epm_install_names $names || return
627
    epm_install_files $files
628
    local RETVAL=$?
629 630 631

    # TODO: reinvent
    [ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
632
    [ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
633

634
    return $RETVAL
Vitaly Lipatov's avatar
Vitaly Lipatov committed
635
}