Bug 850706 - Change default scriptlet interpreter to /bin/bash
Summary: Change default scriptlet interpreter to /bin/bash
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Fedora
Classification: Fedora
Component: redhat-rpm-config
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Panu Matilainen
QA Contact: Fedora Extras Quality Assurance
URL: https://fedoraproject.org/wiki/Packag...
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-08-22 07:46 UTC by Petr Pisar
Modified: 2020-11-03 21:44 UTC (History)
10 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-09-06 05:36:57 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Petr Pisar 2012-08-22 07:46:32 UTC
When building a package with scriptlet without specifying an interpreter, default one is bash according to new Fedora packaging guidelines (https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Default_Shell).

However current rpmbuild behavior is to execute and put dependency on /bin/sh and /bin/sh denotes POSIX shell.

Please change rpmbuild to make /bin/bash the default interpreter.

Comment 1 Panu Matilainen 2012-08-22 10:44:59 UTC
And what if you're not building for Fedora but something else? Fedora guidelines dont apply to the entire world.

Rpm has ALWAYS defaulted to /bin/sh aka POSIX shell, and silently changing that is nothing but asking for trouble: bash does behave differently whether invoked as /bin/sh or /bin/bash.

One could always add a build-environment override macro for the default shell interpreter which redhat-rpm-config could set to /bin/bash or whatever, but even that seems like a bad idea to me: scriptlet behavior would then change depending on where it was built.

If you want to be explicit about relying on bash features, then use -p /bin/bash as the scriptlet interpreter, that works everywhere and has no silent side-effects. Anything else is just an assumption, and you know the saying about assumptions...

Comment 2 Petr Pisar 2012-08-22 11:32:07 UTC
Instead of the lengthy rant, you could move it to redhat-rpm-config component yourself. I filed it against rpm, because I was not aware it is possible to override it by external macro files.

Comment 3 Petr Pisar 2012-08-22 11:37:35 UTC
(In reply to comment #1)
> One could always add a build-environment override macro for the default
> shell interpreter which redhat-rpm-config could set to /bin/bash or
> whatever, but even that seems like a bad idea to me: scriptlet behavior
> would then change depending on where it was built.
> 
Have you read linked packaging guidelines? They mandate the scriptlets are bash language now. So in this light, Fedora build system does not comply to the guidelines and any produced package is possibly broken now.

(I also think this was stupid decision, but that's all I can do).

Comment 4 Panu Matilainen 2012-08-22 11:51:54 UTC
(In reply to comment #2)
> Instead of the lengthy rant, you could move it to redhat-rpm-config
> component yourself. I filed it against rpm, because I was not aware it is
> possible to override it by external macro files.

Sorry I wasn't clear: no such override exists. What I meant is that of course support for such a thing technically *could* be added to rpmbuild, which distro config could then override. But like said, that seems like a bad idea to me. Only individual specs are in position to knowingly override such things.

(In reply to comment #3)
> Have you read linked packaging guidelines? They mandate the scriptlets are
> bash language now. So in this light, Fedora build system does not comply to
> the guidelines and any produced package is possibly broken now.

All I see is:
"In Fedora, you can assume that the default shell (/bin/sh) is bash. Thus, all scriptlets can safely assume that if they are running in shell code, they are running within bash."

So packagers are free to *assume* that /bin/sh is bash. And since /bin/sh is explicitly mentioned there, I read it as "Fedora packages can assume /bin/sh is actually bash, invoked as /bin/sh (and the differences in behavior vs invoked as /bin/bash still apply)

> (I also think this was stupid decision, but that's all I can do).

Decisions can be changed and guidelines can be adjusted.

Comment 5 Petr Pisar 2012-08-22 12:35:23 UTC
There are two problems:

(1) Invoking bash as /bin/sh is not the same as invoking /bin/bash. Despite the guidelines tries to persuade us. This is bug in guidelines and they should be fixed.

(2) Assuming the guidelines recommend using bash language without explicit /bin/bash specification, they are not compatible with Fedora rpmbuild. And the whole guidelines statement should be removed (or better replaced with `default is POSIX shell'), or rpmbuild should obey.


I thing it's time for Fedora Packaging Committee: <https://fedorahosted.org/fpc/ticket/184#comment:5>.

Comment 6 Panu Matilainen 2012-08-22 13:07:53 UTC
So we dont really disagree. What I'm objecting to is the proposed change to rpmbuild defaults as that would just shift the issues elsewhere / create new problems.

Perhaps the most constructive thing would be having rpmbuild optionally run scriptlets without explicit interpreter through checkbashisms and change interpreter to /bin/bash if any bashisms are found. Obviously such its just a heuristic but probably better than the alternatives.

Comment 7 Petr Pisar 2012-08-22 13:35:08 UTC
Implementing some heuristics sounds like a sweeping dust under the carpet. Packagers need reliable environment. Having a fuzzy interpret is not a good way. This problem (packages use bashism → let's lie /bin/sh is bash → let's pick interpreter randomly) is like stashing hacks on hacks.

I do not request changing rpmbuild in upstream RPM. I wish this distribution guidelines and tools would be compatible and support themselves to produce solid distribution. I have no problem with defining default interpreter in guidelines or in rpm/redhat-rpm-config. Actually I welcome it. The only problem is they are in conflict now.

I think making the default interpreter configurable using redhat-rpm-config would be the best option: It would comply with guidelines, it would not require editing each spec file, and it would allow other distributions to pick they favorite shell.

Comment 8 Toshio Ernie Kuratomi 2012-09-05 17:31:43 UTC
(In reply to comment #4)
> 
> All I see is:
> "In Fedora, you can assume that the default shell (/bin/sh) is bash. Thus,
> all scriptlets can safely assume that if they are running in shell code,
> they are running within bash."
> 
> So packagers are free to *assume* that /bin/sh is bash. And since /bin/sh is
> explicitly mentioned there, I read it as "Fedora packages can assume /bin/sh
> is actually bash, invoked as /bin/sh (and the differences in behavior vs
> invoked as /bin/bash still apply)
> 
Thanks Panu, I think that's exactly what we mean.

Comment 9 Panu Matilainen 2012-09-06 05:36:57 UTC
Having thought about this (and then almost forgotten...) Any method of having rpm silently force /bin/bash execution would only make things much worse: suddenly the very same scripts would behave differently depending on which system it was built on. Now *that* is broken.

If you want/need to create "portable" packages, limit yourself to POSIX shell capabilities, OR specify an alternative interpreter and write the scripts according to that knowingly selected shell. The Fedora guidelines simply document the de-facto standard within Fedora, giving packagers a blanket permission to close cases like bug 743448 as NOTABUG.

Comment 10 Matthew Miller 2014-10-06 16:55:58 UTC
How about we define it as "/bin/bash --posix" rather than "/bin/sh (defined to be bash"?

Comment 11 Panu Matilainen 2014-10-07 07:24:17 UTC
How about we first define the actual problem that is being solved?

Introducing a Fedora specific quirk/incompatibility to every single package built on Fedora (and future RHEL) just because some 0.5% of Fedora scriptlets use bashishms doesn't seem sensible to me. What exactly is wrong with telling packagers be explicit about what shell dialect they're scripting in?

Comment 12 Aaron D. Marasco 2020-11-03 21:44:18 UTC
I know this is a really old bug, but it's one of the top Google search results and one of the other hits points back to it.

When building RPMs in CentOS 7 (don't know the RPM version off-hand), the "-p" option doesn't work on the "%install" stanza, so you need to force:

%global _buildshell /bin/bash


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