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
#!/bin/sh
#
# Copyright (C) 2012, 2013 Etersoft
# Copyright (C) 2012, 2013 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-packages
# TODO: combine with -qa (the difference only in return status now)
_query_via_packages_list()
{
local res=0
local firstpkg=$1
shift
# separate first line for print out command
short=1 pkg_filenames=$firstpkg epm_packages | grep -- "^$firstpkg$" || res=1
for pkg in "$@" ; do
short=1 pkg_filenames=$pkg epm_packages 2>/dev/null | grep -- "^$pkg$" || res=1
done
return $res
}
# internal use only
__epm_get_hilevel_nameform()
{
[ -n "$*" ] || return
case $PMTYPE in
apt-rpm)
# use # as delimeter for apt
local pkg
pkg=$(rpm -q --queryformat "%{NAME}#%{SERIAL}:%{VERSION}-%{RELEASE}\n" $1)
echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}#%{VERSION}-%{RELEASE}\n" $1)
# HACK: can use only for multiple install packages like kernel
echo $pkg | grep -q kernel || return 1
echo $pkg
return
;;
yum-rpm)
# just use strict version with Epoch and Serial
local pkg
pkg=$(rpm -q --queryformat "%{EPOCH}:%{NAME}%{VERSION}-%{RELEASE}.${ARCH}\n" $1)
echo $pkg | grep -q "(none)" && pkg=$(rpm -q --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.${ARCH}\n" $1)
echo $pkg
return
;;
*)
return 1
;;
esac
}
# for local installed packages only
# used from epm remove
__epm_get_hilevel_name()
{
local i
for i in $@ ; do
local pkg
# get short form in pkg
quiet=1 short=1 pkg=$(__epm_query_name $i)
# if already short form, skipped
[ "$pkg" = "$i" ] && echo "$i" && continue
# try get long form or use short form
__epm_get_hilevel_nameform $i || echo $pkg
done
}
__epm_query_file()
{
local CMD
[ -z "$*" ] && return
case $PMTYPE in
*-rpm)
CMD="rpm -qp"
[ -n "$short" ] && CMD="rpm -qp --queryformat %{name}\n"
;;
apt-dpkg)
CMD="dpkg-deb --show --showformat=\${Package}-\${Version}\n"
[ -n "$short" ] && CMD="dpkg-query --show --showformat=\${Package}\n"
;;
*)
fatal "Do not know command for query file package"
;;
esac
docmd $CMD $@
}
__epm_query_name()
{
local CMD
[ -z "$*" ] && return
case $PMTYPE in
*-rpm)
CMD="rpm -q"
[ -n "$short" ] && CMD="rpm -q --queryformat %{name}\n"
;;
apt-dpkg)
#docmd dpkg -l $@ | grep "^ii"
CMD="dpkg-query -W --showformat=\${Package}-\${Version}\n"
[ -n "$short" ] && CMD="dpkg-query -W --showformat=\${Package}\n"
;;
npackd)
CMD="npackdcl path --package=$@"
;;
brew)
warning "fix query"
return 1
;;
# Note: slackpkg info pkgname
*)
_query_via_packages_list $@
return
;;
esac
docmd $CMD $@
}
# check if pkg is installed
is_installed()
{
#pkg_filenames="$@" epm_query >/dev/null
epm installed $@ >/dev/null 2>/dev/null
}
# fill pkg_installed and pkg_noninstalled
separate_installed()
{
pkg_installed=
pkg_noninstalled=
for i in $* ; do
is_installed $i && pkg_installed="$pkg_installed $i" || pkg_noninstalled="$pkg_noninstalled $i"
done
}
epm_query()
{
[ -n "$pkg_filenames" ] || fatal "Run query without names"
__epm_query_file $pkg_files || return
__epm_query_name $pkg_names || return
}