1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/sh
#
# Copyright (C) 2012-2013, 2016, 2018, 2019, 2022 Etersoft
# Copyright (C) 2012-2013, 2016, 2018, 2019, 2022 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/>.
#
load_helper epm-query
load_helper epm-print
__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
}
get_linked_shared_libs()
{
assure_exists readelf binutils
#is_command readelf || fatal "Can't get required shared library: readelf is missed. Try install binutils package."
#ldd "$exe" | sed -e 's|[[:space:]]*||' | grep "^lib.*[[:space:]]=>[[:space:]]\(/usr/lib\|/lib\)" | sed -e 's|[[:space:]].*||'
LC_ALL=C readelf -d "$1" | grep "(NEEDED)" | grep "Shared library:" | sed -e 's|.*Shared library: \[||' -e 's|\]$||' | grep "^lib"
}
__epm_elf32_requires()
{
get_linked_shared_libs "$1"
}
__epm_elf64_requires()
{
get_linked_shared_libs "$1" | sed -e 's|$|()(64bit)|'
}
__epm_elf_requires()
{
local i
if [ -n "$direct" ] ; then
for i in $* ; do
get_linked_shared_libs $i
done
return
fi
for i in $* ; do
if file -L "$i" | grep -q " ELF 32-bit " ; then
__epm_elf32_requires "$i"
elif file -L "$i" | grep -q " ELF 64-bit " ; then
__epm_elf64_requires "$i"
else
warning "Unknown ELF binary"
fi
done
}
epm_requires_files()
{
local pkg_files="$*"
[ -n "$pkg_files" ] || return
local fl
for fl in $pkg_files ; do
local PKGTYPE="$(get_package_type $fl)"
case "$PKGTYPE" in
rpm)
assure_exists rpm >/dev/null
__epm_alt_rpm_requires -p $fl
;;
deb)
assure_exists dpkg >/dev/null
a='' docmd dpkg -I $fl | grep "^ *Depends:" | sed "s|^ *Depends:||g"
;;
eopkg)
showcmd eopkg info $fl
LC_ALL=C a='' eopkg info $fl | grep "^Dependencies" | head -n1 | sed -e "s|Dependencies[[:space:]]*: ||"
;;
ELF)
__epm_elf_requires $fl
;;
*)
warning "Have no suitable command for handle file $fl with .$PKGTYPE"
;;
esac
done
}
epm_requires_names()
{
local pkg_names="$*"
local CMD
[ -n "$pkg_names" ] || return
# by package name
case $PMTYPE in
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
assure_exists rpm >/dev/null
__epm_alt_rpm_requires $pkg_names
return
else
if [ -n "$verbose" ] ; then
CMD="apt-cache depends"
else
if [ -n "$short" ] ; then
LC_ALL=C docmd apt-cache depends $pkg_names | grep "Depends:" | sed -e 's|, |\n|g' -e "s|.*Depends: ||" -e "s|<\(.*\)>|\1|" | __epm_filter_out_base_alt_reqs | sed -e "s| .*||"
else
LC_ALL=C docmd apt-cache depends $pkg_names | grep "Depends:" | sed -e 's|, |\n|g' -e "s|.*Depends: ||" -e "s|<\(.*\)>|\1|" | __epm_filter_out_base_alt_reqs
fi
return
fi
fi
;;
packagekit)
CMD="pkcon required-by"
;;
#zypper-rpm)
# # FIXME: use hi level commands
# CMD="rpm -q --requires"
# ;;
urpm-rpm)
CMD="urpmq --requires"
;;
yum-rpm)
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
;;
pacman)
CMD="pactree"
;;
apt-dpkg|aptitude-dpkg)
# FIXME: need fix for a few names case
if is_installed $pkg_names ; then
showcmd dpkg -s $pkg_names
a='' dpkg -s $pkg_names | grep "^Depends:" | sed "s|^Depends:||g"
return
else
CMD="apt-cache depends"
fi
;;
emerge)
assure_exists equery
CMD="equery depgraph"
;;
homebrew)
#docmd brew info $pkg_names | grep "^Required: " | sed -s "|s|^Requires: ||"
docmd brew deps $pkg_names
return
;;
pkgng)
#CMD="pkg rquery '%dn-%dv'"
CMD="pkg info -d"
;;
opkg)
CMD="opkg depends"
;;
eopkg)
showcmd eopkg info $pkg_names
LC_ALL=C a='' eopkg info $pkg_names | grep "^Dependencies" | sed -e "s|Dependencies[[:space:]]*: ||"
return
;;
xbps)
CMD="xbps-query -x"
;;
aptcyg)
#CMD="apt-cyg depends"
# print show version
docmd apt-cyg show $pkg_names | grep "^requires: " | sed "s|^requires: ||g"
return
;;
*)
fatal 'Have no suitable command for $PMTYPE'
;;
esac
docmd $CMD $pkg_names
}
epm_requires()
{
# if possible, it will put pkg_urls into pkg_files or pkg_names
if [ -n "$pkg_urls" ] ; then
load_helper epm-download
__handle_pkg_urls_to_checking
fi
[ -n "$pkg_filenames" ] || fatal "Requires: package name is missed"
epm_requires_files $pkg_files
# shellcheck disable=SC2046
epm_requires_names $(print_name $pkg_names)
}