epm-provides 2.4 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 21
load_helper epm-query

22
epm_provides_files()
23
{
24
	local pkg_files="$@"
25
	[ -n "$pkg_files" ] || return
26

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

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

45 46 47

epm_provides_names()
{
48
	local pkg_names="$@"
49 50
	local CMD
	[ -n "$pkg_names" ] || return
51 52 53 54

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

99
docmd $CMD $pkg_names
100 101

}
102 103 104

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

107 108
	epm_provides_files $pkg_files
	epm_provides_names $pkg_names $pkg_dirs
109
}