epm-commentrepo 2.41 KB
Newer Older
Vitaly Lipatov's avatar
Vitaly Lipatov committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
#!/bin/sh
#
# Copyright (C) 2012, 2017, 2020, 2021, 2022  Etersoft
# Copyright (C) 2012, 2017, 2020, 2021, 2022  Vitaly Lipatov <lav@etersoft.ru>
#
# 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/>.
#

load_helper epm-sh-altlinux
load_helper epm-repofix

# remove grepped lines
__epm_commentrepo_alt_grepremove()
{
	local rl
	__replace_text_in_alt_repo "/^ *#/! s! *(.*$1)!# \1!g"
	exit
	# TODO
	# ^rpm means full string
	if rhas "$1" "^rpm" ; then
		rl="$1"
	else
		rl="$( (epm --quiet repo list) 2>/dev/null | grep -E "$1")"
		[ -z "$rl" ] && warning "Can't find '$1' in the repos (see '# epm repolist' output)" && return 1
	fi
	echo "$rl" | while read rp ; do
		if [ -n "$dryrun" ] ; then
			echo "$rp" | grep -E --color -- "$1"
			continue
		fi
		#if [ -n "$verbose" ] ; then
		#	sudocmd apt-repo $dryrun rm "$rp"
		#else
		__replace_text_in_alt_repo "s! *$rp!# $rp!g"
		#fi
	done
}

__epm_commentrepo_alt()
{
	local repo="$*"
	[ -n "$repo" ] || fatal "No such repo or task. Use epm repo comment <regexp|archive|tasks|TASKNUMBER>"

	assure_exists apt-repo

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

	case "$1" in
		archive)
			info "remove archive repos"
			__epm_commentrepo_alt_grepremove "archive/"
			;;
		tasks)
			info "remove task repos"
			__epm_commentrepo_alt_grepremove " repo/[0-9]+/"
			;;
		task)
			shift
			__epm_commentrepo_alt_grepremove " repo/$1/"
			;;
		-*)
			fatal "epm commentrepo: no options are supported"
			;;
		*)
# TODO: if return empty for whole line, use grep
#			sudocmd apt-repo $dryrun rm "$*"
			__epm_commentrepo_alt_grepremove "$*"
			;;
	esac

}

epm_commentrepo()
{

case $DISTRNAME in
	ALTLinux|ALTServer)
		__epm_commentrepo_alt "$@"
		return
		;;
esac;

fatal "Have no suitable command for $PMTYPE"

}