3
# Copyright (C) 2012-2020 Etersoft
4
# Copyright (C) 2012-2020 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
load_helper epm-sh-altlinux
21
load_helper epm-sh-install
25
load_helper epm-check_updated_repo
26
load_helper epm-sh-warmup
29
# for zypper before SUSE/11.0
30
__use_zypper_no_gpg_checks()
32
a='' zypper install --help 2>&1 | grep -q -- "--no-gpg-checks" && echo "--no-gpg-checks"
35
# args: cmd_reinstall, cmd_install, packages
36
__separate_sudocmd_foreach()
42
if [ -n "$pkg_noninstalled" ] ; then
43
sudocmd_foreach "$cmd_re" $pkg_noninstalled || return
45
if [ -n "$pkg_installed" ] ; then
46
sudocmd_foreach "$cmd_in" $pkg_installed || return
51
# args: cmd_reinstall, cmd_install, packages
58
if [ -n "$pkg_noninstalled" ] ; then
59
sudocmd $cmd_re $pkg_noninstalled || return
61
if [ -n "$pkg_installed" ] ; then
62
sudocmd $cmd_in $pkg_installed || return
67
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
74
if [ -n "$download_only" ] ; then
79
if [ -n "$dryrun" ] ; then
80
load_helper epm-simulate
85
if [ -n "$non_interactive" ] ; then
86
epm_ni_install_names "$@"
92
APTOPTIONS="$APTOPTIONS $(subst_option verbose "-o Debug::pkgMarkInstall=1 -o Debug::pkgProblemResolver=1")"
93
# https://bugzilla.altlinux.org/44670
94
VIRTAPTOPTIONS="-o APT::Install::VirtualVersion=true -o APT::Install::Virtual=true"
95
# not for kernel packages
96
echo "$*" | grep -q "^kernel-" && VIRTAPTOPTIONS=''
97
sudocmd apt-get $VIRTAPTOPTIONS $APTOPTIONS $noremove install $@ && save_installed_packages $@
100
sudocmd aptitude install $@
103
sudocmd ds-install $@
106
sudocmd urpmi $URPMOPTIONS $@
109
docmd pkcon install $@
112
sudocmd pkg_add -r $@
115
sudocmd pkg install $@
118
sudocmd emerge -uD $@
121
sudocmd pacman -S $nodeps $@
124
sudocmd aura -A $force $nodeps $@
127
sudocmd yum $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
130
sudocmd dnf install $(echo "$*" | exp_with_arch_suffix)
133
sudocmd snappy install $@
136
sudocmd zypper install $ZYPPEROPTIONS $@
139
sudocmd mpkg install $@
142
sudocmd eopkg $(subst_option nodeps --ignore-dependency) install $@
145
sudocmd conary update $@
149
__separate_sudocmd_foreach "npackdcl add --package=" "npackdcl update --package=" $@
152
__separate_sudocmd_foreach "/usr/sbin/slackpkg install" "/usr/sbin/slackpkg upgrade" $@
155
# FIXME: sudo and quote
156
SUDO='' __separate_sudocmd "brew install" "brew upgrade" "$@"
159
[ -n "$force" ] && force=-force-depends
160
sudocmd opkg $force install $@
163
__separate_sudocmd "nix-env --install" "nix-env --upgrade" "$@"
169
sudocmd tce-load -wi $@
172
__separate_sudocmd "guix package -i" "guix package -i" $@
175
sudocmd pkg install $@
178
fatal "We still have no idea how to use package repository, ever if it is F-Droid."
181
sudocmd apt-cyg install $@
184
sudocmd xbps-install $@
187
info "When you ask Nix to install a package, it will first try to get it in pre-compiled form from a binary cache. By default, Nix will use the binary cache https://cache.nixos.org; it contains binaries for most packages in Nixpkgs. Only if no binary is available in the binary cache, Nix will build the package from source."
188
sudocmd nix-env -iA $@
191
sudocmd $PMTYPE install $@
194
fatal "Have no suitable install command for $PMTYPE"
199
# Non interactive install
200
epm_ni_install_names()
202
[ -z "$1" ] && return
206
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 $@
209
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 $@
212
sudocmd env ACCEPT_EULA=y DEBIAN_FRONTEND=noninteractive aptitude -y install $@
215
sudocmd yum -y $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
218
sudocmd dnf -y --allowerasing $YUMOPTIONS install $(echo "$*" | exp_with_arch_suffix)
221
sudocmd urpmi --auto $URPMOPTIONS $@
224
# FIXME: returns true ever no package found, need check for "no found", "Nothing to do."
225
yes | sudocmd zypper --non-interactive $ZYPPEROPTIONS install $@
228
docmd pkcon install --noninteractive $@
231
sudocmd pkg_add -r $@
234
sudocmd pkg install -y $@
237
sudocmd emerge -uD $@
240
sudocmd pacman -S --noconfirm $nodeps $@
243
sudocmd aura -A $force $nodeps $@
246
# npackdcl update --package=<package> (remove old and install new)
247
sudocmd npackdcl add --package="$*"
250
docmd choco install $@
253
sudocmd opkg -force-defaults install $@
256
sudocmd eopkg --yes-all install $@
259
sudocmd nix-env --install $@
265
sudocmd tce-load -wi $@
268
sudocmd xbps-install -y $@
271
sudocmd $PMTYPE -s install $@
274
# FIXME: sudo and quote
275
SUDO='' __separate_sudocmd "brew install" "brew upgrade" $@
278
sudocmd pkg install $@
281
# FIXME: broken status when use batch and default answer
282
__separate_sudocmd_foreach "/usr/sbin/slackpkg -batch=on -default_answer=yes install" "/usr/sbin/slackpkg -batch=on -default_answer=yes upgrade" $@
285
fatal "Have no suitable appropriate install command for $PMTYPE"
290
__epm_check_if_rpm_already_installed()
292
# Not: we can make optimize if just check version?
293
LC_ALL=C sudorun rpm -Uvh --test "$@" 2>&1 | grep -q "is already installed"
296
__handle_direct_install()
298
case "$BASEDISTRNAME" in
300
load_helper epm-download
302
for pkg in $pkg_names ; do
303
url=$(__epm_get_altpkg_url $pkg)
304
[ -n "$url" ] || continue
306
pkg_urls="$pkg_urls $url"
314
# TODO: forbid src.rpm
315
__epm_check_if_src_rpm()
319
echo "$pkg" | grep -q "\.src\.rpm" && fatal "Installation of a source packages (like '$pkg') is not supported."
323
__epm_if_command_path()
325
is_dirpath "$1" && rhas "$1" "bin/" && ! rhas "$1" "/home"
328
__epm_get_replacepkgs()
330
[ -n "$2" ] && echo '--replacepkgs' && return
331
# don't use --replacepkgs when install only one file
337
[ -z "$files" ] && return
339
# on some systems install target can be a real path
340
# use hi-level for install by file path (f.i. epm install /usr/bin/git)
341
if __epm_if_command_path $files ; then
342
epm_install_names $files
346
# TODO: check read permissions
348
# do not fallback to install_names if we have no permissions
349
case "$BASEDISTRNAME" in
351
load_helper epm-install-alt
352
epm_install_files_alt $files
358
apt-dpkg|aptitude-dpkg)
359
load_helper epm-install-apt-dpkg
360
epm_install_files_apt_dpkg $files
365
load_helper epm-install-rpm
366
epm_install_files_rpm $files
372
# check save_only before commands without repack supporting
373
if [ -n "$save_only" ] ; then
375
cp -v $files "$EPMCURDIR"
379
if [ -n "$put_to_repo" ] ; then
380
load_helper epm-repopkg
381
epm_put_to_repo $files
388
docmd pkcon install-local $files
391
sudocmd pkg_add $files
394
local PKGTYPE="$(get_package_type $files)"
397
sudocmd pkg_add $files
400
sudocmd pkg add $files
405
sudocmd pm install $files
408
sudocmd eopkg install $files
411
load_helper epm-install-emerge
412
sudocmd epm_install_emerge $files
415
sudocmd pacman -U --noconfirm $nodeps $files && return
418
[ -n "$nodeps" ] && return $RES
419
sudocmd pacman -U $files
422
# FIXME: check for full package name
423
# FIXME: broken status when use batch and default answer
424
__separate_sudocmd_foreach "/sbin/installpkg" "/sbin/upgradepkg" $files
428
# other systems can install file package via ordinary command
429
epm_install_names $files
435
if [ "$BASEDISTRNAME" = "alt" ] ; then
436
if tasknumber "$pkg_names" >/dev/null ; then
437
load_helper epm-install-alt
438
if [ -n "$interactive" ] ; then
439
confirm_info "You are about to install $pkg_names task(s) from https://git.altlinux.org."
441
epm_install_alt_tasks "$pkg_names"
446
if [ -n "$show_command_only" ] ; then
447
# TODO: handle pkg_urls too
448
load_helper epm-install-print-command
449
epm_print_install_files_command $pkg_files
450
epm_print_install_names_command $pkg_names
454
if [ -n "$interactive" ] && [ -n "$pkg_names$pkg_files$pkg_urls" ] ; then
455
confirm_info "You are about to install $(echo $pkg_names $pkg_files $pkg_urls) package(s)."
456
# TODO: for some packages with dependencies apt will ask later again
459
if [ -n "$direct" ] && [ -z "$repack" ] ; then
460
# it will put pkg_urls into pkg_files and reconstruct pkg_filenames
461
__handle_direct_install
464
if [ -n "$pkg_urls" ] ; then
465
load_helper epm-download
466
# it will put downloaded by pkg_urls packages to pkg_files and reconstruct pkg_filenames
467
__handle_pkg_urls_to_install
470
[ -z "$pkg_files$pkg_names" ] && info "Skip empty install list" && return 22
475
# Note: filter_out_installed_packages depends on skip_installed flag
476
local names="$(echo $pkg_names | filter_out_installed_packages)"
477
#local names="$(echo $pkg_names | exp_with_arch_suffix | filter_out_installed_packages)"
478
local files="$(echo $pkg_files | filter_out_installed_packages)"
480
# can be empty only after all installed packages were skipped
481
if [ -z "$files$names" ] ; then
482
# TODO: assert $skip_installed
483
[ -n "$verbose" ] && info "Skip empty install list (filtered out, all requested packages is already installed)"
484
# FIXME: see to_remove below
488
if [ -n "$names" ] && [ -z "$direct" ] ; then
489
# it is useful for first time running
490
update_repo_if_needed
493
case "$BASEDISTRNAME" in
495
load_helper epm-install-alt
496
epm_install_alt_names $names || return
499
# FIXME: see to_remove below
500
epm_install_names $names || return
504
[ -z "$files" ] && debug "Skip empty install files list" && return 0
506
if [ -n "$download_only" ] ; then
507
# save files to the current dir before install and repack
509
cp -v $files "$EPMCURDIR"
513
if [ -n "$repack" ] ; then
514
# repack binary files if asked
515
__epm_repack $files || return
516
files="$repacked_pkgs"
519
epm_install_files $files