Discussion:
Environment variables in RPM installation scripts
David Leangen
2006-08-07 07:05:57 UTC
Permalink
Hello!

According to the documentation I read, environment variables such as
$RPM_BUILD_DIR should be available to me during the %pre and %post parts
of my build.

However, they are not.


Can somebody tell me what I need to do to get access to this information
at build time?


Thank you!!
Jos Vos
2006-08-07 07:17:52 UTC
Permalink
Post by David Leangen
According to the documentation I read, environment variables such as
$RPM_BUILD_DIR should be available to me during the %pre and %post parts
of my build.
What are "%pre" and "%post" parts of the build? These sections are
used at install time.
--
-- Jos Vos <***@xos.nl>
-- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
-- Amsterdam, The Netherlands | Fax: +31 20 6948204
David Leangen
2006-08-07 07:24:47 UTC
Permalink
Hi,

Ok, I guess I got my vocabulary wrong.

In my spec file, I want to do some scripting in the %post macro.
However, nothing is being returned to me for the value of $RPM_BUILD_DIR
(or anything else, for that matter), so I'm not able to locate the build
files. When I try to install the RPM I built, I get a "no such file or
directory" error due to (for example) something like this:

%post
do_something $RPM_BUILD_DIR/some_file

Cheers,
David
Post by Jos Vos
Post by David Leangen
According to the documentation I read, environment variables such as
$RPM_BUILD_DIR should be available to me during the %pre and %post parts
of my build.
What are "%pre" and "%post" parts of the build? These sections are
used at install time.
Jos Vos
2006-08-07 07:35:27 UTC
Permalink
Post by David Leangen
In my spec file, I want to do some scripting in the %post macro.
However, nothing is being returned to me for the value of $RPM_BUILD_DIR
(or anything else, for that matter), so I'm not able to locate the build
files. [...]
Why/how should the *build* dir be available at *install* time?
All files you need at install time should be in the package.
--
-- Jos Vos <***@xos.nl>
-- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
-- Amsterdam, The Netherlands | Fax: +31 20 6948204
David Leangen
2006-08-07 07:42:11 UTC
Permalink
Hi!

The build dir was an example. I guess what I really need is the source.

I want to apply a post-installation patch.

Are you suggesting that I put my patch file with the %files in a
known location and use it from there?

I don't really want to install the patch file as part of the
installation... All I want to do is something like:

%post
patch -p0 < my_patch_file


How would you do this?


Thanks for the comments!
Post by Jos Vos
Post by David Leangen
In my spec file, I want to do some scripting in the %post macro.
However, nothing is being returned to me for the value of
$RPM_BUILD_DIR
(or anything else, for that matter), so I'm not able to locate the build
files. [...]
Why/how should the *build* dir be available at *install* time?
All files you need at install time should be in the package.
--
-- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
-- Amsterdam, The Netherlands | Fax: +31 20 6948204
David Nečas (Yeti)
2006-08-07 07:46:51 UTC
Permalink
Post by David Leangen
The build dir was an example. I guess what I really need is the source.
I want to apply a post-installation patch.
Are you suggesting that I put my patch file with the %files in a
known location and use it from there?
I don't really want to install the patch file as part of the
%post
patch -p0 < my_patch_file
If you can make the patch at build time why don't you patch
it in %install and package already patched files?

Yeti


--
Anonyms eat their boogers.
David Leangen
2006-08-07 07:54:29 UTC
Permalink
Good question!

Yes, I suppose this would be a simple fix, but... In a few places in
the RPM docs, they say that it is not good practice to modify files
that were installed from another package. The files I want to modify
are not files that "belong" to me.

Specifically, I am modifying the *.repo files in /etc/yum.repos.d. I
add my own files, but I want to disable the default fedora files that
were installed by yum.

When I uninstall my package, I would simple reverse the patch to
restore the default yum config files to their original states.

In any case, I can't add any new files from %files, because it gives
me an error saying that these files belong to another package.


I suppose I could install the "updated" files under a new name in a
known location, them apply the patch. Would that be the standard way
of doing what I'm trying to do?


Thanks again!!
Post by David Nečas (Yeti)
Post by David Leangen
The build dir was an example. I guess what I really need is the source.
I want to apply a post-installation patch.
Are you suggesting that I put my patch file with the %files in a
known location and use it from there?
I don't really want to install the patch file as part of the
%post
patch -p0 < my_patch_file
If you can make the patch at build time why don't you patch
it in %install and package already patched files?
Yeti
--
Anonyms eat their boogers.
_______________________________________________
Rpm-list mailing list
https://www.redhat.com/mailman/listinfo/rpm-list
David Leangen
2006-08-07 07:58:05 UTC
Permalink
Post by David Leangen
I suppose I could install the "updated" files under a new name in a
known location, them apply the patch. Would that be the standard
way of doing what I'm trying to do?
Sorry... what I said won't work. I don't want to install the patch
file itself, and, IIUC, it is not a good idea to overwrite the yum
config files.


