RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1003962 - RPM scriptlet -p option not documented
Summary: RPM scriptlet -p option not documented
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: doc-Packagers_Guide
Version: 7.4
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Adam Kvitek
QA Contact: ecs-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2013-09-03 14:59 UTC by daniel.neuberger
Modified: 2019-03-06 01:00 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-07-19 16:08:05 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description daniel.neuberger 2013-09-03 14:59:42 UTC
The fedora RPM guide does not document the -p option that can be passed to the RPM scriptlets.  It should probably be located here http://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch09s04s05.html, but I looked through the entire guide and couldn't find it.

The only only place I could find it documented is here https://fedoraproject.org/wiki/Packaging:ScriptletSnippets, but what it says is wrong.  It says:

"The basic syntax is similar to the %build, %install, and other sections of the rpm spec file. The scripts support a special flag, -p which allows the scriptlet to invoke a single program directly rather than having to spawn a shell to invoke the programs. (ie: %post -p /sbin/ldconfig)"

A more accurate description is:

"The basic syntax is similar to the %build, %install, and other sections of the rpm spec file. 

The scripts support a special flag, -p which specifies the interPreter that should be used to run the script (the default is /bin/sh).  Sometimes the -p option is used with no body in order to run a single command directly rather than having to spawn a shell to invoke the programs (i.e. %post -p /sbin/ldconfig).  Note that this form requires that there be nothing but white space (not even comments) until the next section begins."

Comment 1 Jamie Duncan 2013-09-06 03:19:09 UTC
Ben

I'm happy to help out with this one, if we can get it moving to a quick fix.

Thanks,

Jamie Duncan

Comment 2 Petr Kovar 2013-09-06 12:09:34 UTC
Moving to the Packager's Guide.

Comment 3 Jared Smith 2013-09-06 14:02:21 UTC
I've added a patch to the RPM Guide to add that clarification.  The new information should be part of git commit cc44b49e0977e4f50ae09f48b15b8367c59331de.  The new information should show up in the guide the next time the document is rebuilt.

Just as an FYI, the RPM Guide is fairly old and not being actively maintained like it should be.  There's a new effort underway to take the most important information from the RPM Guide and build a Packager's Guide, but that guide doesn't yet go into any detail on scripts.  Petr Kovar reassigned this bug to him, so hopefully he'll add something to the Packager's Guide about scriptlets.

Comment 4 daniel.neuberger 2013-09-06 14:19:40 UTC
Thanks for adding the patch.

Why was the decision made to create a new guide rather than just renaming or updating the old guide?

Also, wouldn't it make more sense to start by documenting the spec file syntax/"language" as part of the rpm-build rpm?  It seems like the problem is that there's a tool, rpmbuild, that processes a syntax, spec files, that isn't documented or standardized.

In my mind, a "guide" is high level documentation that is very nice to have, but should be based on my low level documentation.  The low level documentation for the tool, rpmbuild, exists, but we're missing the low level documentation for what the tool processes, spec files.

Just some thoughts.  Thanks for the help.

