epm-install 21.4 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 "$download_only" ] ; then
		epm download "$@"
		return
	fi

79 80 81 82 83
	if [ -n "$non_interactive" ] ; then
		epm_ni_install_names "$@"
		return
	fi

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

182
# Non interactive install
183 184
epm_ni_install_names()
{
Danil Mikhailov's avatar
Danil Mikhailov committed
185
	[ -z "$1" ] && return
186

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

273 274 275
__epm_check_if_rpm_already_installed()
{
	# Not: we can make optimize if just check version?
276
	LANG=C sudorun rpm -Uvh --test "$@" 2>&1 | grep -q "is already installed"
277 278
}

279 280
__handle_direct_install()
{
281 282
    case "$BASEDISTRNAME" in
        "alt")
283 284 285 286 287 288 289 290 291 292 293 294 295
            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
}
296

297 298 299 300 301 302 303 304 305
# 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
}

306 307 308 309 310
__epm_if_command_path()
{
    is_dirpath "$1" && rhas "$1" "bin/"
}

311
epm_install_files()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
312
{
313
    local files="$*"
314
    [ -z "$files" ] && return
315

Vitaly Lipatov's avatar
Vitaly Lipatov committed
316 317 318
    # TODO: check read permissions
    # sudo test -r FILE
    # do not fallback to install_names if we have no permissions
319 320
    case "$BASEDISTRNAME" in
        "alt")
Vitaly Lipatov's avatar
Vitaly Lipatov committed
321

322 323 324 325 326 327 328
            # 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
329 330 331 332 333
            if __epm_repack_if_needed $files ; then
                [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
                files="$repacked_pkgs"
            fi

334
            if [ -n "$save_only" ] ; then
335
                echo
336
                cp -v $files "$EPMCURDIR"
337 338 339
                return
            fi

340
            __epm_check_if_src_rpm $files
341

342 343 344 345 346
            if [ -z "$repacked_pkgs" ] ; then
                __epm_check_vendor $files
                __epm_check_if_needed_repack $files
            fi

347
            # --replacepkgs: Install the Package Even If Already Installed
348 349 350 351
            local replacepkgs='--replacepkgs'
            # don't use --replacepkgs when install only one file
            [ -f "$files" ] && replacepkgs=''
            sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && save_installed_packages $files && return
352 353
            local RES=$?
            # TODO: check rpm result code and convert it to compatible format if possible
354
            __epm_check_if_rpm_already_installed $force $replacepkgs $noscripts $nodeps $files && return
355

356
            # if run with --nodeps, do not fallback on hi level
357
            [ -n "$nodeps" ] && return $RES
358

359 360 361
            # separate second output
            info

362 363 364 365 366 367 368 369 370
            # 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
371
                # --replacepkgs: Install the Package Even If Already Installed
372 373 374 375
                local replacepkgs='--replacepkgs'
                # don't use --replacepkgs when install only one file
                [ -f "$files" ] && replacepkgs=''
                sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && save_installed_packages $files
376 377 378
                return
            fi

379 380
            epm_install_names $files
            return
381
            ;;
382
    esac
383

384
    case $PMTYPE in
Vitaly Lipatov's avatar
Vitaly Lipatov committed
385
        apt-dpkg|aptitude-dpkg)
386 387 388 389
            # 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
390

391 392 393 394 395 396
            if __epm_repack_if_needed $files ; then
                [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
                files="$repacked_pkgs"
                # TODO
                #__epm_remove_tmp_files
            fi
397

398
            if [ -n "$save_only" ] ; then
399
                echo
400
                cp -v $files "$EPMCURDIR"
401 402 403
                return
            fi

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

406
            if [ -n "$nodeps" ] ; then
407
                sudocmd dpkg $DPKGOPTIONS -i $files
408 409
                return
            fi
410

411 412 413 414 415 416 417 418 419 420 421 422 423 424
            # 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
425

426 427
            # old way:

428
            sudocmd dpkg $DPKGOPTIONS -i $files
429 430 431 432 433
            local RES=$?

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

434 435 436 437 438
            # 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
439 440

            # repeat install for get correct status
441
            sudocmd dpkg $DPKGOPTIONS -i $files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
442
            return
443
            ;;
444

445
       *-rpm)
