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

27 28 29 30 31 32
__fast_hack_for_filter_out_installed_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'
}

33 34 35 36 37
# TODO: use when run install with epm --skip-installed install
filter_out_installed_packages()
{
	[ -z "$skip_installed" ] && cat && return

38 39 40 41 42 43 44
	case $PMTYPE in
		yum-rpm|dnf-rpm)
			if [ "$($DISTRVENDOR -a)" = "x86_64" ] ; then
				# shellcheck disable=SC2013
				for i in $(cat) ; do
					is_installed "$(__print_with_arch_suffix $i .x86_64)" && continue
					is_installed "$(__print_with_arch_suffix $i .noarch)" && continue
45
					echo $i
46 47 48 49 50 51 52
				done
			else
				__fast_hack_for_filter_out_installed_rpm
			fi
			;;
		*-rpm)
			__fast_hack_for_filter_out_installed_rpm
53
			;;
54 55 56 57 58
		# 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'
		#	;;
59
		*)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
60
			# shellcheck disable=SC2013
61 62 63
			for i in $(cat) ; do
				is_installed $i || echo $i
			done
64
			;;
65
	esac | sed -e "s|rpm-build-altlinux-compat[^ ]*||g" | filter_strip_spaces
66 67
}

68 69 70
# for zypper before SUSE/11.0
__use_zypper_no_gpg_checks()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
71
    a='' zypper install --help 2>&1 | grep -q -- "--no-gpg-checks" && echo "--no-gpg-checks"
72
}
73

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
# 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
106
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
107
epm_install_names()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
108
{
109 110 111 112
	[ -z "$1" ] && return

	warmup_hibase

113 114 115 116 117
	if [ -n "$non_interactive" ] ; then
		epm_ni_install_names "$@"
		return
	fi

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

207
# Non interactive install
208 209
epm_ni_install_names()
{
Danil Mikhailov's avatar
Danil Mikhailov committed
210
	[ -z "$1" ] && return
211

212
	case $PMTYPE in
213
		apt-rpm|apt-dpkg)
214
			export DEBIAN_FRONTEND=noninteractive
215
			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 $@
216
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
217
		aptitude-dpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
218
			sudocmd aptitude -y install $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
219
			return ;;
220
		yum-rpm)
221
			sudocmd yum -y $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
222
			return ;;
223
		dnf-rpm)
224
			sudocmd dnf -y $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
225
			return ;;
226
		urpm-rpm)
227
			sudocmd urpmi --auto $URPMOPTIONS $@
228 229
			return ;;
		zypper-rpm)
230
			# FIXME: returns true ever no package found, need check for "no found", "Nothing to do."
231
			yes | sudocmd zypper --non-interactive $ZYPPEROPTIONS install $@
232
			return ;;
233
		pkgsrc)
234
			sudocmd pkg_add -r $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
235
			return ;;
236 237 238
		pkgng)
			sudocmd pkg install -y $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
239 240 241
		emerge)
			sudocmd emerge -uD $@
			return ;;
242
		pacman)
243
			sudocmd pacman -S --noconfirm $force $nodeps $@
244
			return ;;
245 246 247
		aura)
			sudocmd aura -A $force $nodeps $@
			return ;;
248 249
		npackd)
			#  npackdcl update --package=<package> (remove old and install new)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
250
			sudocmd npackdcl add --package="$*"
251
			return ;;
252 253 254
		chocolatey)
			docmd chocolatey install $@
			return ;;
255 256
		opkg)
			sudocmd opkg -force-defaults install $@
257
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
258 259 260
		nix)
			sudocmd nix-env --install $@
			return ;;
261 262 263
		apk)
			sudocmd apk add $@
			return ;;
264 265 266
		tce)
			sudocmd tce-load -wi $@
			return ;;
267 268 269
		xbps)
			sudocmd xbps-install -y $@
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
270 271
		homebrew)
			# FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
272
			SUDO='' __separate_sudocmd "brew install" "brew upgrade" $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
273
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
274 275 276
		#android)
		#	sudocmd pm install $@
		#	return ;;
277
		slackpkg)
278
			# FIXME: broken status when use batch and default answer
279
			__separate_sudocmd_foreach "/usr/sbin/slackpkg -batch=on -default_answer=yes install" "/usr/sbin/slackpkg -batch=on -default_answer=yes upgrade" $@
280
			return ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
281
		*)
282
			fatal "Have no suitable appropriate install command for $PMTYPE"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
283 284 285 286
			;;
	esac
}

287 288 289 290 291 292
__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"
}

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
__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
}
310

