Compare commits

...

29 Commits
master ... f36

Author SHA1 Message Date
Robbie Harwood 69e614eab8 Give up and just pull the config from BLS
Suggested-by: Bojan Smojver <bojan@rexursive.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-08-22 17:55:51 -04:00
Robbie Harwood e6b270b9d2 Bring back -deprecated for f36 2022-08-18 12:16:18 -04:00
Robbie Harwood 74ff4810be Mark package as obsoleting -deprecated
Resolves: #2117817
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-08-17 15:17:48 +00:00
Robbie Harwood 1faea2de0a Handle updating /etc/kernel/cmdline
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-08-02 18:00:16 -04:00
Fedora Release Engineering c8241463d7 Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2022-07-21 13:06:10 +00:00
Robbie Harwood 29fb24f205 Clarify that grub files aren't used on s390x in man page
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-07-19 19:26:03 +00:00
Robbie Harwood 810b5eee5a Update spec file for previous change
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-06-22 14:43:48 -04:00
Robbie Harwood 78927fa5ed Revert "Additionally write to /etc/kernel/cmdline"
This reverts commit 599a2e1a99.

Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-06-22 14:43:02 -04:00
Robbie Harwood 599a2e1a99 Additionally write to /etc/kernel/cmdline
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-05-31 17:23:49 +00:00
Robbie Harwood 79765ad0d7 Stop building on ia32
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-04-27 13:13:57 -04:00
Robbie Harwood aaefddefe8 rpm-sort: fix missing include and sort
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-04-27 13:08:31 -04:00
Robbie Harwood 415ad451de Remove upstream and layers of indirection around -bls
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-04-27 13:08:25 -04:00
Robbie Harwood 1bc3038166 Add missing changelog (Remove grubby-deprecated)
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-03-15 16:06:36 -04:00
Robbie Harwood 59ba93105a grubby-bls: wire up -h (help)
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
2022-03-10 20:40:02 +00:00
Robbie Harwood dfdd26c908 grubby-bls: wire up -h (help)
Originally authored by Lukas Herbolt.
2022-02-07 16:42:57 -05:00
Fedora Release Engineering 0dd1a4fc40 - Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2022-01-20 11:50:18 +00:00
Fedora Release Engineering eaef784cc6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2021-07-22 07:09:11 +00:00
Javier Martinez Canillas e69860d718
Man page and package description fixes
Clarify package description
  Resolves: rhbz#1913299
Update man page to not mention the GRUB config in the ESP anymore
  Resolves: rhbz#1958458

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-06-23 10:21:14 +02:00
Javier Martinez Canillas 9ebc469d54
Update man page to not mention the GRUB config in the ESP anymore
After https://fedoraproject.org/wiki/Changes/UnifyGrubConfig the config in
ESP is only used as a stub to load the actual GRUB config the in /boot dir.

Don't mention this file in the grubby man page, since users shouldn't even
be aware of that config file.

Resolves: rhbz#1958458

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-06-23 08:22:58 +02:00
Javier Martinez Canillas e94425201f
Clarify package description
The grubby script was meant to be a temporary solution to provide backward
compatibility with existing grubby users. But it turned out that grubby is
the recommended approach to modify the boot loader entries.

Let's make clear in the package description that this is not only meant to
be used for legacy compatibility purposes, which may discourage its usage.

Resolves: rhbz#1913299

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-06-23 07:56:49 +02:00
Javier Martinez Canillas 2b59d1355d
grubby-bls: expand only the kernelopts variable
The BLS snippets have the options field set to a kernelopts variable by
default, which is set in GRUB's environemnt block to the kernel cmdline.

When the kernel command line parameters are modified for all the entries,
the value of this kernelopts variable is modified. But if the cmdline is
modified for a single entry, then the kernelopts variable is expanded and
the resulted modified value stored in the BLS snippet.

