NBash

Форк
0
117 строк · 3.4 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2013-2016  Etersoft
4
# Copyright (C) 2013-2016  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
__check_command_in_path()
21
{
22
    # with hack for sudo case
23
    ( PATH=$PATH:/sbin:/usr/sbin print_command_path "$1" )
24
}
25

26
# returns TRUE if package version is omitted, or package is not installed, or version is too old
27
__epm_need_update()
28
{
29
    local PACKAGE="$1"
30
    local PACKAGEVERSION="$2"
31

32
    [ -n "$PACKAGEVERSION" ] || return 0
33

34
    load_helper epm-query
35
    is_installed "$PACKAGE" || return 0
36

37
    load_helper epm-print
38
    # epm print version for package N
39
    local INSTALLEDVERSION=$(query_package_field "version" "$PACKAGE")
40
    # if needed >= installed, return 0
41
    [ "$(compare_version "$PACKAGEVERSION" "$INSTALLEDVERSION")" -gt 0 ] && return 0
42

43
    return 1
44
}
45

46
__epm_assure_checking()
47
{
48
    local CMD="$1"
49
    local PACKAGE="$2"
50
    local PACKAGEVERSION="$3"
51

52
    [ -n "$PACKAGEVERSION" ] && return 1
53

54
    if is_dirpath "$CMD" ; then
55
        # TODO: check for /usr/bin, /bin, /usr/sbin, /sbin
56
        if [ -e "$CMD" ] ; then
57
            if [ -n "$verbose" ] ; then
58
                info "File or directory $CMD is already exists."
59
                epm qf "$CMD" >&2
60
            fi
61
            return 0
62
        fi
63

64
        [ -n "$PACKAGE" ] || fatal "You need run with package name param when use with absolute path to non executable file"
65
        return 1
66
    fi
67

68
    if __check_command_in_path "$CMD" >/dev/null ; then
69
        if [ -n "$verbose" ] ; then
70
            local compath="$(__check_command_in_path "$1")"
71
            info "Command $CMD is exists: $compath"
72
            epm qf "$compath" >&2
73
        fi
74
        return 0
75
    fi
76

77
    return 1
78
}
79

80
# Do fast checking for command and install package if the command does not exist
81

82
# $1 - command name
83
# $2 - [package name]
84
# $3 - [needed package version]
85

86
epm_assure()
87
{
88
    local CMD="$1"
89
    local PACKAGE="$2"
90
    local PACKAGEVERSION="$3"
91
    [ -n "$PACKAGE" ] || PACKAGE="$1"
92

93
    __epm_assure_checking $CMD $PACKAGE $PACKAGEVERSION && return 0
94

95
    info "Installing appropriate package for $CMD command..."
96
    __epm_need_update $PACKAGE $PACKAGEVERSION || return 0
97

98
    # can't be used in epm ei case
99
    #docmd epm --auto install $PACKAGE || return
100
    load_helper epm-install
101
    (repack='' pkg_names="$PACKAGE" pkg_files='' pkg_urls='' epm_install ) || return
102

103
    # https://bugzilla.altlinux.org/42240
104
    load_helper epm-mark
105
    epm_mark_auto "$PACKAGE"
106

107
    # no check if we don't need a version
108
    [ -n "$PACKAGEVERSION" ] || return 0
109

110
    # check if we couldn't update and still need update
111
    __epm_need_update $PACKAGE $PACKAGEVERSION || return 0
112

113
    local textpackage
114
    [ -n "$PACKAGEVERSION" ] && textpackage=" >= $PACKAGEVERSION"
115
    warning "Can't assure in '$CMD' command from $PACKAGE$textpackage package"
116
    return 1
117
}
118

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

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

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

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