Comment 5 Jared Smith 2013-09-06 16:03:15 UTC
(In reply to daniel.neuberger from comment #4)
> Thanks for adding the patch.

You're most welcome.

> Why was the decision made to create a new guide rather than just renaming or
> updating the old guide?

In short, for a couple of reasons.  The first reason is that the exiting guide is a bit overwhelming to new packagers, and we really wanted to have a guide focused on helping novice packagers get up to speed.

The second reason is the simple fact that updating the existing guide would be an enormous undertaking, and nobody has volunteered to step up and do the work.  There's nothing that says we can't have two guides, we just need help to do the work.

> Also, wouldn't it make more sense to start by documenting the spec file
> syntax/"language" as part of the rpm-build rpm?  It seems like the problem
> is that there's a tool, rpmbuild, that processes a syntax, spec files, that
> isn't documented or standardized.

It makes sense to me, but I'm just a volunteer, and I don't have either the time or inclination to dive into documenting every detail at that level.  Until someone volunteers to do the work or gets asked to do it as part of their day job, it's just wishes and dreams.  

One of the unfortunate truths is that writing documentation isn't sexy, and in open source communities, it often doesn't get the attention that developing new code does.  As with everything else in open source, we either have to scratch the itch ourselves, pay someone to scratch it for us, or find a way to convince someone else that it's their itch.

Comment 6 daniel.neuberger 2013-09-06 16:18:00 UTC
Thanks Jared for all the info.  Unfortunately, I can't undertake the complete task myself either (at least not right now).  I will do my best to help push things in the right direction and contribute bits and pieces as I go along with my work.

Comment 7 Petr Kovar 2017-12-14 09:41:27 UTC
The Fedora packager guide has been deprecated in favor of https://github.com/redhat-developer/rpm-packaging-guide/.

Moving this bug to the RHEL version of redhat-developer/rpm-packaging-guide to investigate if this still is a relevant issue.

Comment 9 Miroslav Suchý 2018-05-18 09:34:46 UTC
The most common example for -p is with ldconfig:
  https://fedoraproject.org/wiki/Packaging:Scriptlets#Linker_Configuration_Files

But... we are trying to get rid of this in recent Fedora (and *this one* is not needed), so I would rather choose some different example.

Hmm I would propose this wordings:

The scripts support a special flag, -p, which allows the scriptlet to invoke a particular interpreter instead of the default -p /bin/sh. If you use bashisms in a scriptlet, it would be prudent to specify -p /bin/bash.

You can specify any interpreter `%post -p /usr/bin/python3` and write your script in python3. Just do not forget to specify it as dependecy: `Requires(post): python3`. 

You can use `%post -p <lua>` and then write your script in lua, which is embeded directly into rpm. This is in fact your only choice if you are going to write %pretrans script, because when installing system from scratch there is not even bash when transaction starts.

The -p option may also be used to invoke one program directly without the shell indirection, e.g. by using %post -p /sbin/ldconfig. 

The scriptlets also take an argument, passed into them by the controlling rpmbuild process. This argument, accessed via $1, is the number of packages of this name which will be left on the system when the action completes, except for %pretrans and %posttrans, which are always run with $1 set to 0. (%pretrans and %posttrans are available in rpm 4.4 and later). So, for the common case of install, upgrade, and uninstall, we have:

	install 	upgrade 	uninstall
 %pretrans 	$1 == 0 	$1 == 0 	(N/A)
 %pre 	$1 == 1 	$1 == 2 	(N/A)
 %post 	$1 == 1 	$1 == 2 	(N/A)
 %preun 	(N/A) 	$1 == 1 	$1 == 0
 %postun 	(N/A) 	$1 == 1 	$1 == 0
 %posttrans 	$1 == 0 	$1 == 0 	(N/A)

Comment 10 Adam Kvitek 2018-05-23 16:47:58 UTC
Hello Miroslav,

thank you for very useful explanation.

Could you please send me an example of simple script written in python3 which is commonly used with -p /usr/bin/python3? I will make a whole chapter about -p around this example.

Thank you!

Comment 11 Miroslav Suchý 2018-05-24 08:41:40 UTC
It is definitely not used commonly. There are some cases. E.g., https://stackoverflow.com/questions/50137854/python-behaves-differently-giving-unwanted-extra-string-when-executed-via-rpm-sp
But this is very rare. Yet, we should mention it.
I recommend to use a just artificial example:

%post -p /usr/bin/python3
print("This is {} code".format("python"))

Comment 12 Adam Kvitek 2018-05-24 16:48:36 UTC
New chapter submitted in a pull request:
https://github.com/redhat-developer/rpm-packaging-guide/pull/46

Comment 13 Adam Kvitek 2018-06-20 11:49:20 UTC
New chapter merged in master branch. Pull request closed. 
https://github.com/redhat-developer/rpm-packaging-guide/pull/46

Comment 14 Adam Kvitek 2018-07-19 16:23:38 UTC
New chapter published. As 6.4.2.1. with a title: Using Non-Shell Scripts in spec File. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/rpm_packaging_guide/advanced-topics#triggers-and-scriptlets


Note You need to log in before you can comment on or make changes to this bug.