epm-install 19.1 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
		eopkg)
			sudocmd eopkg $(subst_option nodeps --ignore-dependency) install $@
			return ;;
129 130 131
		conary)
			sudocmd conary update $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
132
		npackd)
133 134
			# FIXME: correct arg
			__separate_sudocmd_foreach "npackdcl add --package=" "npackdcl update --package=" $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
135
			return ;;
136
		slackpkg)
137
			__separate_sudocmd_foreach "/usr/sbin/slackpkg install" "/usr/sbin/slackpkg upgrade" $@
138 139
			return ;;
		homebrew)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
140
			# FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
141
			SUDO='' __separate_sudocmd "brew install" "brew upgrade" "$@"
142
			return ;;
143
		opkg)
144
			[ -n "$force" ] && force=-force-depends
145
			sudocmd opkg $force install $@
146
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
147
		nix)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
148
			__separate_sudocmd "nix-env --install" "nix-env --upgrade" "$@"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
149
			return ;;
150 151 152
		apk)
			sudocmd apk add $@
			return ;;
153 154 155
		tce)
			sudocmd tce-load -wi $@
			return ;;
156 157 158
		guix)
			__separate_sudocmd "guix package -i" "guix package -i" $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
159
		android)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
160
			fatal "We still have no idea how to use package repository, ever if it is F-Droid."
161
			return ;;
162 163 164
		aptcyg)
			sudocmd apt-cyg install $@
			return ;;
165 166 167
		xbps)
			sudocmd xbps-install $@
			return ;;
168 169 170
		appget|winget)
			sudocmd $PMTYPE install $@
			return ;;
171
		*)
172
			fatal "Have no suitable install command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
173
			;;
174 175 176
	esac
}

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

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

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

274 275
__handle_direct_install()
{
276 277
    case "$BASEDISTRNAME" in
        "alt")
278 279 280 281 282 283 284 285 286 287 288 289 290
            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
}
291

292 293 294 295 296 297 298 299 300
# 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
}

301 302 303 304 305
__epm_if_command_path()
{
    is_dirpath "$1" && rhas "$1" "bin/"
}

306
epm_install_files()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
307
{
308
    local files="$*"
309
    [ -z "$files" ] && return
310

Vitaly Lipatov's avatar
Vitaly Lipatov committed
311 312 313
    # TODO: check read permissions
    # sudo test -r FILE
    # do not fallback to install_names if we have no permissions
314 315
    case "$BASEDISTRNAME" in
        "alt")
Vitaly Lipatov's avatar
Vitaly Lipatov committed
316

317 318 319 320 321 322 323
            # 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
324 325 326 327 328 329
            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
330

331 332 333 334 335 336 337 338 339
            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
340

341
            # if run with --nodeps, do not fallback on hi level
342
            [ -n "$nodeps" ] && return $RES
343

344 345 346
            # separate second output
            info

347 348 349 350 351 352 353 354 355 356 357 358 359 360
            # 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
361
            ;;
362
    esac
363

364
    case $PMTYPE in
Vitaly Lipatov's avatar
Vitaly Lipatov committed
365
        apt-dpkg|aptitude-dpkg)
366 367 368 369
            # 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
370

371 372 373 374 375 376
            if __epm_repack_if_needed $files ; then
                [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
                files="$repacked_pkgs"
                # TODO
                #__epm_remove_tmp_files
            fi
377

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

380
            if [ -n "$nodeps" ] ; then
381
                sudocmd dpkg $DPKGOPTIONS -i $files
382 383
                return
            fi
384

385 386 387 388 389 390 391 392 393 394 395 396 397 398
            # for too old apt-get
            # TODO: check apt-get version?
            apt_can_install_files='1'
            if [ "$DISTRNAME" = "Ubuntu" ] ; then
                [ "$DISTRVERSION" = "14.04" ] && apt_can_install_files=''
                [ "$DISTRVERSION" = "12.04" ] && apt_can_install_files=''
            fi

            if [ -n "$apt_can_install_files" ] ; then
                # TODO: don't resolve fuzzy dependencies ()
                # are there apt that don't support dpkg files to install?
                epm_install_names $(make_filepath $files)
                return
            fi
399

400 401
            # old way:

402
            sudocmd dpkg $DPKGOPTIONS -i $files
403 404 405 406 407
            local RES=$?

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

408 409 410 411 412
            # 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
413 414

            # repeat install for get correct status
415
            sudocmd dpkg $DPKGOPTIONS -i $files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
416
            return
417
            ;;
418

419
       *-rpm)
420 421 422 423 424 425 426 427 428
            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
429 430
            local RES=$?

431
            __epm_check_if_rpm_already_installed $files && return
432

433
            # if run with --nodeps, do not fallback on hi level
434
            [ -n "$nodeps" ] && return $RES
435

436 437 438 439 440
            # fallback to install names

            # separate second output
            info

441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
            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
458
            ;;
459
        packagekit)
460
            docmd pkcon install-local $files
461
            return ;;
462
        pkgsrc)
463
            sudocmd pkg_add $files
464
            return ;;
465
        pkgng)
466
            local PKGTYPE="$(get_package_type $files)"
467 468
            case "$PKGTYPE" in
                tbz)
469
                    sudocmd pkg_add $files
470 471
                    ;;
                *)
472
                    sudocmd pkg add $files
473 474 475
                    ;;
            esac
            return ;;
476
        android)
477
            sudocmd pm install $files
478
            return ;;
479 480 481
        eopkg)
            sudocmd eopkg install $files
            return ;;
482
        emerge)
483
            load_helper epm-install-emerge
484
            sudocmd epm_install_emerge $files
485
            return ;;
486
        pacman)
487
            sudocmd pacman -U --noconfirm $nodeps $files && return
488 489 490
            local RES=$?

            [ -n "$nodeps" ] && return $RES
491
            sudocmd pacman -U $files
492
            return ;;
493
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
494
            # FIXME: check for full package name
Vitaly Lipatov's avatar
Vitaly Lipatov committed
495
            # FIXME: broken status when use batch and default answer
496
            __separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $files
497
            return ;;
498 499
    esac

500
    # other systems can install file package via ordinary command
501
    epm_install_names $files
502 503
}

504 505
epm_print_install_command()
{
506 507 508
    # print out low level command by default (wait --low-level for control it)
    #[ -z "$1" ] && return
    [ -z "$1" ] && [ -n "$pkg_names" ] && return
509
    case $PMTYPE in
510
        *-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
511
            echo "rpm -Uvh --force $nodeps $*"
512
            ;;
513
        *-dpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
514
            echo "dpkg -i $*"
515
            ;;
516
        pkgsrc)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
517
            echo "pkg_add $*"
518
            ;;
519
        pkgng)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
520
            echo "pkg add $*"
521
            ;;
522 523
        emerge)
            # need be placed in /usr/portage/packages/somewhere
Vitaly Lipatov's avatar
Vitaly Lipatov committed
524
            echo "emerge --usepkg $*"
525
            ;;
526
        pacman)
527
            echo "pacman -U --noconfirm $nodeps $*"
528 529
            ;;
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
530
            echo "/sbin/installpkg $*"
531
            ;;
532
        npackd)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
533
            echo "npackdcl add --package=$*"
534
            ;;
535 536
        opkg)
            echo "opkg install $*"
537
            ;;
538 539 540
        eopkg)
            echo "eopkg install $*"
            ;;
541
        android)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
542
            echo "pm install $*"
543
            ;;
544
        aptcyg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
545
            echo "apt-cyg install $*"
546
            ;;
547
        tce)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
548
            echo "tce-load -wi $*"
549
            ;;
550
        xbps)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
551
            echo "xbps-install -y $*"
552
            ;;
553 554 555
        appget|winget)
            echo "$PMTYPE install -s $*"
            ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
556 557
        homebrew)
            # FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
558
            echo "brew install $*"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
559
            ;;
560

561
        *)
562
            fatal "Have no suitable appropriate install command for $PMTYPE"
563 564 565 566
            ;;
    esac
}

