epm-removerepo 3.35 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012, 2017, 2020, 2021  Etersoft
# Copyright (C) 2012, 2017, 2020, 2021  Vitaly Lipatov <lav@etersoft.ru>
5
#
6 7 8
# 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
9 10 11 12 13
# (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
14
# GNU Affero General Public License for more details.
15
#
16 17
# 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/>.
18 19
#

20 21
load_helper epm-sh-altlinux

Vitaly Lipatov's avatar
Vitaly Lipatov committed
22 23 24
# remove grepped lines
__epm_removerepo_alt_grepremove()
{
25
	local rl
26 27 28 29
	# ^rpm means full string
	if [ "$1" = "all" ] || rhas "$1" "^rpm" ; then
		rl="$1"
	else
30 31 32
		rl="$((quiet=1 epm repolist) 2>/dev/null | grep -E "$1")"
		[ -z "$rl" ] && warning "Can't find '$1' in the repos (see '# epm repolist' output)" && return 1
	fi
33
	echo "$rl" | while read rp ; do
Vitaly Lipatov's avatar
Vitaly Lipatov committed
34
		# TODO: print removed lines
35 36 37 38
		if [ -n "$dryrun" ] ; then
			docmd apt-repo $dryrun rm "$rp"
			continue
		fi
39 40 41
		if [ -n "$verbose" ] ; then
			sudocmd apt-repo $dryrun rm "$rp"
		else
42
			sudorun apt-repo $dryrun rm "$rp"
43
		fi
Vitaly Lipatov's avatar
Vitaly Lipatov committed
44 45 46 47 48 49
	done
}

__epm_removerepo_alt()
{
	local repo="$*"
50
	[ -n "$repo" ] || fatal "No such repo or task. Use epm repo remove <autoimports|archive|tasks|TASKNUMBER>"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

	assure_exists apt-repo

	if tasknumber "$repo" >/dev/null ; then
		local tn
		for tn in $(tasknumber "$repo") ; do
			__epm_removerepo_alt_grepremove " repo/$tn/"
		done
		return
	fi

	case "$1" in
		autoimports)
			info "remove autoimports repo"
			[ -n "$DISTRVERSION" ] || fatal "Empty DISTRVERSION"
			repo="autoimports.$(echo "$DISTRVERSION" | tr "[:upper:]" "[:lower:]")"
67
			sudocmd apt-repo $dryrun rm "$repo"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
68 69 70 71 72 73 74 75 76 77 78 79 80
			;;
		archive)
			info "remove archive repos"
			__epm_removerepo_alt_grepremove "archive/"
			;;
		tasks)
			info "remove task repos"
			__epm_removerepo_alt_grepremove " repo/[0-9]+/"
			;;
		task)
			shift
			__epm_removerepo_alt_grepremove " repo/$1/"
			;;
81 82 83
		-*)
			fatal "epm removerepo: no options are supported"
			;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
84
		*)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
85
# TODO: if return empty for whole line, use grep
86 87
#			sudocmd apt-repo $dryrun rm "$*"
			__epm_removerepo_alt_grepremove "$*"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
88 89 90 91 92
			;;
	esac

}

93 94
epm_removerepo()
{
95 96 97

case $DISTRNAME in
	ALTLinux)
98
		__epm_removerepo_alt "$@"
99
		return
100
		;;
101 102 103
esac;

case $PMTYPE in
104 105
	apt-dpkg)
		assure_exists apt-add-repository software-properties-common
106
		set_sudo
Vitaly Lipatov's avatar
Vitaly Lipatov committed
107 108
		# FIXME: it is possible there is troubles to pass the args
		sudocmd apt-add-repository --remove "$*"
109 110 111
		info "Check file /etc/apt/sources.list if needed"
		;;
	aptitude-dpkg)
112
		info "You need remove repo from /etc/apt/sources.list"
113 114
		;;
	yum-rpm)
115
		assure_exists yum-utils
116
		sudocmd yum-config-manager --disable "$@"
117 118
		;;
	urpm-rpm)
119
		sudocmd urpmi.removemedia "$@"
120
		;;
121
	zypper-rpm)
122
		sudocmd zypper removerepo "$@"
123 124
		;;
	emerge)
125
		sudocmd layman "-d$@"
126 127
		;;
	pacman)
128
		info "You need remove repo from /etc/pacman.conf"
129
		;;
130
	npackd)
131
		sudocmd npackdcl remove-repo --url="$@"
132
		;;
133 134 135
	winget)
		sudocmd winget source remove "$@"
		;;
136
	slackpkg)
137
		info "You need remove repo from /etc/slackpkg/mirrors"
138 139
		;;
	*)
140
		fatal "Have no suitable command for $PMTYPE"
141 142 143 144
		;;
esac

}