446 447 448 449 450 451 452
            if __epm_repack_if_needed $files ; then
                [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
                files="$repacked_pkgs"
                # TODO
                #__epm_remove_tmp_files
            fi

453
            if [ -n "$save_only" ] ; then
454
                echo
455
                cp -v $files "$EPMCURDIR"
456 457 458
                return
            fi

459
            __epm_check_if_src_rpm $files
460

461
            # --replacepkgs: Install the Package Even If Already Installed
462 463 464 465
            local replacepkgs='--replacepkgs'
            # don't use --replacepkgs when install only one file
            [ -f "$files" ] && replacepkgs=''
            sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && return
466 467
            local RES=$?

468
            __epm_check_if_rpm_already_installed $force $replacepkgs $noscripts $nodeps $files && return
469

470
            # if run with --nodeps, do not fallback on hi level
471
            [ -n "$nodeps" ] && return $RES
472

473 474 475 476 477
            # fallback to install names

            # separate second output
            info

478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
            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
495 496 497

            epm_install_names $files
            return
498
            ;;
499 500 501
    esac


502 503
    # check save_only before commands without repack supporting
    if [ -n "$save_only" ] ; then
504
        echo
505
        cp -v $files "$EPMCURDIR"
506 507 508 509
        return
    fi


510
    case $PMTYPE in
511
        packagekit)
512
            docmd pkcon install-local $files
513
            return ;;
514
        pkgsrc)
515
            sudocmd pkg_add $files
516
            return ;;
517
        pkgng)
518
            local PKGTYPE="$(get_package_type $files)"
519 520
            case "$PKGTYPE" in
                tbz)
521
                    sudocmd pkg_add $files
522 523
                    ;;
                *)
524
                    sudocmd pkg add $files
525 526 527
                    ;;
            esac
            return ;;
528
        android)
529
            sudocmd pm install $files
530
            return ;;
531 532 533
        eopkg)
            sudocmd eopkg install $files
            return ;;
534
        emerge)
535
            load_helper epm-install-emerge
536
            sudocmd epm_install_emerge $files
537
            return ;;
538
        pacman)
539
            sudocmd pacman -U --noconfirm $nodeps $files && return
540 541 542
            local RES=$?

            [ -n "$nodeps" ] && return $RES
543
            sudocmd pacman -U $files
544
            return ;;
545
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
546
            # FIXME: check for full package name
Vitaly Lipatov's avatar
Vitaly Lipatov committed
547
            # FIXME: broken status when use batch and default answer
548
            __separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $files
549
            return ;;
550 551
    esac

552
    # other systems can install file package via ordinary command
553
    epm_install_names $files
554 555
}

556 557
epm_print_install_command()
{
558 559 560
    # print out low level command by default (wait --low-level for control it)
    #[ -z "$1" ] && return
    [ -z "$1" ] && [ -n "$pkg_names" ] && return
561
    case $PMTYPE in
562
        *-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
563
            echo "rpm -Uvh --force $nodeps $*"
564
            ;;
565
        *-dpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
566
            echo "dpkg -i $*"
567
            ;;
568
        pkgsrc)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
569
            echo "pkg_add $*"
570
            ;;
571
        pkgng)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
572
            echo "pkg add $*"
573
            ;;
574 575
        emerge)
            # need be placed in /usr/portage/packages/somewhere
Vitaly Lipatov's avatar
Vitaly Lipatov committed
576
            echo "emerge --usepkg $*"
577
            ;;
578
        pacman)
579
            echo "pacman -U --noconfirm $nodeps $*"
580 581
            ;;
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
582
            echo "/sbin/installpkg $*"
583
            ;;
584
        npackd)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
585
            echo "npackdcl add --package=$*"
586
            ;;
587 588
        opkg)
            echo "opkg install $*"
589
            ;;
590 591 592
        eopkg)
            echo "eopkg install $*"
            ;;
593
        android)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
594
            echo "pm install $*"
595
            ;;
596
        aptcyg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
597
            echo "apt-cyg install $*"
598
            ;;
599
        tce)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
600
            echo "tce-load -wi $*"
601
            ;;
602
        xbps)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
603
            echo "xbps-install -y $*"
604
            ;;
605 606 607
        appget|winget)
            echo "$PMTYPE install -s $*"
            ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
608 609
        homebrew)
            # FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
610
            echo "brew install $*"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
611
            ;;
612

613
        *)
614
            fatal "Have no suitable appropriate install command for $PMTYPE"
615 616 617 618
            ;;
    esac
}

619 620
epm_print_install_names_command()
{
621
	# check for pkg_files to support print out command without pkg names in args
622 623
	#[ -z "$1" ] && [ -n "$pkg_files" ] && return
	[ -z "$1" ] && return
624
	case $PMTYPE in
625 626 627 628 629
		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
630
			echo "apt-get -y --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS install $*"
631 632 633 634 635
			return ;;
		aptitude-dpkg)
			echo "aptitude -y install $*"
			return ;;
		yum-rpm)
