3
# Copyright (C) 2015, 2016, 2018, 2020, 2022 Etersoft
4
# Copyright (C) 2008, 2015, 2016, 2018, 2020, 2022 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/>.
24
echo "$1" | grep -q "\.rpm$" && return
25
echo "$1" | grep -q "\.deb$" && return
29
# Query variables from rpm package
31
rpm_query_package_format_field()
36
# if a file, add -p for get from rpm base
37
if is_pkgfile "$1" ; then
40
a= rpmquery $INSTALLED --queryformat "$FORMAT" "$@"
43
rpm_query_package_field()
47
rpm_query_package_format_field "$FORMAT" "$@"
50
dpkg_query_package_format_field()
54
if is_pkgfile "$1" ; then
55
a= dpkg-deb --show --showformat="$field\n" "$@"
57
#a= dpkg -s "$1" | grep "^$field: " | sed -e "s|^$field: ||"
58
a= dpkg-query -W --showformat="$field\n" -- "$@"
62
dpkg_query_package_field()
66
#if [ -f "$1" ] ; then
67
# a= dpkg -I "$@" | grep "^.*$field: " | sed -e "s|^.*$field: ||"
69
dpkg_query_package_format_field "\${$field}" "$@"
79
dpkg_query_package_field "$field" "$@"
82
rpm_query_package_field "$field" "$@"
92
dpkg_query_package_field "Arch" "$@" | sed -e "s|-.*||" -e "s|.*:||"
95
rpm_query_package_field "arch" "$@"
104
dpkg_query_package_field "Version" "$@" | sed -e "s|-.*||" -e "s|.*:||"
107
rpm_query_package_field "version" "$@"
116
dpkg_query_package_field "Version" "$@" | sed -e "s|.*-||"
119
rpm_query_package_field "release" "$@"
124
print_pkg_version_release()
128
dpkg_query_package_field "Version" "$@" | sed -e "s|.*:||"
131
rpm_query_package_format_field "%{version}-%{release}" "$@"
140
dpkg_query_package_field "Package" "$@"
143
rpm_query_package_field "name" "$@"
148
# build binary package list (1st - repo dir, 2st - pkgname)
149
# algorithm: list all files in PKGDIR, print packages with our source pkg name
150
print_binpkgfilelist()
153
local PKGNAME=$(basename $2)
154
find "$PKGDIR" ! -name '*\.src\.rpm' -name '*\.rpm' -execdir \
155
rpmquery -p --qf='%{sourcerpm}\t%{name}-%{version}-%{release}.%{arch}.rpm\n' "{}" \; \
156
| grep "^$PKGNAME[[:space:]].*" \
158
| xargs -n1 -I "{}" echo -n "$PKGDIR/{} "
161
# TODO: need try detect more strict
162
# TODO: package name mask for every system
163
# TODO: broken for all systems
164
#PKGNAMEMASK1="\(.*\)-\([^0-9].*[^0-9]\)-\(.*[0-9].*\)"
165
# mask to parse package name
167
# TODO: с хвоста, сначала релиз, потом версию, остаётся пакет.
168
# всё равно остаются неоднозначности: libname-1.0 где 1.0 то ли версия, то ли часть названия.
169
# возможно, нужно ориентироваться только на выделение в полном имени/
171
# libpq5.2-9.0eter-9.0.4-alt14
172
# nx-libs-3.5.99.26.1-eter2astra:amd64
173
PKGNAMEMASK4="6\(.*\)[_-]\([^_-]*\)[_-]\(.*[0-9].*\):\(.*\)$"
174
# nx-libs-3.5.99.26.1-eter2astra
175
PKGNAMEMASK3="^\(.*\)[_-]\([^_-]*\)[_-]\(.*[0-9].*\)$"
177
#PKGNAMEMASK2="^\(.*\)[_-]\([0-9].*\)$"
179
PKGNAMEMASK="\(.*\)-\([0-9].*\)-\(.*[0-9].*\)\.\(.*\)\.\(.*\)"
184
# don't change name (false cases)
185
#echo "$@" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK4|\1-\2-\3|" -e "s|$PKGNAMEMASK3|\1|"
186
echo "$@" | xargs -n1 echo
189
# as hack for print_name
193
#echo "$@" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK4|\1-\2-\3|" -e "s|$PKGNAMEMASK3|\1|"
194
echo "$@" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK3|\1|"
199
echo "$1" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK4|\1-\2-\3|" -e "s|$PKGNAMEMASK3|\2|"
204
echo "$1" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK4|\1-\2-\3|" -e "s|$PKGNAMEMASK3|\3|"
207
print_version_release()
209
echo "$1" | xargs -n1 echo | sed -e "s|$PKGNAMEMASK4|\1-\2-\3|" -e "s|$PKGNAMEMASK3|\2-\3|"
212
# get package name only by package filename
213
# TODO: see also __epm_get_hilevel_name()
218
# TODO: deb and other, arch string
219
echo "$(basename "$i") " | sed -e "s|\.[a-z_0-9]*\.rpm||g" -e "s|\(.*\)_\(.*\)_[a-z_0-9]*\.deb|\1-\2|g"
225
print_name "$(print_srcpkgname "$@")"
230
# CHECKME: it is possible to have two or more specs in one package?
231
a= rpm -qlp "$@" | grep "\.spec\$"
237
if [ -n "$FNFLAG" ] ; then
238
rpm_query_package_field "sourcerpm" "$@"
245
fatal "Unknown command for get source package name via dpkg"
248
docmd urpmq --sourcerpm "$@"
252
showcmd dnf repoquery --qf '%{SOURCERPM}' "$@"
253
a= dnf repoquery --qf '%{SOURCERPM}' "$@"
258
# FIXME: only for installed rpm packages
259
rpm_query_package_field "sourcerpm" "$@"
262
# https://blog.jasonantman.com/2014/07/how-yum-and-rpm-compare-versions/
267
# rpmevrcmp exists in ALT Linux only
268
if is_command rpmevrcmp ; then
271
a= rpm --eval "%{lua:print(rpm.vercmp('$1', '$2'))}"
275
a= dpkg --compare-versions "$1" lt "$2" && echo "-1" && return
276
a= dpkg --compare-versions "$1" eq "$2" && echo "0" && return
280
fatal "Not implemented for $PMTYPE"
285
# construct package file name.
286
# name version [arch] [pkgtype] [ds] [pds]
296
[ -n "$arch" ] || arch="$DISTRARCH"
297
[ -n "$pkgtype" ] || pkgtype="$PKGFORMAT"
298
[ -n "$ds" ] || ds=$(get_pkg_name_delimiter $pkgtype)
299
[ -z "$pds" ] && pds="$ds" && [ "$pds" = "-" ] && pds="."
300
[ -n "$version" ] && version="$ds$version"
301
echo "${name}${version}${pds}$arch.$pkgtype"
308
epm print info [args] print system and distro info (via distro_info command)
309
epm print name [from filename|for package] NN print only name of package name or package file
310
epm print shortname [for package] NN print only short name of package name
311
epm print version [from filename|for package] NN print only version of package name or package file
312
epm print release [from filename|for package] NN print only release of package name or package file
313
epm print version-release [from filename|for package] NN print only release-release of package name or package file
314
epm print arch [from filename|for package] NN print arch of package name or package file
315
epm print field FF for package NN print field of the package
316
epm print pkgname from filename NN print package name for the package file
317
epm print srcname from filename NN print source name for the package file
318
epm print srcpkgname from [filename|package] NN print source package name for the binary package file
319
epm print specname from filename NN print spec filename for the source package file
320
epm print binpkgfilelist in DIR for NN list binary package(s) filename(s) from DIR for the source package file
321
epm print compare [package] version N1 N2 compare (package) versions and print -1 (N1 < N2), 0 (N1 == N2), 1 (N1 > N2)
322
epm print constructname <name> <version> [arch] [pkgtype] [delimiter1] [delimiter2] print distro dependend package filename from args name version arch pkgtype
332
[ "$1" = "from" ] && shift
333
[ "$1" = "for" ] && shift
334
[ "$1" = "of" ] && shift
335
[ "$1" = "in" ] && shift
336
if [ "$1" = "filename" ] ; then
341
if [ "$1" = "package" ] ; then
348
fatal "Use epm print --help to get help."
350
"-h"|"--help"|"help")
354
[ -n "$1" ] || fatal "Arg is missed"
355
if [ -n "$FNFLAG" ] ; then
356
print_name "$(print_pkgname "$@")"
357
elif [ -n "$PKFLAG" ] ; then
364
[ -n "$1" ] || fatal "Arg is missed"
365
if [ -n "$FNFLAG" ] ; then
367
elif [ -n "$PKFLAG" ] ; then
374
[ -n "$1" ] || fatal "Arg is missed"
375
if [ -n "$FNFLAG" ] ; then
376
print_version "$(print_pkgname "$@")"
377
elif [ -n "$PKFLAG" ] ; then
378
print_pkg_version "$@"
384
[ -n "$1" ] || fatal "Arg is missed"
385
if [ -n "$FNFLAG" ] ; then
386
print_release "$(print_pkgname "$@")"
387
elif [ -n "$PKFLAG" ] ; then
388
print_pkg_release "$@"
394
[ -n "$1" ] || exit 0 #fatal "Arg is missed"
398
[ -n "$1" ] || fatal "Arg is missed"
399
if [ -n "$FNFLAG" ] ; then
400
print_version_release "$(print_pkgname "$@")"
401
elif [ -n "$PKFLAG" ] ; then
402
print_pkg_version_release "$@"
404
print_version_release "$@"
408
[ -n "$1" ] || fatal "Arg is missed"
411
[ "$1" = "for" ] && shift
412
[ "$1" = "package" ] && shift
413
query_package_field "$FIELD" "$@"
416
[ -n "$FNFLAG" ] || fatal "print $WHAT works only for filename(s)"
417
[ -n "$1" ] || fatal "Arg is missed"
418
# TODO: drop_pkg_extensions
422
[ -n "$FNFLAG" ] || fatal "print $WHAT works only for filename(s)"
423
[ -n "$1" ] || fatal "Arg is missed"
427
[ -n "$FNFLAG" ] || [ -n "$PKFLAG" ] || fatal "print $WHAT works only for filename(s)"
428
[ -n "$1" ] || fatal "Arg is missed"
429
print_srcpkgname "$@"
432
[ -n "$FNFLAG" ] || [ -n "$PKFLAG" ] || fatal "print $WHAT works only for filename(s)"
433
[ -n "$1" ] || fatal "Arg is missed"
438
# TODO: replace get_binpkg_list
441
[ "$1" = "for" ] && shift
442
[ -n "$DIR" ] || fatal "DIR arg is missed"
443
[ -n "$1" ] || fatal "source package filename is missed"
444
print_binpkgfilelist "$DIR" "$1"
447
[ "$1" = "version" ] && shift
448
[ -n "$1" ] || fatal "Arg is missed"
449
#if [ -n "$PKFLAG" ] ; then
450
# query_package_field "name" "$@"
452
compare_version "$1" "$2"
463
fatal "Unknown command $ epm print $WHAT. Use epm print help for get help."