epm-requires 2.83 KB
Newer Older
1 2
#!/bin/sh
#
Vitaly Lipatov's avatar
Vitaly Lipatov committed
3 4
# Copyright (C) 2012-2013, 2016  Etersoft
# Copyright (C) 2012-2013, 2016  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
load_helper epm-query
21
load_helper epm-print
22

23
epm_requires_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
	local PKGTYPE="$(get_package_type $pkg_files)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
29 30

	case "$PKGTYPE" in
31
		rpm)
32
			assure_exists rpm
33
			docmd rpm -q --requires -p $pkg_files
34 35
			;;
		deb)
36
			assure_exists dpkg
Vitaly Lipatov's avatar
Vitaly Lipatov committed
37
			a='' docmd dpkg -I $pkg_files | grep "^ *Depends:" | sed "s|^ *Depends:||g"
38 39
			;;
		*)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
40
			fatal "Have no suitable command for $PKGTYPE"
41 42 43
			;;
	esac
}
44

45 46
epm_requires_names()
{
47
	local pkg_names="$*"
48 49
	local CMD
	[ -n "$pkg_names" ] || return
50

51
# by package name
52
case $PMTYPE in
53 54 55 56 57 58 59 60 61 62 63 64 65
	apt-rpm)
		# FIXME: need fix for a few names case
		# FIXME: too low level of requires name (libSOME.so)
		if is_installed $pkg_names ; then
			CMD="rpm -q --requires"
		else
			#EXTRA_SHOWDOCMD=' | grep "Depends:"'
			#docmd apt-cache show $pkg_names | grep "Depends:"
			#return
			CMD="apt-cache depends"
		fi

		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
66 67 68 69 70 71
	#zypper-rpm)
	#	# FIXME: use hi level commands
	#	CMD="rpm -q --requires"
	#	;;
	urpm-rpm)
		CMD="urpmq --requires"
72 73
		;;
	yum-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
74 75 76 77 78 79 80 81 82 83 84 85
		if is_installed $pkg_names ; then
			CMD="rpm -q --requires"
		else
			CMD="yum deplist"
		fi
		;;
	dnf-rpm)
		if is_installed $pkg_names ; then
			CMD="rpm -q --requires"
		else
			CMD="dnf repoquery --requires"
		fi
86
		;;
87 88 89
	pacman)
		CMD="pactree"
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
90
	apt-dpkg|aptitude-dpkg)
91 92 93
		# FIXME: need fix for a few names case
		if is_installed $pkg_names ; then
			showcmd dpkg -s $pkg_names
Vitaly Lipatov's avatar
Vitaly Lipatov committed
94
			a='' dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g"
95 96 97 98
			return
		else
			CMD="apt-cache depends"
		fi
99
		;;
100 101 102 103
	emerge)
		assure_exists equery
		CMD="equery depgraph"
		;;
104 105 106 107
	pkgng)
		#CMD="pkg rquery '%dn-%dv'"
		CMD="pkg info -d"
		;;
108 109 110
	xbps)
		CMD="xbps-query -x"
		;;
111 112 113 114 115 116
	aptcyg)
		#CMD="apt-cyg depends"
		# print show version
		docmd apt-cyg show $pkg_names | grep "^requires: " | sed "s|^requires: ||g"
		return
		;;
117
	*)
118
		fatal "Have no suitable command for $PMTYPE"
119 120 121 122
		;;
esac


123
docmd $CMD $pkg_names
124 125

}
126 127 128

epm_requires()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
129
	[ -n "$pkg_filenames" ] || fatal "Requires: missing package(s) name"
130
	epm_requires_files $pkg_files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
131
	# shellcheck disable=SC2046
132
	epm_requires_names $(print_name $pkg_names)
133
}