636
			echo "yum -y $YUMOPTIONS install $*"
637 638
			return ;;
		dnf-rpm)
639
			echo "dnf -y $YUMOPTIONS --allowerasing install $*"
640 641 642 643 644 645 646
			return ;;
		urpm-rpm)
			echo "urpmi --auto $URPMOPTIONS $*"
			return ;;
		zypper-rpm)
			echo "zypper --non-interactive $ZYPPEROPTIONS install $*"
			return ;;
647
		packagekit)
648 649
			echo "pkcon --noninteractive $*"
			return ;;
650
		pacman)
651
			echo "pacman -S --noconfirm $*"
652 653 654 655 656 657 658
			return ;;
		chocolatey)
			echo "chocolatey install $*"
			return ;;
		nix)
			echo "nix-env --install $*"
			return ;;
659 660 661
		eopkg)
			echo "eopkg install $*"
			return ;;
662 663 664
		appget|winget)
			echo "$PMTYPE install $*"
			return ;;
665 666 667 668 669 670
		*)
			fatal "Have no suitable appropriate install command for $PMTYPE"
			;;
	esac
}

671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
# apt-repo with non_interactive support
apt_repo_prepare()
{
    assure_exists apt-repo
    [ -n "$non_interactive" ] || return

    set_sudo
    trap "$SUDO rm /etc/apt/apt.conf.d/eepm-apt-noninteractive.conf 2>/dev/null" EXIT
    echo 'APT::Get::Assume-Yes "true";' | $SUDO tee /etc/apt/apt.conf.d/eepm-apt-noninteractive.conf >/dev/null
}

apt_repo_after()
{
    [ -n "$non_interactive" ] || return

    $SUDO rm /etc/apt/apt.conf.d/eepm-apt-noninteractive.conf 2>/dev/null
}
688 689 690

epm_install()
{
691
    if [ "$BASEDISTRNAME" = "alt" ] ; then
692
        if tasknumber "$pkg_names" >/dev/null ; then
693 694 695
            local res
            # TODO: don't use apt-repo
            apt_repo_prepare
696
            sudocmd_foreach "apt-repo test" $(tasknumber $pkg_names)
697 698 699
            res=$?
            apt_repo_after
            return $res
700
        fi
701 702
    fi

703
    if [ -n "$show_command_only" ] ; then
704
        # TODO: handle pkg_urls too
705 706
        epm_print_install_command $pkg_files
        epm_print_install_names_command $pkg_names
707 708 709
        return
    fi

710 711 712 713 714 715
    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?
716
    if [ -n "$direct" ] && [ -z "$repack" ] ; then
717 718 719
        __handle_direct_install
    fi

720
    # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
721 722 723 724
    if [ -n "$pkg_urls" ] ; then
        load_helper epm-download
        __handle_pkg_urls_to_install
    fi
725

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

728 729 730
    # to be filter happy
    warmup_lowbase

731
    # Note: filter_out_installed_packages depends on skip_installed flag
732 733
    local names="$(echo $pkg_names | filter_out_installed_packages)"
    #local names="$(echo $pkg_names | exp_with_arch_suffix | filter_out_installed_packages)"
734
    local files="$(echo $pkg_files | filter_out_installed_packages)"
735

736 737 738
    # can be empty only after skip installed
    if [ -z "$files$names" ] ; then
        # TODO: assert $skip_installed
739
        [ -n "$verbose" ] && info "Skip empty install list (filtered out)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
740
        # FIXME: see to_remove below
741
        return 0
742
    fi
743

744
    if [ -z "$files" ] && [ -z "$direct" ] ; then
745 746 747
        # it is useful for first time running
        update_repo_if_needed
    fi
748

Vitaly Lipatov's avatar
Vitaly Lipatov committed
749
    # FIXME: see to_remove below
750
    epm_install_names $names || return
751

752
    # save files before install and repack
753
    if [ -n "$download_only" ] && [ -n "$files" ] ; then
754
        echo
755
        cp -v $files "$EPMCURDIR"
756 757 758
        return
    fi

759 760
    # repack binary files
    if [ -n "$repack" ] ; then
761 762
        __epm_repack $files || return
        files="$repacked_pkgs"
763 764
    fi

765
    epm_install_files $files
766
    local RETVAL=$?
767

768
    __epm_remove_tmp_files
769

770
    return $RETVAL
Vitaly Lipatov's avatar
Vitaly Lipatov committed
771
}