NBash

Форк
0
232 строки · 6.8 Кб
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
epm_install_files_alt()
21
{
22
    local files="$*"
23
    [ -z "$files" ] && return
24

25
    # TODO: check read permissions
26
    # sudo test -r FILE
27
    # do not fallback to install_names if we have no permissions
28

29
    __epm_print_warning_for_nonalt_packages $files
30

31
    # do repack if needed
32
    if __epm_repack_if_needed $files ; then
33
        [ -n "$repacked_pkgs" ] || fatal "Can't convert $files"
34
        files="$repacked_pkgs"
35
    fi
36

37
    if [ -n "$save_only" ] ; then
38
        echo
39
        cp -v $files "$EPMCURDIR"
40
        return
41
    fi
42

43
    if [ -n "$put_to_repo" ] ; then
44
        load_helper epm-repopkg
45
        epm_put_to_repo $files
46
        return
47
    fi
48

49
    __epm_check_if_src_rpm $files
50

51
    if [ -z "$repacked_pkgs" ] ; then
52
        __epm_check_vendor $files
53
        __epm_check_if_needed_repack $files
54
    fi
55

56
    # --replacepkgs: Install the Package Even If Already Installed
57
    local replacepkgs="$(__epm_get_replacepkgs $files)"
58
    sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && save_installed_packages $files && return
59
    local RES=$?
60
    # TODO: check rpm result code and convert it to compatible format if possible
61
    __epm_check_if_rpm_already_installed $force $replacepkgs $noscripts $nodeps $files && return
62

63
    # if run with --nodeps, do not fallback on hi level
64
    [ -n "$nodeps" ] && return $RES
65

66
    # separate second output
67
    info
68

69
    # try install via apt if we could't install package file via rpm (we guess we need install requirements firsly)
70

71
    if [ -z "$noscripts" ] ; then
72
        epm_install_names $files
73
        return
74
    fi
75

76
    # TODO: use it always (apt can install version from repo instead of a file package)
77
    info "Workaround for install packages via apt with --noscripts (see https://bugzilla.altlinux.org/44670)"
78
    info "Firstly install package requrements …"
79
    # names of packages to be installed
80
    local fl="$(epm print name for package $files)"
81
    local req="$(docmd epm req --short $files)" || return
82
    # exclude package names from requires (req - fl)
83
    req="$(estrlist exclude "$fl" "$req")"
84
    # TODO: can we install only requires via apt?
85
    docmd epm install --skip-installed $req || return
86

87
    # retry with rpm
88
    # --replacepkgs: Install the Package Even If Already Installed
89
    local replacepkgs="$(__epm_get_replacepkgs $files)"
90
    sudocmd rpm -Uvh $replacepkgs $(subst_option dryrun --test) $force $noscripts $nodeps $files && save_installed_packages $files
91
}
92

93
get_current_kernel_flavour()
94
{
95
    rrel=$(uname -r)
96
    rflv=${rrel#*-}
97
    rflv=${rflv%-*}
98
    echo "$rflv"
99
}
100

101
# std-def 1.2.3-alt1 -> 1.2.3-std-def-alt1
102
make_kernel_release()
103
{
104
    echo "$2" | sed -e "s|-|-$1-|"
105
}
106

107
# return latest installed kernel in a form like 5.15.109-un-def-alt1
108
get_latest_kernel_rel()
109
{
110
    local kernel_flavour="$1"
111
    # current
112
    rrel=$(uname -r)
113

114
    # latest
115
    # copied and modified from update-kernel
116
    # get the maximum available kernel package version
117
    kmaxver=
118
    while read version
119
    do
120
        comparever="$(rpmevrcmp "$kmaxver" "$version")"
121
        [ "$comparever" -lt 0 ] && kmaxver="$version" ||:
122
    done <<<"$(epm print version-release for package kernel-image-$kernel_flavour)"
123
    [ -z "$kmaxver" ] && echo "$rrel" && return
124

125
    make_kernel_release "$kernel_flavour" "$kmaxver"
126
}
127

128
# install <module-name>-std-def
129
epm_install_alt_kernel_module()
130
{
131
    [ -n "$1" ] || return 0
132

133
    local kflist=''
134
    local kmplist=''
135
    local kmf km kf
136

137
    # fill kernel flavour list
138
    for kmf in $*; do
139
        km="$(echo "$kmf" | cut -d- -f1)"
140
        kf="$(echo "$kmf" | cut -d- -f2,3)"
141
        # use current flavour as default
142
        [ "$km" = "$kf" ] && kf="$(get_current_kernel_flavour)"
143
        kflist="$kflist $kf"
144
    done
145

146
    # firstly, update all needed kernels (by flavour)
147
    for kf in $(estrlist uniq $kflist) ; do
148
        info
149
        docmd epm update-kernel -t $kf || exit
150
    done
151

152
    # skip install modules if there are no installed kernels (may be, a container)
153
    epm installed "kernel-image-$kf" || return 0
154

155
    # make list for install kernel modules
156
    for kmf in $*; do
157
        km="$(echo "$kmf" | cut -d- -f1)"
158
        kf="$(echo "$kmf" | cut -d- -f2,3)"
159
        # use current flavour as default
160
        [ "$km" = "$kf" ] && kf="$(get_current_kernel_flavour)"
161
        kvf="$(get_latest_kernel_rel $kf)"
162
        #kmplist="$kmplist kernel-modules-$km-$kf"
163
        # install kernel module for latest installed kernel
164
        kmplist="$kmplist kernel-modules-$km-$kvf"
165
    done
166

167
    # secondly, install module(s)
168
    epm_install_names $kmplist
169
}
170

171

172
epm_install_alt_names()
173
{
174
    local kmlist=''
175
    local installnames=''
176

177
    while [ -n "$1" ] ; do
178
        local pkgname
179
        pkgname="$1"
180
        if echo "$pkgname" | grep -v "#" | grep -q "^kernel-modules*-" ; then
181
            # virtualbox[-std-def]
182
            local kmn="$(echo $pkgname | sed -e 's|kernel-modules*-||')"
183
            local kf1="$(echo "$kmn" | cut -d- -f2)"
184
            local kf2="$(echo "$kmn" | cut -d- -f4)"
185
            # pass install with full pkgnames
186
            if [ "$kf1" != "$kf2" ] && [ -n "$kf2" ] || echo "$kf1" | grep -q "^[0-9]" ; then
187
                installnames="$installnames $pkgname"
188
            else
189
                kmlist="$kmlist $kmn"
190
            fi
191
        else
192
            installnames="$installnames $pkgname"
193
        fi
194
        shift
195
    done
196

197
    epm_install_names $installnames || return
198
    epm_install_alt_kernel_module $kmlist || return
199
}
200

201

202
# apt-repo with non_interactive support
203
apt_repo_prepare()
204
{
205
    assure_exists apt-repo
206
    [ -n "$non_interactive" ] || return
207

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

213
apt_repo_after()
214
{
215
    [ -n "$non_interactive" ] || return
216

217
    $SUDO rm /etc/apt/apt.conf.d/eepm-apt-noninteractive.conf 2>/dev/null
218
}
219

220

221
epm_install_alt_tasks()
222
{
223
    local res
224
    # TODO: don't use apt-repo
225
    apt_repo_prepare
226

227
    sudocmd_foreach "apt-repo test" $(tasknumber "$@")
228
    res=$?
229

230
    apt_repo_after
231
    return $res
232
}
233

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

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

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

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