epm-removerepo 3.84 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
		rl="$( (epm --quiet repolist) 2>/dev/null | grep -E "$1")"
31 32
		[ -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 <regexp|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

case $DISTRNAME in
97
	ALTLinux|ALTServer)
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
107 108 109 110 111 112 113 114 115 116 117 118

		if [ "$DISTRNAME" = "AstraLinux" ] ; then
			echo "Use workaround for AstraLinux"
			[ -n "$*" ] || fatal "empty repo name"
			# aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for AstraLinuxCE/orel
			sudocmd sed -i -e "s|.*$*.*||" /etc/apt/sources.list
			if [ -d /etc/apt/sources.list.d ] && ls /etc/apt/sources.list.d/*.list >/dev/null 2>/dev/null ; then
				sudocmd sed -i -e "s|.*$*.*||" /etc/apt/sources.list.d/*.list
			fi
			exit
		fi

Vitaly Lipatov's avatar
Vitaly Lipatov committed
119 120
		# FIXME: it is possible there is troubles to pass the args
		sudocmd apt-add-repository --remove "$*"
121 122 123
		info "Check file /etc/apt/sources.list if needed"
		;;
	aptitude-dpkg)
124
		info "You need remove repo from /etc/apt/sources.list"
125 126
		;;
	yum-rpm)
127
		assure_exists yum-utils
128
		sudocmd yum-config-manager --disable "$@"
129 130
		;;
	urpm-rpm)
131
		sudocmd urpmi.removemedia "$@"
132
		;;
133
	zypper-rpm)
134
		sudocmd zypper removerepo "$@"
135 136
		;;
	emerge)
137
		sudocmd layman "-d$@"
138 139
		;;
	pacman)
140
		info "You need remove repo from /etc/pacman.conf"
141
		;;
142
	npackd)
143
		sudocmd npackdcl remove-repo --url="$@"
144
		;;
145 146 147
	winget)
		sudocmd winget source remove "$@"
		;;
148
	slackpkg)
149
		info "You need remove repo from /etc/slackpkg/mirrors"
150 151
		;;
	*)
152
		fatal "Have no suitable command for $PMTYPE"
153 154 155 156
		;;
esac

}