rpm/rpmsort
Michael Schröder 486d0ef0e2 Accepting request 790868 from home:favogt:rpmsmalle
Rebased:

- Replace rpmsort with rewrite using Lua (boo#1164553)

- Split out perl and python dep generators from rpm-build to avoid
  pulling in perl and python in all RPM builds
- Port rpmconfigcheck to pure shell
- Refactor %files list of main package to not require %excludes
  as those might lead to missing files in the package

OBS-URL: https://build.opensuse.org/request/show/790868
OBS-URL: https://build.opensuse.org/package/show/Base:System/rpm?expand=0&rev=537
2020-04-02 13:57:28 +00:00

77 lines
1.5 KiB
Bash

#!/bin/sh
# rpmsort implemented mostly in Lua
# Copyright (c) 2020 SUSE LLC
# SPDX-License-Identifier: GPL-2.0-or-later
# Author: fvogt@suse.de
# Enhanced by: mwilck@suse.com
rpmsort() {
direction=$1
script='
function parse(ver)
local epoch, version, release = 0, ver, 0
_, eend, e = ver:find("^(%d+):")
if eend then
ver = ver:sub(eend + 1)
version = ver
epoch = e
end
_, _, v, r = ver:find("(.+)%-(.+)$")
if v then
version = v
release = r
end
return epoch, version, release
end
function pkgvercmp(a, b)
local ae, av, ar = parse(a)
local be, bv, br = parse(b)
local ecmp = rpm.vercmp(ae, be)
if ecmp ~= 0 then return ecmp end
local vcmp = rpm.vercmp(av, bv)
if vcmp ~= 0 then return vcmp end
return rpm.vercmp(ar, br)
end
vers = {}
for line in io.stdin:lines() do
table.insert(vers, line)
end
table.sort(vers, function(a, b) return pkgvercmp(a, b) == '"$direction"' end)
print(table.concat(vers, "\n"))
'
rpm --eval "%{lua: ${script}}"
}
usage() {
cat >&2 <<EOF
$0 - sort input according to rpm version sorting conventions
Expects rpm package versions separated by newlines as input and outputs
them sorted according to rpm version sorting conventions, with old versions
at the top.
Options:
-r|--reverse sort backwards
-h|--help print this help
EOF
exit 0
}
DIRECTION=-1
while [ $# -gt 0 ]; do
case $1 in
-r|--reverse) DIRECTION=1;;
-h|--help) usage;;
*) echo "$0: invalid parameter $1 ignored" >&2;;
esac
shift
done
rpmsort "$DIRECTION"