epm-repofix 2.93 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2015-2016  Etersoft
# Copyright (C) 2015-2016  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 43 44 45 46 47 48
# 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
			warning "Skip set $br vendor key (it misssed) for $list"
			regexp_subst "/$path/s/^rpm[[:space:]]*\[$br\][[:space:]]*([fhr])/rpm \1/" $list
		fi
	fi
}

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

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

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

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

Vitaly Lipatov's avatar
Vitaly Lipatov committed
75
epm_repofix()
76
{
77 78 79

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

80 81 82
case $PMTYPE in
	apt-rpm)
		assure_exists apt-repo
83
		[ -n "$quiet" ] || docmd apt-repo list
84 85
		__fix_apt_sources_list /etc/apt/sources.list
		__fix_apt_sources_list /etc/apt/sources.list.d/*.list
Vitaly Lipatov's avatar
Vitaly Lipatov committed
86
		docmd apt-repo list
87
		# FIXME: what the best place?
88 89 90 91 92
		# rebuild rpm database
		#sudocmd rm -fv /var/lib/rpm/__db*
		#sudocmd rpm --rebuilddb
		;;
	yum-rpm|dnf-rpm)
93 94 95 96 97 98
		# FIXME: what the best place?
		#sudocmd rm -fv /var/lib/rpm/__db*
		#sudocmd rpm --rebuilddb
		;;
	xbps)
		sudocmd xbps-pkgdb -a
99 100 101 102 103 104 105
		;;
	*)
		fatal "Have no suitable command for $PMTYPE"
		;;
esac

}