epm-provides 2.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/bin/sh
#
# Copyright (C) 2013  Etersoft
# Copyright (C) 2013  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/>.
#

Vitaly Lipatov's avatar
Vitaly Lipatov committed
20
load_helper epm-query
21
load_helper epm-print
Vitaly Lipatov's avatar
Vitaly Lipatov committed
22

23
epm_provides_files()
24
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
25
	local pkg_files="$*"
26
	[ -n "$pkg_files" ] || return
27

Vitaly Lipatov's avatar
Vitaly Lipatov committed
28 29 30
	local PKGTYPE="$(get_package_type $pkg_files)"

	case $PKGTYPE in
31
		rpm)
32
			assure_exists rpm
33
			docmd rpm -q --provides -p $pkg_files
34
			;;
35
		deb)
36
			assure_exists dpkg
37 38 39
			# FIXME: will we provide ourself?
			docmd dpkg -I $pkg_files | grep "^ *Provides:" | sed "s|^ *Provides:||g"
			;;
40 41 42 43 44
		*)
			fatal "Have no suitable command for $PMTYPE"
			;;
	esac
}
45

46 47 48

epm_provides_names()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
49
	local pkg_names="$*"
50 51
	local CMD
	[ -n "$pkg_names" ] || return
52 53 54 55

# by package name
case $PMTYPE in
	apt-rpm)
56 57
		# FIXME: need fix for a few names case
		# TODO: separate this function to two section
58 59 60
		if is_installed $pkg_names ; then
			CMD="rpm -q --provides"
		else
61 62 63
			EXTRA_SHOWDOCMD=' | grep "Provides:"'
			docmd apt-cache show $pkg_names | grep "Provides:"
			return
64 65
		fi
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
66
	urpm-rpm|zypper-rpm|yum-rpm|dnf-rpm)
67 68 69
		if is_installed $pkg_names ; then
			CMD="rpm -q --provides"
		else
70
			fatal "FIXME: use hi level commands"
71 72
		fi
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
73
	emerge)
74
		assure_exists equery
Vitaly Lipatov's avatar
Vitaly Lipatov committed
75 76
		CMD="equery files"
		;;
77 78 79
#	yum-rpm)
#		CMD="yum deplist"
#		;;
80 81 82
	pkgng)
		CMD="pkg info -b"
		;;
83 84 85
	apt-dpkg)
		# FIXME: need fix for a few names case
		if is_installed $pkg_names ; then
86 87 88 89
			showcmd dpkg -s $pkg_names
			a='' dpkg -s $pkg_names | grep "^Provides:" | sed "s|^Provides:||g"
			return
		else
90
			EXTRA_SHOWDOCMD=' | grep "Provides:"'
91
			docmd apt-cache show $pkg_names | grep "Provides:" | sed -e 's|, |\n|g' | grep -v "^Provides:"
92
			return
93
		fi
94
		;;
95
	*)
96
		fatal "Have no suitable command for $PMTYPE"
97 98 99
		;;
esac

100
docmd $CMD $pkg_names
101 102

}
103 104 105

epm_provides()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
106
	[ -n "$pkg_filenames" ] || fatal "Provides: package name is missed"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
107

108
	epm_provides_files $pkg_files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
109
	# shellcheck disable=SC2046
110
	epm_provides_names $(print_name $pkg_names)
111
}