NBash

Форк
0
520 строк · 15.5 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2012-2020  Etersoft
4
# Copyright (C) 2012-2020  Vitaly Lipatov <lav@etersoft.ru>
5
#
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.
10
#
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.
15
#
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/>.
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
# for zypper before SUSE/11.0
30
__use_zypper_no_gpg_checks()
31
{
32
    a='' zypper install --help 2>&1 | grep -q -- "--no-gpg-checks" && echo "--no-gpg-checks"
33
}
34

35
# args: cmd_reinstall, cmd_install, packages
36
__separate_sudocmd_foreach()
37
{
38
    local cmd_re=$1
39
    local cmd_in=$2
40
    shift 2
41
    separate_installed $@
42
    if [ -n "$pkg_noninstalled" ] ; then
43
        sudocmd_foreach "$cmd_re" $pkg_noninstalled || return
44
    fi
45
    if [ -n "$pkg_installed" ] ; then
46
        sudocmd_foreach "$cmd_in" $pkg_installed || return
47
    fi
48
    return 0
49
}
50

51
# args: cmd_reinstall, cmd_install, packages
52
__separate_sudocmd()
53
{
54
    local cmd_re=$1
55
    local cmd_in=$2
56
    shift 2
57
    separate_installed $@
58
    if [ -n "$pkg_noninstalled" ] ; then
59
        sudocmd $cmd_re $pkg_noninstalled || return
60
    fi
61
    if [ -n "$pkg_installed" ] ; then
62
        sudocmd $cmd_in $pkg_installed || return
63
    fi
64
    return 0
65
}
66

67
# copied from etersoft-build-utils/share/eterbuild/functions/rpmpkg
68
epm_install_names()
69
{
70
    [ -z "$1" ] && return
71

72
    warmup_hibase
73

74
    if [ -n "$download_only" ] ; then
75
        epm download "$@"
76
        return
77
    fi
78

79
    if [ -n "$dryrun" ] ; then
80
        load_helper epm-simulate
81
        epm simulate "$@"
82
        return
83
    fi
84

85
    if [ -n "$non_interactive" ] ; then
86
        epm_ni_install_names "$@"
87
        return
88
    fi
89

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

199
# Non interactive install
200
epm_ni_install_names()
201
{
202
    [ -z "$1" ] && return
203

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

290
__epm_check_if_rpm_already_installed()
291
{
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"
294
}
295

296
__handle_direct_install()
297
{
298
    case "$BASEDISTRNAME" in
299
        "alt")
300
            load_helper epm-download
301
            local pkg url
302
            for pkg in $pkg_names ; do
303
                url=$(__epm_get_altpkg_url $pkg)
304
                [ -n "$url" ] || continue
305
                # TODO: use estrlist
306
                pkg_urls="$pkg_urls $url"
307
            done
308
            # FIXME: need remove
309
            pkg_names=""
310
            ;;
311
    esac
312
}
313

314
# TODO: forbid src.rpm
315
__epm_check_if_src_rpm()
316
{
317
    local pkg
318
    for pkg in $@ ; do
319
        echo "$pkg" | grep -q "\.src\.rpm" && fatal "Installation of a source packages (like '$pkg') is not supported."
320
    done
321
}
322

323
__epm_if_command_path()
324
{
325
    is_dirpath "$1" && rhas "$1" "bin/" && ! rhas "$1" "/home"
326
}
327

328
__epm_get_replacepkgs()
329
{
330
    [ -n "$2" ] && echo '--replacepkgs' && return
331
    # don't use --replacepkgs when install only one file
332
}
333

334
epm_install_files()
335
{
336
    local files="$*"
337
    [ -z "$files" ] && return
338

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
343
        return
344
    fi
345

346
    # TODO: check read permissions
347
    # sudo test -r FILE
348
    # do not fallback to install_names if we have no permissions
349
    case "$BASEDISTRNAME" in
350
        "alt")
351
            load_helper epm-install-alt
352
            epm_install_files_alt $files
353
            return
354
            ;;
355
    esac
356

357
    case $PMTYPE in
358
        apt-dpkg|aptitude-dpkg)
359
            load_helper epm-install-apt-dpkg
360
            epm_install_files_apt_dpkg $files
361
            return
362
            ;;
363

364
       *-rpm)
365
            load_helper epm-install-rpm
366
            epm_install_files_rpm $files
367
            return
368
            ;;
369
    esac
370

371

372
    # check save_only before commands without repack supporting
373
    if [ -n "$save_only" ] ; then
374
        echo
375
        cp -v $files "$EPMCURDIR"
376
        return
377
    fi
378

379
    if [ -n "$put_to_repo" ] ; then
380
        load_helper epm-repopkg
381
        epm_put_to_repo $files
382
        return
383
    fi
384

385

386
    case $PMTYPE in
387
        packagekit)
388
            docmd pkcon install-local $files
389
            return ;;
390
        pkgsrc)
391
            sudocmd pkg_add $files
392
            return ;;
393
        pkgng)
394
            local PKGTYPE="$(get_package_type $files)"
395
            case "$PKGTYPE" in
396
                tbz)
397
                    sudocmd pkg_add $files
398
                    ;;
399
                *)
400
                    sudocmd pkg add $files
401
                    ;;
402
            esac
403
            return ;;
404
        android)
405
            sudocmd pm install $files
406
            return ;;
407
        eopkg)
408
            sudocmd eopkg install $files
409
            return ;;
410
        emerge)
411
            load_helper epm-install-emerge
412
            sudocmd epm_install_emerge $files
413
            return ;;
414
        pacman)
415
            sudocmd pacman -U --noconfirm $nodeps $files && return
416
            local RES=$?
417

418
            [ -n "$nodeps" ] && return $RES
419
            sudocmd pacman -U $files
420
            return ;;
421
        slackpkg)
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
425
            return ;;
426
    esac
427

428
    # other systems can install file package via ordinary command
429
    epm_install_names $files
430
}
431

432

433
epm_install()
434
{
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."
440
            fi
441
            epm_install_alt_tasks "$pkg_names"
442
            return
443
        fi
444
    fi
445

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
451
        return
452
    fi
453

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
457
    fi
458

459
    if [ -n "$direct" ] && [ -z "$repack" ] ; then
460
        # it will put pkg_urls into pkg_files and reconstruct pkg_filenames
461
        __handle_direct_install
462
    fi
463

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
468
    fi
469

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

472
    # to be filter happy
473
    warmup_lowbase
474

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)"
479

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
485
        return 0
486
    fi
487

488
    if [ -n "$names" ] && [ -z "$direct" ] ; then
489
        # it is useful for first time running
490
        update_repo_if_needed
491
    fi
492

493
    case "$BASEDISTRNAME" in
494
        "alt")
495
            load_helper epm-install-alt
496
            epm_install_alt_names $names || return
497
            ;;
498
        *)
499
            # FIXME: see to_remove below
500
            epm_install_names $names || return
501
            ;;
502
    esac
503

504
    [ -z "$files" ] && debug "Skip empty install files list" && return 0
505

506
    if [ -n "$download_only" ] ; then
507
        # save files to the current dir before install and repack
508
        echo
509
        cp -v $files "$EPMCURDIR"
510
        return
511
    fi
512

513
    if [ -n "$repack" ] ; then
514
        # repack binary files if asked
515
        __epm_repack $files || return
516
        files="$repacked_pkgs"
517
    fi
518

519
    epm_install_files $files
520
}
521

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.