3
# Copyright (C) 2015-2016, 2020, 2021 Etersoft
4
# Copyright (C) 2015-2016, 2020, 2021 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/>.
23
__replace_text_in_alt_repo()
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"
34
__repofix_check_vendor()
37
for i in /etc/apt/vendors.list.d/*.list; do
38
[ -e "$i" ] || continue
39
grep -q "^simple-key \"$1\"" $i && return
44
__repofix_filter_vendor()
47
br="$(echo "$br" | sed -e "s|\..*||")"
63
__replace_alt_version_in_repo()
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"
76
__alt_replace_sign_name()
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"
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]"
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/"
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/"
117
if [ "$TO" = "p10" ] ; then
118
echo '%_priority_distbranch p10' >/etc/rpm/macros.d/p10
120
rm -fv /etc/rpm/macros.d/p10
126
# source-list vendor path
127
# example: /etc/apt/source.list p7 ALTLinux\/Sisyphus
128
__try_fix_apt_source_list()
131
local br="$(__repofix_filter_vendor "$2")"
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
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
143
__fix_alt_sources_list()
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'
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
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"
163
# skip branch replacement for ALT Linux Sisyphus
164
[ "$DISTRVERSION" = "Sisyphus" ] && continue
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"
172
__subst_with_etersoft_url()
174
local NURL="http://download.etersoft.ru/pub ALTLinux"
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|"
182
__subst_with_eterfund_url()
184
local NURL="https://mirror.eterfund.org/download.etersoft.ru/pub ALTLinux"
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|"
191
__subst_with_yandex_url()
193
local NURL="http://mirror.yandex.ru altlinux"
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|"
202
__subst_with_basealt_url()
204
local NURL="http://ftp.basealt.ru/pub/distributions ALTLinux"
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|"
212
__subst_with_altlinux_url()
214
local NURL="http://ftp.altlinux.org/pub/distributions ALTLinux"
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|"
222
__fix_repo_to_etersoft()
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
233
__fix_repo_to_yandex()
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
244
__fix_repo_to_basealt()
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
259
case $BASEDISTRNAME in
261
assure_exists apt-repo
262
[ -n "$quiet" ] || docmd apt-repo list
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
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
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
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
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
298
fatal "Have no suitable command for $PMTYPE"