epm-requires 3.06 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012-2013, 2016, 2018, 2019  Etersoft
# Copyright (C) 2012-2013, 2016, 2018, 2019  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
	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
64
		;;
65
	packagekit)
66
		CMD="pkcon required-by"
67
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
68 69 70 71 72 73
	#zypper-rpm)
	#	# FIXME: use hi level commands
	#	CMD="rpm -q --requires"
	#	;;
	urpm-rpm)
		CMD="urpmq --requires"
74 75
		;;
	yum-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
76 77 78 79 80 81 82 83 84 85 86 87
		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
88
		;;
89 90 91
	pacman)
		CMD="pactree"
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
92
	apt-dpkg|aptitude-dpkg)
93 94 95
		# 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
96
			a='' dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g"
97 98 99 100
			return
		else
			CMD="apt-cache depends"
		fi
101
		;;
102 103 104 105
	emerge)
		assure_exists equery
		CMD="equery depgraph"
		;;
106
	homebrew)
107 108
		#docmd brew info $pkg_names | grep "^Required: " | sed -s "|s|^Requires: ||"
		docmd brew deps $pkg_names
109 110
		return
		;;
111 112 113 114
	pkgng)
		#CMD="pkg rquery '%dn-%dv'"
		CMD="pkg info -d"
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
115 116 117
	opkg)
		CMD="opkg depends"
		;;
118 119 120
	xbps)
		CMD="xbps-query -x"
		;;
121 122 123 124 125 126
	aptcyg)
		#CMD="apt-cyg depends"
		# print show version
		docmd apt-cyg show $pkg_names | grep "^requires: " | sed "s|^requires: ||g"
		return
		;;
127
	*)
128
		fatal "Have no suitable command for $PMTYPE"
129 130 131 132
		;;
esac


133
docmd $CMD $pkg_names
134 135

}
136 137 138

epm_requires()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
139
	[ -n "$pkg_filenames" ] || fatal "Requires: package name is missed"
140
	epm_requires_files $pkg_files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
141
	# shellcheck disable=SC2046
142
	epm_requires_names $(print_name $pkg_names)
143
}