epm-requires 4.1 KB
Newer Older
1 2
#!/bin/sh
#
3 4
# Copyright (C) 2012-2013, 2016, 2018, 2019, 2022  Etersoft
# Copyright (C) 2012-2013, 2016, 2018, 2019, 2022  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 24 25 26 27 28 29 30 31 32 33 34 35 36 37
__epm_filter_out_base_alt_reqs()
{
	grep -E -v "(^rpmlib\(|^/bin/sh|^/bin/bash|^rtld\(GNU_HASH\)|ld-linux)"
}

__epm_alt_rpm_requires()
{
	if [ -n "$short" ] ; then
		# TODO see also rpmreqs from etersoft-build-utils
		docmd rpm -q --requires "$@" | __epm_filter_out_base_alt_reqs | sed -e "s| .*||"
	else
		docmd rpm -q --requires "$@" | __epm_filter_out_base_alt_reqs
	fi
}

38
epm_requires_files()
39
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
40
	local pkg_files="$*"
41
	[ -n "$pkg_files" ] || return
42

Vitaly Lipatov's avatar
Vitaly Lipatov committed
43
	local PKGTYPE="$(get_package_type $pkg_files)"
Vitaly Lipatov's avatar
Vitaly Lipatov committed
44 45

	case "$PKGTYPE" in
46
		rpm)
47
			assure_exists rpm >/dev/null
48
			__epm_alt_rpm_requires -p $pkg_files
49 50
			;;
		deb)
51
			assure_exists dpkg >/dev/null
Vitaly Lipatov's avatar
Vitaly Lipatov committed
52
			a='' docmd dpkg -I $pkg_files | grep "^ *Depends:" | sed "s|^ *Depends:||g"
53
			;;
54 55 56 57
		eopkg)
			showcmd eopkg info $pkg_files
			a= eopkg info $pkg_files | grep "^Dependencies" | head -n1 | sed -e "s|Dependencies[[:space:]]*: ||"
			;;
58
		*)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
59
			fatal "Have no suitable command for $PKGTYPE"
60 61 62
			;;
	esac
}
63

64 65
epm_requires_names()
{
66
	local pkg_names="$*"
67 68
	local CMD
	[ -n "$pkg_names" ] || return
69

70
# by package name
71
case $PMTYPE in
72 73 74 75
	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
76 77 78
			assure_exists rpm >/dev/null
			__epm_alt_rpm_requires $pkg_names
			return
79
		else
80 81 82 83 84 85 86 87 88 89
			if [ -n "$verbose" ] ; then
				CMD="apt-cache depends"
			else
				if [ -n "$short" ] ; then
					LANG=C docmd apt-cache depends $pkg_names | grep "Depends:" | sed -e "s|.*Depends: ||" -e "s|<\(.*\)>|\1|" | __epm_filter_out_base_alt_reqs | sed -e "s| .*||"
				else
					LANG=C docmd apt-cache depends $pkg_names | grep "Depends:" | sed -e "s|.*Depends: ||" -e "s|<\(.*\)>|\1|" | __epm_filter_out_base_alt_reqs
				fi
				return
			fi
90
		fi
91
		;;
92
	packagekit)
93
		CMD="pkcon required-by"
94
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
95 96 97 98 99 100
	#zypper-rpm)
	#	# FIXME: use hi level commands
	#	CMD="rpm -q --requires"
	#	;;
	urpm-rpm)
		CMD="urpmq --requires"
101 102
		;;
	yum-rpm)
Vitaly Lipatov's avatar
Vitaly Lipatov committed
103 104 105 106 107 108 109 110 111 112 113 114
		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
115
		;;
116 117 118
	pacman)
		CMD="pactree"
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
119
	apt-dpkg|aptitude-dpkg)
120 121 122
		# 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
123
			a='' dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g"
124 125 126 127
			return
		else
			CMD="apt-cache depends"
		fi
128
		;;
129 130 131 132
	emerge)
		assure_exists equery
		CMD="equery depgraph"
		;;
133
	homebrew)
134 135
		#docmd brew info $pkg_names | grep "^Required: " | sed -s "|s|^Requires: ||"
		docmd brew deps $pkg_names
136 137
		return
		;;
138 139 140 141
	pkgng)
		#CMD="pkg rquery '%dn-%dv'"
		CMD="pkg info -d"
		;;
Vitaly Lipatov's avatar
Vitaly Lipatov committed
142 143 144
	opkg)
		CMD="opkg depends"
		;;
145 146 147 148 149
	eopkg)
		showcmd eopkg info $pkg_names
		a= eopkg info $pkg_names | grep "^Dependencies" | sed -e "s|Dependencies[[:space:]]*: ||"
		return
		;;
150 151 152
	xbps)
		CMD="xbps-query -x"
		;;
153 154 155 156 157 158
	aptcyg)
		#CMD="apt-cyg depends"
		# print show version
		docmd apt-cyg show $pkg_names | grep "^requires: " | sed "s|^requires: ||g"
		return
		;;
159
	*)
160
		fatal "Have no suitable command for $PMTYPE"
161 162 163 164
		;;
esac


165
docmd $CMD $pkg_names
166 167

}
168 169 170

epm_requires()
{
Vitaly Lipatov's avatar
Vitaly Lipatov committed
171
	[ -n "$pkg_filenames" ] || fatal "Requires: package name is missed"
172
	epm_requires_files $pkg_files
Vitaly Lipatov's avatar
Vitaly Lipatov committed
173
	# shellcheck disable=SC2046
174
	epm_requires_names $(print_name $pkg_names)
175
}