epm-repofix 3.49 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2015-2016, 2020  Etersoft
# Copyright (C) 2015-2016, 2020  Vitaly Lipatov <lav@etersoft.ru>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

20
load_helper epm-query
21

22 23 24 25 26 27 28 29 30 31
__repofix_check_vendor()
{
	local i
	for i in /etc/apt/vendors.list.d/*.list; do
		[ -e "$i" ] || continue
		grep -q "^simple-key \"$1\"" $i && return
	done
	return 1
}

32 33 34 35 36 37 38 39 40 41 42
# source-list vendor path
# example: /etc/apt/source.list p7 ALTLinux\/Sisyphus
__try_fix_apt_source_list()
{
	local list="$1"
	local br="$2"
	local path="$3"
	if grep -q -e "^[^#].*$path" $list ; then
		if __repofix_check_vendor $br ; then
			regexp_subst "/$path/s/^rpm[[:space:]]*([fhr])/rpm [$br] \1/" $list
		else
Vitaly Lipatov's avatar
Vitaly Lipatov committed
43
			warning "Skip set $br vendor key (it is missed) for $list"
44 45 46 47 48
			regexp_subst "/$path/s/^rpm[[:space:]]*\[$br\][[:space:]]*([fhr])/rpm \1/" $list
		fi
	fi
}

49
__fix_alt_sources_list()
50
{
51
	# for beauty spaces
52 53
	local SUBST_ALT_RULE1='s!^(.*)[/ ](ALTLinux|LINUX\@Etersoft)[/ ]*(Sisyphus)[/ ](x86_64|i586|x86_64-i586|noarch) !\1 \2/\3/\4 !gi'
	local SUBST_ALT_RULE2='s!^(.*)[/ ](ALTLinux|LINUX\@Etersoft)[/ ]*([tcp][6-9][/ ]branch|[tcp]1[012][/ ]branch)[/ ](x86_64|i586|x86_64-i586|noarch) !\1 \2/\3/\4 !gi'
Vitaly Lipatov's avatar
Vitaly Lipatov committed
54 55
	local i
	assure_root
56 57
	for i in "$@" ; do
		[ -s "$i" ] || continue
58
		#perl -i.bak -pe "$SUBST_ALT_RULE" $i
Vitaly Lipatov's avatar
Vitaly Lipatov committed
59 60
		# TODO: only for uncommented strings
		#sed -i -r -e "$SUBST_ALT_RULE" $i
61 62
		regexp_subst "/^ *#/! $SUBST_ALT_RULE1" $i
		regexp_subst "/^ *#/! $SUBST_ALT_RULE2" $i
63

64
		# Sisyphus uses 'alt' vendor key
65
		__try_fix_apt_source_list $i alt "ALTLinux\/Sisyphus"
66
		__try_fix_apt_source_list $i etersoft "Etersoft\/Sisyphus"
67 68 69 70

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

71
		# add signs for branches
72 73
		__try_fix_apt_source_list $i $DISTRVERSION "ALTLinux\/$DISTRVERSION\/branch"
		__try_fix_apt_source_list $i etersoft "Etersoft\/$DISTRVERSION\/branch"
74 75 76
	done
}

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
__subst_with_etersoft_url()
{
	local NURL="http://download.etersoft.ru/pub ALTLinux"
	echo "$1" | sed \
		-e "s|h\?f\?t\?tp://ftp.altlinux.org/pub/distributions ALTLinux|$NURL|" \
		-e "s|h\?f\?t\?tp://mirror.yandex.ru altlinux|$NURL|"
}

__fix_repo_to_etersoft()
{
	local NN
	apt-repo list | grep -v debuginfo | grep -v etersoft | grep -v "file:/" | while read nn ; do
		NN="$(__subst_with_etersoft_url "$nn")"
		epm addrepo "$NN"
		epm removerepo "$nn"
	done
}

Vitaly Lipatov's avatar
Vitaly Lipatov committed
95
epm_repofix()
96
{
97 98


99 100
case $DISTRNAME in
	ALTLinux)
101
		assure_exists apt-repo
102
		[ -n "$quiet" ] || docmd apt-repo list
103 104
		__fix_alt_sources_list /etc/apt/sources.list
		__fix_alt_sources_list /etc/apt/sources.list.d/*.list
105 106 107 108
		if [ "$pkg_filenames" = "etersoft" ] ; then
			__fix_repo_to_etersoft /etc/apt/sources.list
			__fix_repo_to_etersoft /etc/apt/sources.list.d/*.list
		fi
Vitaly Lipatov's avatar
Vitaly Lipatov committed
109
		docmd apt-repo list
110
		return
111
		;;
112 113
esac

114 115
[ -z "$pkg_filenames" ] || fatal "No arguments are allowed here"

116 117 118 119 120
case $PMTYPE in
#	apt-rpm)
#		;;
#	yum-rpm|dnf-rpm)
#		;;
121 122 123 124 125 126
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}