Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior when using -q --queryformat in %pre scriplet #1331

Closed
idzikovsky opened this issue Aug 13, 2020 · 2 comments
Closed

Unexpected behavior when using -q --queryformat in %pre scriplet #1331

idzikovsky opened this issue Aug 13, 2020 · 2 comments

Comments

@idzikovsky
Copy link

I need to backup some conf files of my package during upgrade into directory called e.g /mypackage-<old-version>.
So I'm trying to get old package version in %pre scriplet and doing it in the following way:

%pre
VERS=$(rpm --queryformat='%{VERSION}' -q mypackage)
VERS_ALTERNATIVE=$(rpm -qi mypackage | awk -F': ' '/Version/ {print $2}')

And the strange thing is that VERS variable got version of the package that I'm upgrading to (newer), while value of VERS_ALTERNATIVE contains version of the package that I'm upgrading from (older).

I'm do realize that invoking rpm -q in RPM scirplets is not the best idea, but anyway for me seems like this behavior is some kind of bug, as I suppose that in all cases result of rpm -qi and rpm --queryformat should output similar information.

I got this in CentOS 8 with RPM version 4.14.2. Same problem in CentOS 7.

@ffesti
Copy link
Contributor

ffesti commented Aug 13, 2020

%{VERSION} is replaced within the spec file itself. You need to use %%{VERSION} to avoid expanding the macro right away.
As you already said this is probably a really bad idea anyway. RPM actually does backup modified config files on it's own if they are tagged as config files in the package. Do things like this in a %pre script should not be necessary for all but very exotic cases.

@ffesti ffesti closed this as completed Aug 13, 2020
@idzikovsky
Copy link
Author

Thank you, and sorry for wrong bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants