epm-install 18.2 KB
Newer Older
Vitaly Lipatov's avatar
Vitaly Lipatov committed
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012-2020  Etersoft
# Copyright (C) 2012-2020  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-sh-install
22
load_helper epm-query
23
load_helper epm-assure
24
load_helper epm-repack
25
load_helper epm-check_updated_repo
26
load_helper epm-sh-warmup
27

28

29 30 31
# for zypper before SUSE/11.0
__use_zypper_no_gpg_checks()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
32
    a='' zypper install --help 2>&1 | grep -q -- "--no-gpg-checks" && echo "--no-gpg-checks"
33
}
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
# 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
59
        sudocmd $cmd_re $pkg_noninstalled || return
60 61
    fi
    if [ -n "$pkg_installed" ] ; then
62
        sudocmd $cmd_in $pkg_installed || return
63 64 65 66
    fi
    return 0
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
67
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
68
epm_install_names()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
69
{
70 71 72 73
	[ -z "$1" ] && return

	warmup_hibase

74 75 76 77 78
	if [ -n "$non_interactive" ] ; then
		epm_ni_install_names "$@"
		return
	fi

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

174
# Non interactive install
175 176
epm_ni_install_names()
{
Danil Mikhailov's avatar
Danil Mikhailov committed
177
	[ -z "$1" ] && return
178

179
	case $PMTYPE in
180 181 182 183
		apt-rpm)
			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 $@
			return ;;
		apt-dpkg)
184
			sudocmd env ACCEPT_EULA=y DEBIAN_FRONTEND=noninteractive 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 $@
185
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
186
		aptitude-dpkg)
187
			sudocmd env ACCEPT_EULA=y DEBIAN_FRONTEND=noninteractive aptitude -y install $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
188
			return ;;
189
		yum-rpm)
190
			sudocmd yum -y $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
191
			return ;;
192
		dnf-rpm)
193
			sudocmd dnf -y --allowerasing $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
194
			return ;;
195
		urpm-rpm)
196
			sudocmd urpmi --auto $URPMOPTIONS $@
197 198
			return ;;
		zypper-rpm)
199
			# FIXME: returns true ever no package found, need check for "no found", "Nothing to do."
200
			yes | sudocmd zypper --non-interactive $ZYPPEROPTIONS install $@
201
			return ;;
202
		packagekit)
203 204
			docmd pkcon install --noninteractive $@
			return ;;
205
		pkgsrc)
206
			sudocmd pkg_add -r $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
207
			return ;;
208 209 210
		pkgng)
			sudocmd pkg install -y $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
211 212 213
		emerge)
			sudocmd emerge -uD $@
			return ;;
214
		pacman)
215
			sudocmd pacman -S --noconfirm $nodeps $@
216
			return ;;
217 218 219
		aura)
			sudocmd aura -A $force $nodeps $@
			return ;;
220 221
		npackd)
			#  npackdcl update --package=<package> (remove old and install new)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
222
			sudocmd npackdcl add --package="$*"
223
			return ;;
224 225 226
		chocolatey)
			docmd chocolatey install $@
			return ;;
227 228
		opkg)
			sudocmd opkg -force-defaults install $@
229
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
230 231 232
		nix)
			sudocmd nix-env --install $@
			return ;;
233 234 235
		apk)
			sudocmd apk add $@
			return ;;
236 237 238
		tce)
			sudocmd tce-load -wi $@
			return ;;
239 240 241
		xbps)
			sudocmd xbps-install -y $@
			return ;;
242 243 244
		appget|winget)
			sudocmd $PMTYPE -s install $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
245 246
		homebrew)
			# FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
247
			SUDO='' __separate_sudocmd "brew install" "brew upgrade" $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
248
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
249 250 251
		#android)
		#	sudocmd pm install $@
		#	return ;;
252
		slackpkg)
253
			# FIXME: broken status when use batch and default answer
254
			__separate_sudocmd_foreach "/usr/sbin/slackpkg -batch=on -default_answer=yes install" "/usr/sbin/slackpkg -batch=on -default_answer=yes upgrade" $@
255
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
256
		*)
257
			fatal "Have no suitable appropriate install command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
258 259 260 261
			;;
	esac
}

262 263 264
__epm_check_if_rpm_already_installed()
{
	# Not: we can make optimize if just check version?
265
	LANG=C sudorun rpm -Uvh $force $nodeps $@ 2>&1 | grep -q "is already installed"
266 267
}

268 269 270
__handle_direct_install()
{
    case "$DISTRNAME" in
271
        ALTLinux|ALTServer)
272 273 274 275 276 277 278 279 280 281 282 283 284
            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
}
285

286 287 288 289 290 291 292 293 294
# TODO: forbid src.rpm
__epm_check_if_src_rpm()
{
    local pkg
    for pkg in $@ ; do
        echo "$pkg" | grep -q "\.src.\rpm" && fatal "Installation of a source packages (like '$pkg') is not supported."
    done
}

295 296 297 298 299
__epm_if_command_path()
{
    is_dirpath "$1" && rhas "$1" "bin/"
}

300
epm_install_files()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
301
{
302
    local files="$*"
303
    [ -z "$files" ] && return
304

Vitaly Lipatov's avatar
Vitaly Lipatov committed
305 306 307
    # TODO: check read permissions
    # sudo test -r FILE
    # do not fallback to install_names if we have no permissions
308
    case "$DISTRNAME" in
309
        ALTLinux|ALTServer)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
310

311 312 313 314 315 316 317
            # do not use low-level for install by file path (f.i. epm install /usr/bin/git)
            if __epm_if_command_path $files ; then
                epm_install_names $files
                return
            fi

            # on ALT install target can be a real path
318 319 320 321 322 323
            if __epm_repack_if_needed $files ; then
                [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
                files="$repacked_pkgs"
            fi

            __epm_check_if_src_rpm $files
324

325 326 327 328 329 330 331 332 333
            if [ -z "$repacked_pkgs" ] ; then
                __epm_check_vendor $files
                __epm_check_if_needed_repack $files
            fi

            sudocmd rpm -Uvh $force $noscripts $nodeps $files && save_installed_packages $files && return
            local RES=$?
            # TODO: check rpm result code and convert it to compatible format if possible
            __epm_check_if_rpm_already_installed $files && return
334

335
            # if run with --nodeps, do not fallback on hi level
336
            [ -n "$nodeps" ] && return $RES
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351

            # try install via apt if we could't install package file via rpm (we guess we need install requirements firsly)

            # TODO: use it always (apt can install version from repo instead of a file package)
            if [ -n "$noscripts" ] ; then
                info "Workaround for install packages via apt with --noscripts (see https://bugzilla.altlinux.org/44670)"
                info "Firstly install package requrements …"
                # TODO: can we install only requires via apt?
                epm install $(epm req --short $files) || return
                # retry with rpm
                sudocmd rpm -Uvh $force $noscripts $nodeps $files && save_installed_packages $files
                return
            fi

            # common fallback
352
            ;;
353
    esac
354

355
    case $PMTYPE in
Vitaly Lipatov's avatar
Vitaly Lipatov committed
356
        apt-dpkg|aptitude-dpkg)
357 358 359 360
            # 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
361

362 363 364 365 366 367
            if __epm_repack_if_needed $files ; then
                [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
                files="$repacked_pkgs"
                # TODO
                #__epm_remove_tmp_files
            fi
368

369
            # TODO: if dpkg can't install due missed deps, trying with apt (as for now, --refuse-depends, --refuse-breaks don't help me)
370

371
            if [ -n "$nodeps" ] ; then
372
                sudocmd dpkg $DPKGOPTIONS -i $files
373 374
                return
            fi
375

376
            # TODO: don't resolve fuzzy dependencies ()
377
            # are there apt that don't support dpkg files to install?
378
            epm_install_names $(make_filepath $files)
379
            return
380

381 382
            # old way:

383
            sudocmd dpkg $DPKGOPTIONS -i $files
384 385 386 387 388
            local RES=$?

            # return OK if all is OK
            [ "$RES" = "0" ] && return $RES

389 390 391 392 393
            # TODO: workaround with epm-check needed only for very old apt

            # run apt -f install if there are were some errors during install
            load_helper epm-check
            epm_check
394 395

            # repeat install for get correct status
396
            sudocmd dpkg $DPKGOPTIONS -i $files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
397
            return
398
            ;;
399

400
       *-rpm)
401 402 403 404 405 406 407 408 409
            if __epm_repack_if_needed $files ; then
                [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
                files="$repacked_pkgs"
                # TODO
                #__epm_remove_tmp_files
            fi

            __epm_check_if_src_rpm $files
            sudocmd rpm -Uvh $force $noscripts $nodeps $files && return
410 411
            local RES=$?

412
            __epm_check_if_rpm_already_installed $files && return
413

414
            # if run with --nodeps, do not fallback on hi level
415
            [ -n "$nodeps" ] && return $RES
416

417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
            case $PMTYPE in
                yum-rpm|dnf-rpm)
                    YUMOPTIONS=--nogpgcheck
                    # use install_names
                    ;;
                zypper-rpm)
                    ZYPPEROPTIONS=$(__use_zypper_no_gpg_checks)
                    # use install_names
                    ;;
                urpm-rpm)
                    URPMOPTIONS=--no-verify-rpm
                    # use install_names
                    ;;
                *)
                    # use install_names
                    ;;
            esac