Cheers,
David
Jim Wildman
2006-08-07 10:15:46 UTC
Permalink
Post by David Leangen
Post by David Leangen
I suppose I could install the "updated" files under a new name in a
known location, them apply the patch. Would that be the standard
way of doing what I'm trying to do?
Sorry... what I said won't work. I don't want to install the patch
file itself, and, IIUC, it is not a good idea to overwrite the yum
config files.
Supply the patch file (or the complete file itself) as a 'here' document in
%post, or a sed script. Since it is not part of %files, rpm won't complain
about a conflict. Of course, rpm -V will report that the file has
changed, but that is as expected.

------------------------------------------------------------------------
Jim Wildman, CISSP, RHCE ***@rossberry.com http://www.rossberry.com
"Society in every state is a blessing, but Government, even in its best
state, is a necessary evil; in its worst state, an intolerable one."
Thomas Paine
David Leangen
2006-08-07 12:35:23 UTC
Permalink
Post by Jim Wildman
Post by David Leangen
Post by David Leangen
I suppose I could install the "updated" files under a new name in a
known location, them apply the patch. Would that be the standard
way of doing what I'm trying to do?
Sorry... what I said won't work. I don't want to install the patch
file itself, and, IIUC, it is not a good idea to overwrite the yum
config files.
Supply the patch file (or the complete file itself) as a 'here'
document in %post, or a sed script. Since it is not part of
%files, rpm won't complain about a conflict. Of course,
rpm -V will report that the file has changed, but that is
as expected.
Excuse me if this is a silly question, but what do you mean by a "'here'
document"?

Do you have any examples?


Thanks so much!
Luciano Miguel Ferreira Rocha
2006-08-07 12:56:57 UTC
Permalink
Post by David Leangen
Excuse me if this is a silly question, but what do you mean by a "'here'
document"?
patch -p0 <<'EOF'
+++ zbr
--- zbr
....
EOF

Another solution, for disabling the fedora's repos:
perl -pi -e 's/enabled=.*/enabled=0/' /etc/yum.repos.d/fedora*.repo
--
lfr
0/0
David Leangen
2006-08-08 00:50:59 UTC
Permalink
Oh, that's it. Thank you!

I'm still curious, though... in all the docs I read, I see variables
such as $RPM_SOURCE_DIR, or %{buildroot}, or whatever.

Was some design decision made recently to remove all of those? If
not, where can I find the list?


Thank you!
Post by Luciano Miguel Ferreira Rocha
Post by David Leangen
Excuse me if this is a silly question, but what do you mean by a "'here'
document"?
patch -p0 <<'EOF'
+++ zbr
--- zbr
....
EOF
perl -pi -e 's/enabled=.*/enabled=0/' /etc/yum.repos.d/fedora*.repo
--
lfr
0/0
_______________________________________________
Rpm-list mailing list
https://www.redhat.com/mailman/listinfo/rpm-list
David Leangen
2006-08-08 14:00:22 UTC
Permalink
For the sake of anybody following this thread archived in 10 years, I
finally found how this works.

There are tons of macros defined in the file /usr/lib/rpm/macros.

For example, the macros %_topdir and %_builddir are available, which is what
I was looking for all along.


Thanks to all who helped me out.
Jos Vos
2006-08-08 14:09:39 UTC
Permalink
Post by David Leangen
For example, the macros %_topdir and %_builddir are available, which is what
I was looking for all along.
Yes, but you can't/should use it for your purpose, as the build dir
is not supposed to be available on the install system.
--
-- Jos Vos <***@xos.nl>
-- X/OS Experts in Open Systems BV | Phone: +31 20 6938364
-- Amsterdam, The Netherlands | Fax: +31 20 6948204
David Leangen
2006-08-09 02:11:11 UTC
Permalink
Post by Jos Vos
Post by David Leangen
For example, the macros %_topdir and %_builddir are available,
which is what I was looking for all along.
Yes, but you can't/should use it for your purpose, as the build dir
is not supposed to be available on the install system.
Good point!

Thank you.
Bob Proulx
2006-08-12 08:07:27 UTC
Permalink
Post by David Leangen
I'm still curious, though... in all the docs I read, I see variables
such as $RPM_SOURCE_DIR, or %{buildroot}, or whatever.
Was some design decision made recently to remove all of those? If
not, where can I find the list?
Those variables are available at build time in the %prep, %build, and
%install scripts. They were not removed. You have been trying to use
them at %post script time which will often be on a different system
perhaps on a different continent from the build machine.

Bob

Loading...