NBash

Форк
0
302 строки · 9.5 Кб
1
#!/bin/sh
2
#
3
# Copyright (C) 2015-2016, 2020, 2021  Etersoft
4
# Copyright (C) 2015-2016, 2020, 2021  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-query
21

22

23
__replace_text_in_alt_repo()
24
{
25
    local i
26
    for i in /etc/apt/sources.list /etc/apt/sources.list.d/*.list ; do
27
        [ -s "$i" ] || continue
28
        # TODO: don't change file if untouched
29
        #grep -q -- "$1" "$i" || continue
30
        regexp_subst "$1" "$i"
31
    done
32
}
33

34
__repofix_check_vendor()
35
{
36
    local i
37
    for i in /etc/apt/vendors.list.d/*.list; do
38
        [ -e "$i" ] || continue
39
        grep -q "^simple-key \"$1\"" $i && return
40
    done
41
    return 1
42
}
43

44
__repofix_filter_vendor()
45
{
46
    local br="$1"
47
    br="$(echo "$br" | sed -e "s|\..*||")"
48
    case $br in
49
        c8*)
50
            br="cert8"
51
            ;;
52
        c9*)
53
            br="cert9"
54
            ;;
55
        Sisyphus)
56
            br="alt"
57
            ;;
58
    esac
59
    echo "$br"
60
}
61

62

63
__replace_alt_version_in_repo()
64
{
65
    local i
66
    assure_exists apt-repo
67
    #echo "Upgrading $DISTRNAME from $1 to $2 ..."
68
    a='' apt-repo list | sed -E -e "s|($1)|{\1}->{$2}|g" | grep -E --color -- "$1"
69
    # ask and replace only we will have changes
70
    if a='' apt-repo list | grep -E -q -- "$1" ; then
71
        __replace_text_in_alt_repo "/^ *#/! s!$1!$2!g"
72
    fi
73
    #docmd apt-repo list
74
}
75

76
__alt_replace_sign_name()
77
{
78
    local TO="$1"
79
    __replace_text_in_alt_repo "/^ *#/! s!\[alt\]!$TO!g"
80
    __replace_text_in_alt_repo "/^ *#/! s!\[sisyphus\]!$TO!g"
81
    __replace_text_in_alt_repo "/^ *#/! s!\[updates\]!$TO!g"
82
    __replace_text_in_alt_repo "/^ *#/! s!\[cert[789]\]!$TO!g"
83
    __replace_text_in_alt_repo "/^ *#/! s!\[p10\.?[0-9]?\]!$TO!g"
84
    __replace_text_in_alt_repo "/^ *#/! s!\[[tpc][6-9]\.?[0-9]?\]!$TO!g"
85
}
86

87
__alt_repofix()
88
{
89
    local TO="$1"
90
    epm --quiet repo fix >/dev/null
91
    if [ -n "$TO" ] ; then
92
        # TODO: switch it in repo code
93
        TO="$(__repofix_filter_vendor "$TO")"
94
        __alt_replace_sign_name "[$TO]"
95
    fi
96
}
97

98
#__switch_repo_to()
99
epm_reposwitch()
100
{
101
    local TO="$1"
102
    [ -n "$TO" ] || fatal "run repo switch with arg (p9, p10, Sisyphus)"
103
    [ "$TO" = "sisyphus" ] && TO="Sisyphus"
104
    if [ "$TO" = "Sisyphus" ] ; then
105
        __replace_alt_version_in_repo "[tpc][5-9]\.?[0-9]?/branch/" "$TO/"
106
        __replace_alt_version_in_repo "p10\.?[0-9]?/branch/" "$TO/"
107
    else
108
        __replace_alt_version_in_repo "Sisyphus/" "$TO/branch/"
109
        __replace_alt_version_in_repo "[tpc][5-9]\.?[0-9]?/branch/" "$TO/branch/"
110
        if [ "$TO" != "p10" ] ; then
111
            __replace_alt_version_in_repo "p10\.?[0-9]?/branch/" "$TO/branch/"
112
        fi
113
    fi
114

115
    __alt_repofix "$TO"
116

117
    if [ "$TO" = "p10" ] ; then
118
        echo '%_priority_distbranch p10' >/etc/rpm/macros.d/p10
119
    else
120
        rm -fv /etc/rpm/macros.d/p10
121
    fi
122
    #epm repo list
123
}
124

125

126
# source-list vendor path
127
# example: /etc/apt/source.list p7 ALTLinux\/Sisyphus
128
__try_fix_apt_source_list()
129
{
130
    local list="$1"
131
    local br="$(__repofix_filter_vendor "$2")"
132
    local path="$3"
133
    if grep -q -e "^[^#].*$path" $list ; then
134
        if __repofix_check_vendor $br ; then
135
            regexp_subst "/$path/s/^rpm[[:space:]]*([fhr])/rpm [$br] \1/" $list
136
        else
137
            warning "Skip set $br vendor key (it is missed) for $list"
138
            regexp_subst "/$path/s/^rpm[[:space:]]*\[$br\][[:space:]]*([fhr])/rpm \1/" $list
139
        fi
140
    fi
141
}
142

143
__fix_alt_sources_list()
144
{
145
    # for beauty spaces
146
    local SUBST_ALT_RULE1='s!^(.*)[/ ](ALTLinux|LINUX\@Etersoft)[/ ]*(Sisyphus)[/ ](x86_64|i586|x86_64-i586|noarch|aarch64) !\1 \2/\3/\4 !gi'
147
    local SUBST_ALT_RULE2='s!^(.*)[/ ](ALTLinux|LINUX\@Etersoft)[/ ]*([tcp][6-9]\.?[0-9]?[/ ]branch|[tcp]1[012][/ ]branch)[/ ](x86_64|i586|x86_64-i586|noarch|aarch64) !\1 \2/\3/\4 !gi'
148
    local i
149

150
    for i in "$@" ; do
151
        [ -s "$i" ] || continue
152
        #perl -i.bak -pe "$SUBST_ALT_RULE" $i
153
        # TODO: only for uncommented strings
154
        #sed -i -r -e "$SUBST_ALT_RULE" $i
155
        regexp_subst "/^ *#/! s| pub|/pub|" $i
156
        regexp_subst "/^ *#/! $SUBST_ALT_RULE1" $i
157
        regexp_subst "/^ *#/! $SUBST_ALT_RULE2" $i
158

159
        # Sisyphus uses 'alt' vendor key
160
        __try_fix_apt_source_list $i alt "ALTLinux\/Sisyphus"
161
        __try_fix_apt_source_list $i etersoft "Etersoft\/Sisyphus"
162

163
        # skip branch replacement for ALT Linux Sisyphus
164
        [ "$DISTRVERSION" = "Sisyphus" ] && continue
165

166
        # add signs for branches
167
        __try_fix_apt_source_list $i $DISTRVERSION "ALTLinux\/$DISTRVERSION\/branch"
168
        __try_fix_apt_source_list $i etersoft "Etersoft\/$DISTRVERSION\/branch"
169
    done
170
}
171

172
__subst_with_etersoft_url()
173
{
174
    local NURL="http://download.etersoft.ru/pub ALTLinux"
175
    echo "$1" | sed \
176
        -e "s|h\?f\?t\?tp://ftp.altlinux.org/pub/distributions/* ALTLinux|$NURL|" \
177
        -e "s|h\?f\?t\?tp://ftp.basealt.ru/pub/distributions/* ALTLinux|$NURL|" \
178
        -e "s|h\?f\?t\?tp://mirror.yandex.ru/* altlinux|$NURL|" \
179
        -e "s|h\?f\?t\?tp://mirror.eterfund.org/download.etersoft.ru/pub/* ALTLinux|$NURL|"
180
}
181

182
__subst_with_eterfund_url()
183
{
184
    local NURL="https://mirror.eterfund.org/download.etersoft.ru/pub ALTLinux"
185
    echo "$1" | sed \
186
        -e "s|h\?f\?t\?tp://ftp.altlinux.org/pub/distributions/* ALTLinux|$NURL|" \
187
        -e "s|h\?f\?t\?tp://ftp.basealt.ru/pub/distributions/* ALTLinux|$NURL|" \
188
        -e "s|h\?f\?t\?tp://mirror.yandex.ru/* altlinux|$NURL|"
189
}
190

191
__subst_with_yandex_url()
192
{
193
    local NURL="http://mirror.yandex.ru altlinux"
194
    echo "$1" | sed \
195
        -e "s|h\?f\?t\?tp://ftp.altlinux.org/pub/distributions/* ALTLinux|$NURL|" \
196
        -e "s|h\?f\?t\?tp://ftp.basealt.ru/pub/distributions/* ALTLinux|$NURL|" \
197
        -e "s|h\?f\?t\?tp://ftp.etersoft.ru/pub/* ALTLinux|$NURL|" \
198
        -e "s|h\?f\?t\?tp://download.etersoft.ru/pub/* ALTLinux|$NURL|" \
199
        -e "s|h\?f\?t\?tp://mirror.eterfund.org/download.etersoft.ru/pub/* ALTLinux|$NURL|"
200
}
201

202
__subst_with_basealt_url()
203
{
204
    local NURL="http://ftp.basealt.ru/pub/distributions ALTLinux"
205
    echo "$1" | sed \
206
        -e "s|h\?f\?t\?tp://mirror.yandex.ru/* altlinux|$NURL|" \
207
        -e "s|h\?f\?t\?tp://ftp.etersoft.ru/pub/* ALTLinux|$NURL|" \
208
        -e "s|h\?f\?t\?tp://mirror.eterfund.org/download.etersoft.ru/pub/* ALTLinux|$NURL|" \
209
        -e "s|h\?f\?t\?tp://download.etersoft.ru/pub/* ALTLinux|$NURL|"
210
}
211

212
__subst_with_altlinux_url()
213
{
214
    local NURL="http://ftp.altlinux.org/pub/distributions ALTLinux"
215
    echo "$1" | sed \
216
        -e "s|h\?f\?t\?tp://mirror.yandex.ru/* altlinux|$NURL|" \
217
        -e "s|h\?f\?t\?tp://ftp.etersoft.ru/pub/* ALTLinux|$NURL|" \
218
        -e "s|h\?f\?t\?tp://mirror.eterfund.org/download.etersoft.ru/pub/* ALTLinux|$NURL|" \
219
        -e "s|h\?f\?t\?tp://download.etersoft.ru/pub/* ALTLinux|$NURL|"
220
}
221

222
__fix_repo_to_etersoft()
223
{
224
    local NN
225
    a="" apt-repo list | grep -v debuginfo | grep -v etersoft | grep -v "file:/" | while read nn ; do
226
        NN="$(__subst_with_etersoft_url "$nn")"
227
        [ "$NN" = "$nn" ] && continue
228
        epm removerepo "$nn"
229
        epm addrepo "$NN"
230
    done
231
}
232

233
__fix_repo_to_yandex()
234
{
235
    local NN
236
    a="" apt-repo list | grep -v debuginfo | grep -v mirror\.yandex | grep -v "file:/" | while read nn ; do
237
        NN="$(__subst_with_yandex_url "$nn")"
238
        [ "$NN" = "$nn" ] && continue
239
        epm removerepo "$nn"
240
        epm addrepo "$NN"
241
    done
242
}
243

244
__fix_repo_to_basealt()
245
{
246
    local NN
247
    a="" apt-repo list | grep -v debuginfo | grep -v ftp.basealt | grep -v "file:/" | while read nn ; do
248
        NN="$(__subst_with_basealt_url "$nn")"
249
        [ "$NN" = "$nn" ] && continue
250
        epm removerepo "$nn"
251
        epm addrepo "$NN"
252
    done
253
}
254

255

256
epm_repofix()
257
{
258

259
case $BASEDISTRNAME in
260
    "alt")
261
        assure_exists apt-repo
262
        [ -n "$quiet" ] || docmd apt-repo list
263
        assure_root
264
        __fix_alt_sources_list /etc/apt/sources.list
265
        __fix_alt_sources_list /etc/apt/sources.list.d/*.list
266
        # TODO: move to repo change
267
        if [ "$1" = "etersoft" ] ; then
268
            __fix_repo_to_etersoft /etc/apt/sources.list
269
            __fix_repo_to_etersoft /etc/apt/sources.list.d/*.list
270
        fi
271
        if [ "$1" = "eterfund.org" ] ; then
272
            __fix_repo_to_eterfund /etc/apt/sources.list
273
            __fix_repo_to_eterfund /etc/apt/sources.list.d/*.list
274
        fi
275
        if [ "$1" = "yandex" ] ; then
276
            __fix_repo_to_yandex /etc/apt/sources.list
277
            __fix_repo_to_yandex /etc/apt/sources.list.d/*.list
278
        fi
279
        if [ "$1" = "basealt" ] ; then
280
            __fix_repo_to_basealt /etc/apt/sources.list
281
            __fix_repo_to_basealt /etc/apt/sources.list.d/*.list
282
        fi
283
        if [ "$1" = "altlinux.org" ] ; then
284
            __fix_repo_to_altlinux /etc/apt/sources.list
285
            __fix_repo_to_altlinux /etc/apt/sources.list.d/*.list
286
        fi
287
        docmd apt-repo list
288
        return
289
        ;;
290
esac
291

292
case $PMTYPE in
293
#    apt-rpm)
294
#        ;;
295
#    yum-rpm|dnf-rpm)
296
#        ;;
297
    *)
298
        fatal "Have no suitable command for $PMTYPE"
299
        ;;
300
esac
301

302
}
303

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

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

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

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