Mailinglist Archive: opensuse-factory (602 mails)

< Previous Next >
Re: [opensuse-factory] Can we assume that /bin/sh is bash?
On Fri, 8 Feb 2019 at 13:23, Martin Wilck <mwilck@xxxxxxxx> wrote:

Hi Jan, all,

I'd like to carry our OBS dicussion to a wider audience
(https://build.opensuse.org/request/show/672510).

The question is whether we can assume that "/bin/sh" links to bash,
in particular whether rpm scriptlets without explicit -p interpreter
can be assumed to interpreted by bash.

I'm aware that, in principle, /bin/sh is supposed to be the Bourne
shell on Unix systems. But as a matter of fact, on current openSUSE, it
is not. Unless it's tampered with, /bin/sh is a symlink to /bin/bash.
bash is not started in full POSIX mode if invoked as /bin/sh, and even
if it's in POSIX mode, it supports some extensions over the POSIX shell
spec (e.g. the [[ ]] construct), which makes it behave differently than
another shell not supporting [[ ]] would (*). Problably there are more
differences, I can't claim to know them all.

Here are some arguments why I think it'd be reasonable to assume that
/bin/sh is bash on openSUSE:

1. patterns-base-minimal_base depends on bash, and the /bin/sh symlink
is a non-configurable part of the "bash" package.
2. we could handle /bin/sh via /etc/alternatives, but we don't.
3. our Wiki suggests testing failing scriplets using "bash -xv"
(https://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets)
4. /bin/sh has pointed to bash for a long time (not sure how long
exactly).

FTR, Fedora basically guarantees (sh == bash) for the purpose of rpm
scriptlets (https://fedoraproject.org/wiki/Packaging:Scriptlets). So
Fedora <-> openSUSE portability may also be an issue to consider.

If we can't assume that /bin/sh is bash, what else can we assume? I
recall from earlier work that writing really 100% compatible shell code
for all kinds of environments is really hard. E.g., "[" isn't 100%
portable either, even though it's part of the POSIX "test" standard
(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html).

We should have clear rules which syntax expressions can be used in rpm
scriptlets, and which can't. IMO we should define one of the various
existing shells as a reference by saying "if it's supported
by this shell, it's valid scriptlet code". That'd be easier (especially
for testing compliance) than referring to a spec. That reference shell
doesn't have to be bash, of course.

Thanks
Martin

Thanks Martin,

I see two questions popping out of this post and the subsequent
discussion. I'm replying to the original because I wish to summarise
my views from the thread to date, rather than respond to details
specifically.

I see Question 1) as "should packaging submissions be rejected because
they assume /bin/sh is bash?"

My answer to this is a strong resounding, maybe even slightly grumpy, "No"

/bin/sh is currently not user configurable. There is no way, without
removing files owned by an openSUSE distribution package, to set
/bin/sh to be something other than /bin/bash.
In a growing number of supported openSUSE configurations (Kubic,
Transactional Server, etc) the user can't even do that given / is
read-only.
So, while I can see the benefit of avoiding bashisms, I really,
really, strongly object to any SR getting held up in any way manner or
form by any reviewer on the grounds that it assumes /bin/sh is
pointing to /bin/bash.

(Note, this really strong opinion is despite the fact that I'm a zsh
fanboy who sets /bin/zsh to his login shell for every user I use,
including root)

However this debate does bring up a second question

I see Question 2) as "should /bin/bash be /bin/sh in openSUSE?"

I do not have a strong answer to this at the moment.
I have never been comfortable with /bin/bash being /bin/sh, because of
the quirky nature of 'bashisms'.

But on the other hand, is there a suitably generic 'lowest common
denominator' alternative?
If the answer is yes, I can see how moving to something else could
have benefits.

For example, it has been mentioned dash would save ~800KiB or so
compared to bash
When you consider things like our container images, which don't really
contain much more than zypper and bash, that 800KiB saved in
every-single-container could be a huge benefit.

Maybe there is a better option that is even smaller and more standards
compliant?
I'd still advocate for /bin/bash being the default shell for users
(just like right now..we explicitly define /bin/bash in /etc/passwd,
not /bin/sh)

But I think /bin/sh should be the bare minimum, smallest, leanest,
most generic shell.
It needs to be something which any developer/packager should be sure
will act the same way in every-single openSUSE system.
This behaviour needs to be the same regardless of it being a server,
desktop, container, JeOS image, or whatever, and should be confident
that it will work in a very standards compliant way.

I'm not sure it needs to be bash, I'm open to the idea of it changing,
and I'm even willing to help with the insane amount of fallout that
could be caused if we do decide to change it ;)

Thoughts?
--
To unsubscribe, e-mail: opensuse-factory+unsubscribe@xxxxxxxxxxxx
To contact the owner, e-mail: opensuse-factory+owner@xxxxxxxxxxxx

< Previous Next >
References