3
# Copyright (C) 2012, 2013, 2015-2017 Etersoft
4
# Copyright (C) 2012, 2013, 2015-2017 Vitaly Lipatov <lav@etersoft.ru>
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU Affero General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU Affero General Public License for more details.
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
load_helper epm-packages
24
__print_with_arch_suffix()
28
[ -n "$pkg" ] || return 1
29
# do not change if some suffix already exists
30
echo "$pkg" | grep -q "(x86-32)$" && echo "$pkg" | sed -e "s|(x86-32)$|.i686|" && return 1
31
echo "$pkg" | grep "\.x86_64$" && return 1
32
echo "$pkg" | grep "\.noarch$" && return 1
33
echo "$pkg" | grep "\.i[56]86$" && return 1
37
# add suffix .x86_64 if we have 64 arch
42
[ "$DISTRARCH" = "x86_64" ] || { cat ; return ; }
43
[ "$DISTRNAME" = "ROSA" ] && { cat ; return ; }
45
# TODO: it is ok for ALT rpm to remove with this suffix
46
# TODO: separate install and remove?
57
# TODO: use estrlist or some function to do it
59
for pkg in $(cat) ; do
61
# check only packages without arch
62
p="$(__print_with_arch_suffix "$pkg" .i686)" || { echo "$pkg" ; continue ; }
63
# add arch suffix only if arch package already installed (otherwise we don't know package arch)
64
is_installed "$p" || { echo "$pkg" ; continue ; }
73
[ "$PMTYPE" != "emerge" ] && echo "$def" && return
74
# Gentoo hack: support for short package form
75
echo "$1" | grep -q "/" && echo "$def" && return
79
# TODO: combine with -qa (the difference only in return status now)
80
_shortquery_via_packages_list()
87
grepexp=$(_get_grep_exp $firstpkg)
89
# TODO: we miss status due grep
90
# Note: double call due stderr redirect
91
# Note: we use short=1 here due grep by ^name$
92
# separate first line for print out command
93
(short=1 epm_packages $firstpkg | grep -- "$grepexp") && res=0 || res=1
97
grepexp=$(_get_grep_exp $pkg)
98
(short=1 epm_packages $pkg 2>/dev/null) | grep -- "$grepexp" || res=1
101
# TODO: print in query (for user): 'warning: package $pkg is not installed'
105
# Note: modified from _shortquery_via_packages_list
106
# TODO: non optimal double epm packages call
107
_query_via_packages_list()
114
grepexp=$(_get_grep_exp $firstpkg)
116
# TODO: we miss status due grep
117
# TODO: grep correctly
118
# Note: double call due stderr redirect
119
# Note: we use short=1 here due grep by ^name$
120
# separate first line for print out command
121
(short=1 epm_packages $firstpkg) | grep -q -- "$grepexp" && (quiet=1 epm_packages $firstpkg) && res=0 || res=1
125
grepexp=$(_get_grep_exp $pkg)
126
(short=1 epm_packages $pkg 2>/dev/null) | grep -q -- "$grepexp" && (quiet=1 epm_packages $pkg) || res=1
132
# internal use only, for installed package
133
__epm_get_hilevel_nameform()
135
[ -n "$*" ] || return
139
# use # as delimeter for apt
141
pkg=$(rpm -q --queryformat "%{NAME}=%{SERIAL}:%{VERSION}-%{RELEASE}\n" -- $1)
142
# for case if serial is missed
143
echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}#%{VERSION}-%{RELEASE}\n" -- $1)
144
# HACK: can use only for multiple install packages like kernel
145
echo $pkg | grep -q kernel || return 1
150
# just use strict version with Epoch and Serial
152
#pkg=$(rpm -q --queryformat "%{EPOCH}:%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" -- $1)
153
#echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" -- $1)
154
pkg=$(rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" -- $1)
164
# for local installed packages only
165
# used from epm remove
166
__epm_get_hilevel_name()
171
# get short form in pkg
172
# FIXME: where we use it? continue or pkg=$i?
173
quiet=1 pkg=$(__epm_query_shortname "$i") || pkg="$i" #continue # drop not installed packages
174
# if already short form, skipped
175
[ "$pkg" = "$i" ] && echo "$i" && continue
176
# try get long form or use short form
177
__epm_get_hilevel_nameform "$i" || echo $pkg
185
[ -z "$*" ] && return
190
[ -n "$short" ] && CMD="rpm -qp --queryformat %{name}\n"
193
CMD="dpkg-deb --show --showformat=\${Package}-\${Version}\n"
194
[ -n "$short" ] && CMD="dpkg-query --show --showformat=\${Package}\n"
197
fatal "Do not know command for query file package"
204
# hack: dpkg -W will print names for removed packages too (until newest Ubuntu)
205
__epm_query_dpkg_check()
209
a='' dpkg -s $i >/dev/null 2>/dev/null || return
218
[ -z "$*" ] && return
225
#docmd dpkg -l $@ | grep "^ii"
226
#CMD="dpkg-query -W --showformat=\${Package}-\${Version}\n"
227
docmd dpkg-query -W "--showformat=\${Package}-\${Version}\n" -- $@ || return
228
__epm_query_dpkg_check $@ || return
232
docmd npackdcl path --package=$1
239
showcmd eopkg blame $1
241
str="$(a= eopkg blame $1 | grep "^Name")"
242
[ -n "$str" ] || return 1
243
echo "$str" | sed -e "s|Name[[:space:]]*: \(.*\), version: \(.*\), release: \(.*\)|\1-\2-\3|"
247
# showcmd "brew info $1"
249
# HBRESULT="$(brew info "$1" 2>/dev/null)" || return
250
# echo "$HBRESULT" | grep -q "Not installed" && return 1
258
# TODO: need to print name if exists
262
# Note: slackpkg info pkgname
264
# default slow workaround
265
_query_via_packages_list $@
273
__epm_query_shortname()
277
[ -z "$*" ] && return
281
showcmd rpm -q --queryformat '%{name}\n' -- $@
282
a='' rpm -q --queryformat '%{name}\n' -- $@
286
#CMD="dpkg-query -W --showformat=\${Package}\n"
287
docmd dpkg-query -W "--showformat=\${Package}\n" -- $@ || return
288
__epm_query_dpkg_check $@ || return
292
docmd npackdcl path --package=$1
299
showcmd eopkg blame $1
301
str="$(a= eopkg blame $1 | grep "^Name")"
302
[ -n "$str" ] || return 1
303
echo "$str" | sed -e "s|Name[[:space:]]*: \(.*\), version: \(.*\), release: \(.*\)|\1|"
307
docmd brew info "$1" >/dev/null 2>/dev/null && echo "$1" && return
312
# docmd pacman -Q $@ | sed -e "s| .*||g"
316
# TODO: need to print name if exists
320
# Note: slackpkg info pkgname
322
# default slow workaround
323
_shortquery_via_packages_list $@
332
# keep here, all modules and epm-query use is_installed from epm-query
335
# check if pkg is installed
338
(quiet=1 __epm_query_name "$@") >/dev/null 2>/dev/null
341
filter_pkgnames_to_short()
344
__epm_query_shortname $names
349
[ -n "$pkg_filenames" ] || fatal "Query: package name is missed"
351
__epm_query_file $pkg_files || return
353
if [ -n "$short" ] ; then
354
# shellcheck disable=SC2046
355
__epm_query_shortname $(print_name $pkg_names) || return
357
# shellcheck disable=SC2046
358
__epm_query_name $(print_name $pkg_names) || return