The grubby tool expanded all the variables in the options field, but it's
possible that some of these variables are managed by another tool. For
example the tuned program adds a tuned variable that shouldn't be changed
by the grubby tool. Otherwise it will mangle the tuned configuration set.

To prevent this, let's make grubby to only expand the kernelopts variable.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-06-09 23:40:23 +02:00
Javier Martinez Canillas 5d3963841d
grubby-bs: Fix changing kernel cmdline params not working on ppc64le
Currently the grubby script re-generates a GRUB config file that contains
menuentry commands for every /boot/loader/entries/*.conf file snippet.

But this is only needed for ppc64le machines that have a Petitboot version
that doesn't support parsing BLS snippets. Instead of generating a config
on any ppc64le machine, restrict this for the case where is really needed.

The /etc/grub.d/10_linux script already takes this into account and does
not add menuentry commands unless is needed. But the grubby script didn't
check this, causing changing kernel cmdline params to not work on ppc64le.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-04-26 18:46:31 +02:00
Fedora Release Engineering 786a133370 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2021-01-26 13:00:54 +00:00
Tom Stellard fd57e031d4
Use make_build macro instead of plain make
This will make it possible for buildroots to inject arguments to
make by redefining the %__make macro.
2020-12-30 17:27:35 +01:00
Peter Robinson 536f42db1c Add device tree kernel install option, minor cleanups 2020-11-24 10:44:12 +00:00
Josh Boyer b91640a743 Only require s390utils-core
zipl appears to be the only thing grubby needs, and that is provided by s390utils-core.  Change the Requires to that, which allows for a more minimal installation.
2020-10-26 16:13:44 -04:00
Josh Boyer 3498276978 Only require s390utils-core
zipl appears to be the only thing grubby needs, and that is provided by s390utils-core.  Change the Requires to that, which allows for a more minimal installation.
2020-10-24 12:33:50 +00:00
Fedora Release Engineering 1ead121a08 - Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2020-07-28 00:24:28 +00:00
Javier Martinez Canillas a5c9c3a138
fix build with rpm-4.16 and correct --extra-initrd option image path
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2020-06-26 10:16:05 +02:00
6 changed files with 602 additions and 38 deletions

View File

@ -0,0 +1,28 @@
From 1afddd618629a97479560bedbdcfa11b2c492a0e Mon Sep 17 00:00:00 2001
From: Javier Martinez Canillas <javierm@redhat.com>
Date: Fri, 26 Jun 2020 10:02:51 +0200
Subject: [PATCH] Fix build with rpm-4.16
rpmvercmp() was moved to librpmio, so link against this library instead.
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
index 1ab58aeb039..a54b053a30b 100644
--- a/Makefile
+++ b/Makefile
@@ -59,7 +59,7 @@ grubby:: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(grubby_LIBS)
rpm-sort::rpm-sort.o
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lrpm
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lrpmio
clean:
rm -f *.o grubby rpm-sort *~
--
2.26.2

73
10-devicetree.install Executable file
View File

@ -0,0 +1,73 @@
#!/bin/bash
# set -x
if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 ]]
then
COMMAND="$1"
KERNEL_VERSION="$2"
#BOOT_DIR_ABS="$3"
#KERNEL_IMAGE="$4"
[ -f /etc/u-boot.conf ] && source /etc/u-boot.conf || true
[ -z "$FIRMWAREDT" ] || FirmwareDT=$FIRMWAREDT
if [[ $FirmwareDT == "True" ]]
then
# if we want to use firmware DT we remove symlink to current kernel DT
if [ -h /boot/dtb ]; then
rm -f /boot/dtb
fi
exit 0
fi
# Setup a /boot/dtb -> /boot/dtb-$newest_kernel_version symlink so that
# u-boot can find the correct dtb to load.
#
# If invoked to 'add' a new kernel, find the newest based on `sort`ing
# the kernel versions dtb. If 'remove', then follow basically the same
# procedure but exclude the version currently being removed.
#
# The theory of operation here is that, while newer kernels may add new
# dtb nodes and fields, as upstreaming hw support for some particular
# device progresses, it should never make backward incompatible changes.
# So it should always be safe to use a newer dtb with an older kernel.
list_dtb_versions() {
excluded_version="$1"
for dtbdir in /boot/dtb-*; do
dtbver=${dtbdir#*-}
if [ "$dtbver" != "$excluded_version" ]; then
echo $dtbver
fi
done
}
setup_dtb_link() {
ver=`list_dtb_versions $1 | sort -r --sort=version | head -1`
if [ -h /boot/dtb ]; then
rm -f /boot/dtb
fi
ln -s dtb-$ver /boot/dtb
}
ret=0
case "$COMMAND" in
add)
# If we're adding a kernel we want that version
if [ -h /boot/dtb ]; then
rm -f /boot/dtb
fi
ln -s dtb-$KERNEL_VERSION /boot/dtb
ret=$?
;;
remove)
setup_dtb_link $KERNEL_VERSION
ret=$?
;;
esac
exit $ret
else
# Just exit on non ARM
exit 0
fi

View File

@ -235,7 +235,7 @@ get_bls_args() {
local opts=(${args})
for opt in ${opts[*]}; do
if [[ $opt =~ ^\$ ]]; then
if [[ $opt = "\$kernelopts" ]]; then
value="$(expand_var $opt)"
args="$(echo ${args} | sed -e "s/${opt}/${value}/")"
fi
@ -429,7 +429,7 @@ add_bls_fragment() {
fi
if [[ -n $extra_initrd ]]; then
append_bls_value "${bls_target}" "initrd" "${extra_initrd}"
append_bls_value "${bls_target}" "initrd" " ${extra_initrd}"
fi
if [[ $MAKEDEBUG = "yes" ]]; then
@ -528,6 +528,20 @@ update_bls_fragment() {
fi
done
if [[ $param = "ALL" ]] && [[ -n $remove_args || -n $add_args ]]; then
if [[ ! -f /etc/kernel/cmdline ]]; then
# anaconda could pre-populate this file, but until then, most of
# the time we'll just want the most recent one. This is pretty
# close to the current almost-correct behavior of falling back to
# /proc/cmdline anyhow.
echo "$(get_bls_args -1)" > /etc/kernel/cmdline
fi
read old_args < /etc/kernel/cmdline
local new_args="$(update_args "${old_args}" "${remove_args}" "${add_args}")"
echo "$new_args" > /etc/kernel/cmdline
fi
update_grubcfg
}
@ -567,7 +581,7 @@ remove_var_prefix() {
fi
if [[ -n $extra_initrd ]]; then
extra_initrd=" /${extra_initrd##${prefix}/}"
extra_initrd="/${extra_initrd##${prefix}/}"
fi
if [[ -n $kernel ]]; then
@ -581,8 +595,33 @@ remove_var_prefix() {
update_grubcfg()
{
if [[ $arch = 'ppc64' || $arch = 'ppc64le' ]]; then
grub2-mkconfig --no-grubenv-update -o "${grub_config}" >& /dev/null
# Older ppc64le OPAL firmware (petitboot version < 1.8.0) don't have BLS support
# so grub2-mkconfig has to be run to generate a config with menuentry commands.
if [ "${arch}" = "ppc64le" ] && [ -d /sys/firmware/opal ]; then
RUN_MKCONFIG="true"
petitboot_path="/sys/firmware/devicetree/base/ibm,firmware-versions/petitboot"
if test -e ${petitboot_path}; then
read -r -d '' petitboot_version < ${petitboot_path}
petitboot_version="$(echo ${petitboot_version//v})"
if test -n ${petitboot_version}; then
major_version="$(echo ${petitboot_version} | cut -d . -f1)"
minor_version="$(echo ${petitboot_version} | cut -d . -f2)"
re='^[0-9]+$'
if [[ $major_version =~ $re ]] && [[ $minor_version =~ $re ]] &&
([[ ${major_version} -gt 1 ]] ||
[[ ${major_version} -eq 1 &&
${minor_version} -ge 8 ]]); then
RUN_MKCONFIG="false"
fi
fi
fi
fi
if [[ $RUN_MKCONFIG = "true" ]]; then
grub2-mkconfig --no-grubenv-update -o "${grub_config}" >& /dev/null
fi
}
@ -616,12 +655,12 @@ Usage: grubby [OPTION...]
--no-etc-grub-update don't update the GRUB_CMDLINE_LINUX variable in /etc/default/grub
Help options:
-?, --help Show this help message
-h, --help Show this help message
EOF
}
OPTS="$(getopt -o c:i:b:? --long help,add-kernel:,args:,bad-image-okay,\
OPTS="$(getopt -o hc:i:b:? --long help,add-kernel:,args:,bad-image-okay,\
config-file:,copy-default,default-kernel,default-index,default-title,env:,\
grub2,info:,initrd:,extra-initrd:,make-default,remove-args:,\
remove-kernel:,set-default:,set-default-index:,title:,update-kernel:,zipl,\
@ -683,7 +722,7 @@ while [ ${#} -gt 0 ]; do
shift
;;
--extra-initrd|-i)
extra_initrd=" /${2}"
extra_initrd="${2}"
shift
;;
--make-default)

View File

@ -19,13 +19,10 @@ about the configuration files for the \fBgrub2\fR and \fBzipl\fR boot loaders.
It is primarily designed to be used from scripts which install new kernels and
need to find information about the current boot environment.
On BIOS-based Intel x86 platforms, \fBgrub2\fR is the default bootloader and
the configuration file is in \fB/boot/grub2/grub.cfg\fR. On UEFI-based Intel
x86 platforms, \fBgrub2\fR is the default bootloader, and the configuration
file is in \fB/boot/efi/EFI/redhat/grub.cfg\fR. On PowerPC platforms, systems
based on Power8 and Power9 support \fBgrub2\fR as a bootloader and use a
configuration stored in \fB/boot/grub2/grub.cfg\fR. On s390x platforms the
\fBzipl\fR bootloader use a default configuration in \fB/etc/zipl.conf\fR.
On BIOS-based Intel x86, PowerPC and UEFI-based platforms, \fBgrub2\fR is the
default bootloader and the configuration file is in \fB/boot/grub2/grub.cfg\fR.
On s390x platforms, the \fBzipl\fR bootloader use a default configuration in
\fB/etc/zipl.conf\fR.
All bootloaders define the boot entries as individual configuration fragments
that are stored by default in \fB/boot/loader/entries\fR. The format for the
@ -148,7 +145,8 @@ the only items that can be updated is the kernel argument list, which is
modified via the \fB-\-args\fR and \fB-\-remove-args\fR options. If the
\fBALL\fR argument is used the variable \fB GRUB_CMDLINE_LINUX\fR in
\fB/etc/default/grub\fR is updated with the latest kernel argument list,
unless the \fB-\-no-etc-grub-update\fR option is used.
unless the \fB-\-no-etc-grub-update\fR option is used or the file does not
exist (e.g., on s390x).
.TP
\fB-\-zipl\fR

View File

@ -1,6 +1,6 @@
Name: grubby
Version: 8.40
Release: 45%{?dist}
Release: 67%{?dist}
Summary: Command line tool for updating bootloader configs
License: GPLv2+
URL: https://github.com/rhinstaller/grubby
@ -14,7 +14,9 @@ Source2: grubby.in
Source3: installkernel.in
Source4: installkernel-bls
Source5: 95-kernel-hooks.install
Source6: grubby.8
Source6: 10-devicetree.install
Source7: grubby.8
Patch0001: 0001-remove-the-old-crufty-u-boot-support.patch
Patch0002: 0002-Change-return-type-in-getRootSpecifier.patch
Patch0003: 0003-Add-btrfs-subvolume-support-for-grub2.patch
@ -27,46 +29,41 @@ Patch0009: 0009-Improve-man-page-for-info-option.patch
Patch0010: 0010-Fix-GCC-warnings-about-possible-string-truncations-a.patch
Patch0011: 0011-Fix-stringop-overflow-warning.patch
Patch0012: 0012-Fix-maybe-uninitialized-warning.patch
Patch0013: 0013-Fix-build-with-rpm-4.16.patch
BuildRequires: gcc
BuildRequires: pkgconfig glib2-devel popt-devel
BuildRequires: libblkid-devel git-core sed make
BuildRequires: libblkid-devel sed make
# for make test / getopt:
BuildRequires: util-linux-ng
BuildRequires: rpm-devel
%ifarch aarch64 i686 x86_64 %{power64}
BuildRequires: sed
%ifarch aarch64 x86_64 %{power64}
BuildRequires: grub2-tools-minimal
Requires: grub2-tools-minimal
Requires: grub2-tools
%endif
%ifarch s390 s390x
Requires: s390utils-base
Requires: s390utils-core
%endif
Requires: findutils
Requires: util-linux
ExcludeArch: %{ix86}
Conflicts: uboot-tools < 2021.01-0.1.rc2
Obsoletes: %{name}-bls < %{version}-%{release}
%description
This package provides a grubby compatibility script that manages
BootLoaderSpec files and is meant to only be used for legacy compatibility
users with existing grubby users.
BootLoaderSpec files and is meant to be backward compatible with
the previous grubby tool.
%prep
%setup -q -n grubby-%{version}-1
git init
git config user.email "noone@example.com"
git config user.name "no one"
git add .
git commit -a -q -m "%{version} baseline"
git am %{patches} </dev/null
git config --unset user.email
git config --unset user.name
%autosetup -p1 -n grubby-%{version}-1
%build
%set_build_flags
make %{?_smp_mflags} LDFLAGS="${LDFLAGS}"
%make_build LDFLAGS="${LDFLAGS}"
%ifnarch aarch64 %{arm}
%check
@ -86,8 +83,9 @@ sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/grubby,g" %{SOURCE2} \
sed -e "s,@@LIBEXECDIR@@,%{_libexecdir}/installkernel,g" %{SOURCE3} \
> %{buildroot}%{_sbindir}/installkernel
install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE5}
install -D -m 0755 -t %{buildroot}%{_prefix}/lib/kernel/install.d/ %{SOURCE6}
rm %{buildroot}%{_mandir}/man8/grubby.8*
install -m 0644 %{SOURCE6} %{buildroot}%{_mandir}/man8/
install -m 0644 %{SOURCE7} %{buildroot}%{_mandir}/man8/
%post
if [ "$1" = 2 ]; then
@ -111,7 +109,6 @@ scripts which install new kernels and need to find information about the
current boot environment.
%files
%{!?_licensedir:%global license %%doc}
%license COPYING
%dir %{_libexecdir}/grubby
%dir %{_libexecdir}/installkernel
@ -120,11 +117,11 @@ current boot environment.
%attr(0755,root,root) %{_sbindir}/grubby
%attr(0755,root,root) %{_libexecdir}/installkernel/installkernel-bls
%attr(0755,root,root) %{_sbindir}/installkernel
%attr(0755,root,root) %{_prefix}/lib/kernel/install.d/10-devicetree.install
%attr(0755,root,root) %{_prefix}/lib/kernel/install.d/95-kernel-hooks.install
%{_mandir}/man8/[gi]*.8*
%files deprecated
%{!?_licensedir:%global license %%doc}
%license COPYING
%dir %{_libexecdir}/grubby
%dir %{_libexecdir}/installkernel
@ -133,9 +130,82 @@ current boot environment.
%attr(0755,root,root) %{_sbindir}/grubby
%attr(0755,root,root) %{_sbindir}/installkernel
%attr(0755,root,root) %{_sbindir}/new-kernel-pkg
%{_mandir}/man8/*.8*
%{_mandir}/man8/*.8*
%changelog
* Mon Aug 22 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-67
- Give up and just pull the config from BLS
- Suggested-by: Bojan Smojver <bojan@rexursive.com>
* Thu Aug 18 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-66
- Bring back -deprecated for fedora 36
* Wed Aug 17 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-65
- Mark package as obsoleting -deprecated
- Resolves: #2117817
* Tue Aug 02 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-64
- Handle updating /etc/kernel/cmdline
* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-63
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
* Tue Jul 19 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-62
- Clarify that grub files aren't used on s390x in man page
* Wed Jun 22 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-61
- Revert previous change
* Tue May 31 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-60
- Additionally write to /etc/kernel/cmdline
* Wed Apr 27 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-59
- Remove upstream and layers of indirection around -bls
* Thu Mar 10 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-58
- Remove grubby-deprecated
* Mon Feb 07 2022 Robbie Harwood <rharwood@redhat.com> - 8.40-57
- grubby-bls: wire up -h (help)
* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-56
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
* Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-55
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
* Wed Jun 23 2021 Javier Martinez Canillas <javierm@redhat.com> - 8.40-54
- Clarify package description
Resolves: rhbz#1913299
- Update man page to not mention the GRUB config in the ESP anymore
Resolves: rhbz#1958458
* Wed Jun 09 2021 Javier Martinez Canillas <javierm@redhat.com> - 8.40-53
- grubby-bls: expand only the kernelopts variable
* Mon Apr 26 2021 Javier Martinez Canillas <javierm@redhat.com> - 8.40-52
- grubby-bs: Fix changing kernel cmdline params not working on ppc64le
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-51
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
* Wed Dec 30 2020 Tom Stellard <tstellar@redhat.com> - 8.40-50
- Use make_build macro instead of plain make
- https://docs.fedoraproject.org/en-US/packaging-guidelines/#_parallel_make
* Fri Nov 20 2020 Peter Robinson <pbrobinson@fedoraproject.org> - 8.40-49
- Add device tree kernel install option
* Mon Oct 26 2020 Josh Boyer <jwb@redhat.com> - 8.40-48
- Only require s390utils-core, not s390utils-base
* Tue Jul 28 2020 Fedora Release Engineering <releng@fedoraproject.org> - 8.40-47
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
* Fri Jun 26 2020 Javier Martinez Canillas <javierm@redhat.com> - 8.40-46
- fix build with rpm-4.16
- grubby-bls: fix --extra-initrd option not adding the correct path
* Wed May 13 2020 Javier Martinez Canillas <javierm@redhat.com> - 8.40-45
- grubby-bls: don't replace options with kernelopts if values are the same

356
rpm-sort.c Normal file
View File

@ -0,0 +1,356 @@
#define _GNU_SOURCE
#include <argp.h>
#include <assert.h>
#include <err.h>
#include <errno.h>
#include <rpm/rpmlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
typedef enum {
RPMNVRCMP,
VERSNVRCMP,
RPMVERCMP,
STRVERSCMP,
} comparitors;
static comparitors comparitor = RPMNVRCMP;
static inline void *xmalloc(size_t sz)
{
void *ret = malloc(sz);
assert(sz == 0 || ret != NULL);
return ret;
}
static inline void *xrealloc(void *p, size_t sz)
{
void *ret = realloc(p, sz);
assert(sz == 0 || ret != NULL);
return ret;
}
static inline char *xstrdup(const char * const s)
{
void *ret = strdup(s);
assert(s == NULL || ret != NULL);
return ret;
}
static size_t
read_file (const char *input, char **ret)
{
FILE *in;
size_t s;
size_t sz = 2048;
size_t offset = 0;
char *text;
if (!strcmp(input, "-"))
in = stdin;
else
in = fopen(input, "r");
text = xmalloc (sz);
if (!in)
err(1, "cannot open `%s'", input);
while ((s = fread (text + offset, 1, sz - offset, in)) != 0)
{
offset += s;
if (sz - offset == 0)
{
sz += 2048;
text = xrealloc (text, sz);
}
}
text[offset] = '\0';
*ret = text;
if (in != stdin)
fclose(in);
return offset + 1;
}
/* returns name/version/release */
/* NULL string pointer returned if nothing found */
static void
split_package_string (char *package_string, char **name,
char **version, char **release)
{
char *package_version, *package_release;
/* Release */
package_release = strrchr (package_string, '-');
if (package_release != NULL)
*package_release++ = '\0';
*release = package_release;
/* Version */
package_version = strrchr(package_string, '-');
if (package_version != NULL)
*package_version++ = '\0';
*version = package_version;
/* Name */
*name = package_string;
/* Bubble up non-null values from release to name */
if (*name == NULL)
{
*name = (*version == NULL ? *release : *version);
*version = *release;
*release = NULL;
}
if (*version == NULL)
{
*version = *release;
*release = NULL;
}
}
static int
cmprpmversp(const void *p1, const void *p2)
{
return rpmvercmp(*(char * const *)p1, *(char * const *)p2);
}
static int
cmpstrversp(const void *p1, const void *p2)
{
return strverscmp(*(char * const *)p1, *(char * const *)p2);
}
/*
* package name-version-release comparator for qsort
* expects p, q which are pointers to character strings (char *)
* which will not be altered in this function
*/
static int
package_version_compare (const void *p, const void *q)
{
char *local_p, *local_q;
char *lhs_name, *lhs_version, *lhs_release;
char *rhs_name, *rhs_version, *rhs_release;
int vercmpflag = 0;
int (*cmp)(const char *s1, const char *s2);
switch(comparitor)
{
default: /* just to shut up -Werror=maybe-uninitialized */
case RPMNVRCMP:
cmp = rpmvercmp;
break;
case VERSNVRCMP:
cmp = strverscmp;
break;
case RPMVERCMP:
return cmprpmversp(p, q);
break;
case STRVERSCMP:
return cmpstrversp(p, q);
break;
}
local_p = alloca (strlen (*(char * const *)p) + 1);
local_q = alloca (strlen (*(char * const *)q) + 1);
/* make sure these allocated */
assert (local_p);
assert (local_q);
strcpy (local_p, *(char * const *)p);
strcpy (local_q, *(char * const *)q);
split_package_string (local_p, &lhs_name, &lhs_version, &lhs_release);
split_package_string (local_q, &rhs_name, &rhs_version, &rhs_release);
/* Check Name and return if unequal */
vercmpflag = cmp ((lhs_name == NULL ? "" : lhs_name),
(rhs_name == NULL ? "" : rhs_name));
if (vercmpflag != 0)
return vercmpflag;
/* Check version and return if unequal */
vercmpflag = cmp ((lhs_version == NULL ? "" : lhs_version),
(rhs_version == NULL ? "" : rhs_version));
if (vercmpflag != 0)
return vercmpflag;
/* Check release and return the version compare value */
vercmpflag = cmp ((lhs_release == NULL ? "" : lhs_release),
(rhs_release == NULL ? "" : rhs_release));
return vercmpflag;
}
static void
add_input (const char *filename, char ***package_names, size_t *n_package_names)
{
char *orig_input_buffer = NULL;
char *input_buffer;
char *position_of_newline;
char **names = *package_names;
char **new_names = NULL;
size_t n_names = *n_package_names;
if (!*package_names)
new_names = names = xmalloc (sizeof (char *) * 2);
if (read_file (filename, &orig_input_buffer) < 2)
{
if (new_names)
free (new_names);
if (orig_input_buffer)
free (orig_input_buffer);
return;
}
input_buffer = orig_input_buffer;
while (input_buffer && *input_buffer &&
(position_of_newline = strchrnul (input_buffer, '\n')))
{
size_t sz = position_of_newline - input_buffer;
char *new;
if (sz == 0)
{
input_buffer = position_of_newline + 1;
continue;
}
new = xmalloc (sz+1);
strncpy (new, input_buffer, sz);
new[sz] = '\0';
names = xrealloc (names, sizeof (char *) * (n_names + 1));
names[n_names] = new;
n_names++;
/* move buffer ahead to next line */
input_buffer = position_of_newline + 1;
if (*position_of_newline == '\0')
input_buffer = NULL;
}
free (orig_input_buffer);
*package_names = names;
*n_package_names = n_names;
}
static char *
help_filter (int key, const char *text, void *input __attribute__ ((unused)))
{
return (char *)text;
}
static struct argp_option options[] = {
{ "comparitor", 'c', "COMPARITOR", 0, "[rpm-nvr-cmp|vers-nvr-cmp|rpmvercmp|strverscmp]", 0},
{ 0, }
};
struct arguments
{
size_t ninputs;
size_t input_max;
char **inputs;
};
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
struct arguments *arguments = state->input;
switch (key)
{
case 'c':
if (!strcmp(arg, "rpm-nvr-cmp") || !strcmp(arg, "rpmnvrcmp"))
comparitor = RPMNVRCMP;
else if (!strcmp(arg, "vers-nvr-cmp") || !strcmp(arg, "versnvrcmp"))
comparitor = VERSNVRCMP;
else if (!strcmp(arg, "rpmvercmp"))
comparitor = RPMVERCMP;
else if (!strcmp(arg, "strverscmp"))
comparitor = STRVERSCMP;
else
err(1, "Invalid comparitor \"%s\"", arg);
break;
case ARGP_KEY_ARG:
assert (arguments->ninputs < arguments->input_max);
arguments->inputs[arguments->ninputs++] = xstrdup (arg);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = {
options, argp_parser, "[INPUT_FILES]",
"Sort a list of strings in RPM version sort order.",
NULL, help_filter, NULL
};
int
main (int argc, char *argv[])
{
struct arguments arguments;
char **package_names = NULL;
size_t n_package_names = 0;
int i;
memset (&arguments, 0, sizeof (struct arguments));
arguments.input_max = argc+1;
arguments.inputs = xmalloc ((arguments.input_max + 1)
* sizeof (arguments.inputs[0]));
memset (arguments.inputs, 0, (arguments.input_max + 1)
* sizeof (arguments.inputs[0]));
/* Parse our arguments */
if (argp_parse (&argp, argc, argv, 0, 0, &arguments) != 0)
errx(1, "%s", "Error in parsing command line arguments\n");
/* If there's no inputs in argv, add one for stdin */
if (!arguments.ninputs)
{
arguments.ninputs = 1;
arguments.inputs[0] = xmalloc (2);
strcpy(arguments.inputs[0], "-");
}
for (i = 0; i < arguments.ninputs; i++)
add_input(arguments.inputs[i], &package_names, &n_package_names);
if (package_names == NULL || n_package_names < 1)
errx(1, "Invalid input");
qsort (package_names, n_package_names, sizeof (char *),
package_version_compare);
/* send sorted list to stdout */
for (i = 0; i < n_package_names; i++)
{
fprintf (stdout, "%s\n", package_names[i]);
free (package_names[i]);
}
free (package_names);
for (i = 0; i < arguments.ninputs; i++)
free (arguments.inputs[i]);
free (arguments.inputs);
return 0;
}