567 568
epm_print_install_names_command()
{
569
	# check for pkg_files to support print out command without pkg names in args
570 571
	#[ -z "$1" ] && [ -n "$pkg_files" ] && return
	[ -z "$1" ] && return
572
	case $PMTYPE in
573 574 575 576 577
		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
578
			echo "apt-get -y --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS install $*"
579 580 581 582 583
			return ;;
		aptitude-dpkg)
			echo "aptitude -y install $*"
			return ;;
		yum-rpm)
584
			echo "yum -y $YUMOPTIONS install $*"
585 586
			return ;;
		dnf-rpm)
587
			echo "dnf -y $YUMOPTIONS --allowerasing install $*"
588 589 590 591 592 593 594
			return ;;
		urpm-rpm)
			echo "urpmi --auto $URPMOPTIONS $*"
			return ;;
		zypper-rpm)
			echo "zypper --non-interactive $ZYPPEROPTIONS install $*"
			return ;;
595
		packagekit)
596 597
			echo "pkcon --noninteractive $*"
			return ;;
598
		pacman)
599
			echo "pacman -S --noconfirm $*"
600 601 602 603 604 605 606
			return ;;
		chocolatey)
			echo "chocolatey install $*"
			return ;;
		nix)
			echo "nix-env --install $*"
			return ;;
607 608 609
		eopkg)
			echo "eopkg install $*"
			return ;;
610 611 612
		appget|winget)
			echo "$PMTYPE install $*"
			return ;;
613 614 615 616 617 618
		*)
			fatal "Have no suitable appropriate install command for $PMTYPE"
			;;
	esac
}

619 620 621

epm_install()
{
622
    if [ "$BASEDISTRNAME" = "alt" ] ; then
623 624
        if tasknumber "$pkg_names" >/dev/null ; then
            assure_exists apt-repo
Vitaly Lipatov's avatar
Vitaly Lipatov committed
625
            # TODO: add --auto support
626
            sudocmd_foreach "apt-repo test" $(tasknumber $pkg_names)
627 628
            return
        fi
629 630
    fi

631
    if [ -n "$show_command_only" ] ; then
632
        # TODO: handle pkg_urls too
633 634
        epm_print_install_command $pkg_files
        epm_print_install_names_command $pkg_names
635 636 637
        return
    fi

638 639 640 641 642 643
    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?
644
    if [ -n "$direct" ] && [ -z "$repack" ] ; then
645 646 647
        __handle_direct_install
    fi

648
    # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
649 650 651 652
    if [ -n "$pkg_urls" ] ; then
        load_helper epm-download
        __handle_pkg_urls_to_install
    fi
653

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

656 657 658
    # to be filter happy
    warmup_lowbase

659
    # Note: filter_out_installed_packages depends on skip_installed flag
660 661
    local names="$(echo $pkg_names | filter_out_installed_packages)"
    #local names="$(echo $pkg_names | exp_with_arch_suffix | filter_out_installed_packages)"
662
    local files="$(echo $pkg_files | filter_out_installed_packages)"
663

664 665 666
    # can be empty only after skip installed
    if [ -z "$files$names" ] ; then
        # TODO: assert $skip_installed
667
        [ -n "$verbose" ] && info "Skip empty install list (filtered out)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
668
        # FIXME: see to_remove below
669
        return 0
670
    fi
671

672
    if [ -z "$files" ] && [ -z "$direct" ] ; then
673 674 675
        # it is useful for first time running
        update_repo_if_needed
    fi
676

Vitaly Lipatov's avatar
Vitaly Lipatov committed
677
    # FIXME: see to_remove below
678
    epm_install_names $names || return
679 680 681

    # repack binary files
    if [ -n "$repack" ] ; then
682 683
        __epm_repack $files || return
        files="$repacked_pkgs"
684 685
    fi

686
    epm_install_files $files
687
    local RETVAL=$?
688

689
    __epm_remove_tmp_files
690

691
    return $RETVAL
Vitaly Lipatov's avatar
Vitaly Lipatov committed
692
}