311
epm_install_files()
Vitaly Lipatov's avatar
Vitaly Lipatov committed
312
{
Danil Mikhailov's avatar
Danil Mikhailov committed
313
    [ -z "$1" ] && return
314

Vitaly Lipatov's avatar
Vitaly Lipatov committed
315 316 317 318
    # TODO: check read permissions
    # sudo test -r FILE
    # do not fallback to install_names if we have no permissions

319
    case $PMTYPE in
320
        apt-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
321
            # TODO: replace with name changed function
322 323
            __epm_check_if_try_install_deb $@ && return

324
            # do not using low-level for install by file path (FIXME: reasons?)
325
            if ! is_dirpath "$@" || [ "$(get_package_type "$@")" = "rpm" ] ; then
326
                sudocmd rpm -Uvh $force $nodeps $@ && save_installed_packages $@ && return
327
                local RES=$?
328
                # TODO: check rpm result code and convert it to compatible format if possible
329
                __epm_check_if_rpm_already_installed $@ && return
330

331
            # if run with --nodeps, do not fallback on hi level
332
            [ -n "$nodeps" ] && return $RES
333
            fi
334

335 336
            # use install_names
            ;;
337

Vitaly Lipatov's avatar
Vitaly Lipatov committed
338
        apt-dpkg|aptitude-dpkg)
339 340 341 342
            # 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
343 344 345

            __epm_check_if_try_install_rpm $@ && return

346
            # FIXME: return false in case no install and in case install with broken deps
347
            sudocmd dpkg $DPKGOPTIONS -i $@
348
            local RES=$?
349 350
            # if run with --nodeps, do not fallback on hi level

351
            [ -n "$nodeps" ] && return $RES
352
            # fall to apt-get -f install for fix deps
Vitaly Lipatov's avatar
Vitaly Lipatov committed
353 354
            # can't use APTOPTIONS with empty install args
            epm_install_names -f
355 356 357

            # repeat install for get correct status
            sudocmd dpkg $DPKGOPTIONS -i $@
Vitaly Lipatov's avatar
Vitaly Lipatov committed
358
            return
359
            ;;
360

361
        yum-rpm|dnf-rpm)
362 363
            __epm_check_if_try_install_deb $@ && return

364 365 366
            sudocmd rpm -Uvh $force $nodeps $@ && return
            # if run with --nodeps, do not fallback on hi level

367 368
            __epm_check_if_rpm_already_installed $@ && return

369 370 371 372
            [ -n "$nodeps" ] && return
            YUMOPTIONS=--nogpgcheck
            # use install_names
            ;;
373

374
        zypper-rpm)
375
            __epm_check_if_try_install_deb $@ && return
376
            sudocmd rpm -Uvh $force $nodeps $@ && return
377 378
            local RES=$?

379 380
            __epm_check_if_rpm_already_installed $@ && return

381 382
            # if run with --nodeps, do not fallback on hi level

383
            [ -n "$nodeps" ] && return $RES
384
            ZYPPEROPTIONS=$(__use_zypper_no_gpg_checks)
385 386
            # use install_names
            ;;
387

388
        urpm-rpm)
389
            __epm_check_if_try_install_deb $@ && return
390
            sudocmd rpm -Uvh $force $nodeps $@ && return
391 392
            local RES=$?

393 394
            __epm_check_if_rpm_already_installed $@ && return

395
            # if run with --nodeps, do not fallback on hi level
396
            [ -n "$nodeps" ] && return $RES
397 398

            URPMOPTIONS=--no-verify-rpm
399 400
            # use install_names
            ;;
401
        pkgsrc)
402
            sudocmd pkg_add $@
403
            return ;;
404 405 406 407 408 409 410 411 412 413 414
        pkgng)
            local PKGTYPE="$(get_package_type $@)"
            case "$PKGTYPE" in
                tbz)
                    sudocmd pkg_add $@
                    ;;
                *)
                    sudocmd pkg add $@
                    ;;
            esac
            return ;;
415 416 417
        android)
            sudocmd pm install $@
            return ;;
418
        emerge)
419 420
            load_helper epm-install-emerge
            sudocmd epm_install_emerge $@
421
            return ;;
422
        pacman)
423
            sudocmd pacman -U --noconfirm $force $nodeps $@ && return
424 425 426
            local RES=$?

            [ -n "$nodeps" ] && return $RES
427
            sudocmd pacman -U $force $@
428
            return ;;
429
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
430
            # FIXME: check for full package name
Vitaly Lipatov's avatar
Vitaly Lipatov committed
431
            # FIXME: broken status when use batch and default answer
432
            __separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $@
433
            return ;;
434 435
    esac

436
    # other systems can install file package via ordinary command
437
    epm_install_names "$@"
438 439
}