434
            ;;
435
        packagekit)
436
            docmd pkcon install-local $files
437
            return ;;
438
        pkgsrc)
439
            sudocmd pkg_add $files
440
            return ;;
441
        pkgng)
442
            local PKGTYPE="$(get_package_type $files)"
443 444
            case "$PKGTYPE" in
                tbz)
445
                    sudocmd pkg_add $files
446 447
                    ;;
                *)
448
                    sudocmd pkg add $files
449 450 451
                    ;;
            esac
            return ;;
452
        android)
453
            sudocmd pm install $files
454
            return ;;
455
        emerge)
456
            load_helper epm-install-emerge
457
            sudocmd epm_install_emerge $files
458
            return ;;
459
        pacman)
460
            sudocmd pacman -U --noconfirm $nodeps $files && return
461 462 463
            local RES=$?

            [ -n "$nodeps" ] && return $RES
464
            sudocmd pacman -U $files
465
            return ;;
466
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
467
            # FIXME: check for full package name
Vitaly Lipatov's avatar
Vitaly Lipatov committed
468
            # FIXME: broken status when use batch and default answer
469
            __separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $files
470
            return ;;
471 472
    esac

473
    # other systems can install file package via ordinary command
474
    epm_install_names $files
475 476
}

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

531
        *)
532
            fatal "Have no suitable appropriate install command for $PMTYPE"
533 534 535 536
            ;;
    esac
}

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

586 587 588

epm_install()
{
589
    if [ "$DISTRNAME" = "ALTLinux" ] || [ "$DISTRNAME" = "ALTServer" ] ; then
590 591
        if tasknumber "$pkg_names" >/dev/null ; then
            assure_exists apt-repo
Vitaly Lipatov's avatar
Vitaly Lipatov committed
592
            # TODO: add --auto support
593
            sudocmd_foreach "apt-repo test" $(tasknumber $pkg_names)
594 595
            return
        fi
596 597
    fi

598
    if [ -n "$show_command_only" ] ; then
599
        # TODO: handle pkg_urls too
600 601
        epm_print_install_command $pkg_files
        epm_print_install_names_command $pkg_names
602 603 604
        return
    fi

605 606 607 608 609 610
    if [ -n "$interactive" ] ; then
        confirm_info "You are about to install $pkg_names $pkg_files $pkg_urls package(s)."
        # TODO: for some packages with dependencies apt will ask later again
    fi

    # TODO: put it after empty install list checking?
611
    if [ -n "$direct" ] && [ -z "$repack" ] ; then
612 613 614
        __handle_direct_install
    fi

615
    # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
616 617 618 619
    if [ -n "$pkg_urls" ] ; then
        load_helper epm-download
        __handle_pkg_urls_to_install
    fi
620

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

623 624 625
    # to be filter happy
    warmup_lowbase

626
    # Note: filter_out_installed_packages depends on skip_installed flag
627 628
    local names="$(echo $pkg_names | filter_out_installed_packages)"
    #local names="$(echo $pkg_names | exp_with_arch_suffix | filter_out_installed_packages)"
629
    local files="$(echo $pkg_files | filter_out_installed_packages)"
630

631 632 633
    # can be empty only after skip installed
    if [ -z "$files$names" ] ; then
        # TODO: assert $skip_installed
634
        [ -n "$verbose" ] && info "Skip empty install list (filtered out)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
635
        # FIXME: see to_remove below
636
        return 0
637
    fi
638

639
    if [ -z "$files" ] && [ -z "$direct" ] ; then
640 641 642
        # it is useful for first time running
        update_repo_if_needed
    fi
643

Vitaly Lipatov's avatar
Vitaly Lipatov committed
644
    # FIXME: see to_remove below
645
    epm_install_names $names || return
646 647 648

    # repack binary files
    if [ -n "$repack" ] ; then
649 650
        __epm_repack $files || return
        files="$repacked_pkgs"
651 652
    fi

653
    epm_install_files $files
654
    local RETVAL=$?
655

656
    __epm_remove_tmp_files
657

658
    return $RETVAL
Vitaly Lipatov's avatar
Vitaly Lipatov committed
659
}