440 441
epm_print_install_command()
{
442 443 444
    # print out low level command by default (wait --low-level for control it)
    #[ -z "$1" ] && return
    [ -z "$1" ] && [ -n "$pkg_names" ] && return
445
    case $PMTYPE in
446
        apt-rpm|yum-rpm|urpm-rpm|zypper-rpm|dnf-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
447
            echo "rpm -Uvh --force $nodeps $*"
448
            ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
449
        apt-dpkg|aptitude-dpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
450
            echo "dpkg -i $*"
451
            ;;
452
        pkgsrc)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
453
            echo "pkg_add $*"
454
            ;;
455
        pkgng)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
456
            echo "pkg add $*"
457
            ;;
458 459
        emerge)
            # need be placed in /usr/portage/packages/somewhere
Vitaly Lipatov's avatar
Vitaly Lipatov committed
460
            echo "emerge --usepkg $*"
461
            ;;
462
        pacman)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
463
            echo "pacman -U --noconfirm --force $nodeps $*"
464 465
            ;;
        slackpkg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
466
            echo "/sbin/installpkg $*"
467
            ;;
468
        npackd)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
469
            echo "npackdcl add --package=$*"
470
            ;;
471 472
        opkg)
            echo "opkg install $*"
473
            ;;
474
        android)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
475
            echo "pm install $*"
476
            ;;
477
        aptcyg)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
478
            echo "apt-cyg install $*"
479
            ;;
480
        tce)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
481
            echo "tce-load -wi $*"
482
            ;;
483
        xbps)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
484
            echo "xbps-install -y $*"
485
            ;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
486 487
        homebrew)
            # FIXME: sudo and quote
Vitaly Lipatov's avatar
Vitaly Lipatov committed
488
            echo "brew install $*"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
489
            ;;
490

491
        *)
492
            fatal "Have no suitable appropriate install command for $PMTYPE"
493 494 495 496
            ;;
    esac
}

497 498
epm_print_install_names_command()
{
499
	# check for pkg_files to support print out command without pkg names in args
500 501
	#[ -z "$1" ] && [ -n "$pkg_files" ] && return
	[ -z "$1" ] && return
502 503
	case $PMTYPE in
		apt-rpm|apt-dpkg)
504
			echo "apt-get -y --force-yes -o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true $APTOPTIONS install $*"
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
			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
}

536 537 538

epm_install()
{
539
    if tasknumber "$pkg_names" >/dev/null ; then
540
        assure_distr ALTLinux "install with task number"
541 542 543 544 545
        assure_exists apt-repo
        sudocmd apt-repo test $(tasknumber "$pkg_names")
        return
    fi

546
    if [ -n "$show_command_only" ] ; then
547 548
        epm_print_install_command $pkg_files
        epm_print_install_names_command $pkg_names
549 550 551
        return
    fi

552
    if [ -n "$direct" ] && [ -z "$repack" ] ; then
553 554 555
        __handle_direct_install
    fi

556
    # if possible, it will put pkg_urls into pkg_files and reconstruct pkg_filenames
557 558 559 560
    if [ -n "$pkg_urls" ] ; then
        load_helper epm-download
        __handle_pkg_urls_to_install
    fi
561

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

564 565 566
    # to be filter happy
    warmup_lowbase

567 568
    local names="$(echo $pkg_names | filter_out_installed_packages)"
    #local names="$(echo $pkg_names | exp_with_arch_suffix | filter_out_installed_packages)"
569
    local files="$(echo $pkg_files | filter_out_installed_packages)"
570

571 572 573 574
    # can be empty only after skip installed
    if [ -z "$files$names" ] ; then
        # TODO: assert $skip_installed
        [ -n "$verbose" ] && info "Skip empty install list"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
575
        # FIXME: see to_remove below
576 577
        return 22
    fi
578

579
    if [ -z "$files" ] && [ -z "$direct" ] ; then
580 581 582
        # it is useful for first time running
        update_repo_if_needed
    fi
583

Vitaly Lipatov's avatar
Vitaly Lipatov committed
584
    # FIXME: see to_remove below
585
    epm_install_names $names || return
586 587 588

    # repack binary files
    if [ -n "$repack" ] ; then
Vitaly Lipatov's avatar
Vitaly Lipatov committed
589
        # FIXME: see to_remove below
590 591 592 593
        __epm_repack_rpm $files || fatal
        files="$repacked_rpms"
    fi

594
    epm_install_files $files
595
    local RETVAL=$?
596

597 598
    # TODO: move it to exit handler
    if [ -z "$DEBUG" ] ; then
599 600
    # TODO: reinvent
    [ -n "$to_remove_pkg_files" ] && rm -fv $to_remove_pkg_files
601
    [ -n "$to_remove_pkg_files" ] && rmdir -v $(dirname $to_remove_pkg_files | head -n1) 2>/dev/null
602
    fi
603

604
    return $RETVAL
Vitaly Lipatov's avatar
Vitaly Lipatov committed
605
}