[opensuse-packaging] Are bashisms in RPM scriptlets allowed?

Hello, are bashisms in RPM scriptlets allowed? Up to now I ignorantly assumed that bash is used for RPM scriptlets so that bashisms in RPM scriptlets "just work". But I got https://build.opensuse.org/request/show/260498 By Googling for "bash rpm scriptlet site:opensuse.org" I did not find an authoritative answer. In particular neither https://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets nor https://en.opensuse.org/openSUSE:Specfile_guidelines helps. I found http://lists.opensuse.org/opensuse-packaging/2010-03/msg00076.html where comments therein seem to indicate that bash is o.k. for shell scripts but to be on the safe side one should explicitly require it via "#!/bin/bash" shebang but as far as I know I cannot have a bash shebang in RPM scriptlets. FYI: https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Default_Shell reads: "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." Kind Regards Johannes Meixner -- SUSE LINUX GmbH -- Maxfeldstrasse 5 -- 90409 Nuernberg -- Germany HRB 21284 (AG Nuernberg) GF: Jeff Hawn, Jennifer Guild, Felix Imendoerffer -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

On Wednesday 2014-11-12 16:21, Johannes Meixner wrote:
are bashisms in RPM scriptlets allowed?
If you do use them, be sure to use %post -p /bin/bash
In particular neither https://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets nor https://en.opensuse.org/openSUSE:Specfile_guidelines helps.
I found http://lists.opensuse.org/opensuse-packaging/2010-03/msg00076.html where comments therein seem to indicate that bash is o.k. for shell scripts but to be on the safe side one should explicitly require it via "#!/bin/bash" shebang but as far as I know I cannot have a bash shebang in RPM scriptlets.
That is because the shebang at the start of %post is not necessarily the first line in /var/tmp/rpm-xxxxxxx.xxxx. Hence -p. -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

On Wednesday 2014-11-12 16:25, Jan Engelhardt wrote:
are bashisms in RPM scriptlets allowed?
If you do use them, be sure to use %post -p /bin/bash
In particular neither https://en.opensuse.org/openSUSE:Packaging_scriptlet_snippets nor https://en.opensuse.org/openSUSE:Specfile_guidelines helps.
I would love to see - someday - /bin/sh pointing to a non-bash. Any bashism-requiring scripts or rpm scriptlets should just be honest and indicate so via requesting /bin/bash. To that end, I also edited those pages. -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

Johannes Meixner <jsmeix@suse.de> writes:
I found http://lists.opensuse.org/opensuse-packaging/2010-03/msg00076.html where comments therein seem to indicate that bash is o.k. for shell scripts but to be on the safe side one should explicitly require it via "#!/bin/bash" shebang but as far as I know I cannot have a bash shebang in RPM scriptlets.
%post -p /bin/bash Andreas. -- Andreas Schwab, SUSE Labs, schwab@suse.de GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7 "And now for something completely different." -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org

Hello, On Wed, 12 Nov 2014, Johannes Meixner wrote:
are bashisms in RPM scriptlets allowed?
Avoid them whenever easily doable. Use POSIX shell only (use dash/ash/busybox to check, calling bash as /bin/sh does _NOT_ suffice[1]!) http://www.in-ulm.de/~mascheck/various/portability/ (and all the stuff around that page ;) Sven is the guru on shell-oddities and portability issues. -dnh [1] easy example: $ cat foo.sh foo () { x=( "foo" "bar" "fu bar" "baz" ); for i in "${x[@]}"; do printf " »%s«" "$i"; done; echo } foo $ ls -l /bin/sh /bin/ksh /etc/alternatives/ksh lrwxrwxrwx 1 root root 4 Nov 4 22:53 /bin/sh -> bash lrwxrwxrwx 1 root root 21 May 19 2011 /bin/ksh -> /etc/alternatives/ksh* lrwxrwxrwx 1 root root 10 May 19 2011 /etc/alternatives/ksh -> /bin/pdksh* $ /bin/bash foo.sh »foo« »bar« »fu bar« »baz« $ /bin/sh foo.sh »foo« »bar« »fu bar« »baz« $ /bin/zsh foo.sh »foo« »bar« »fu bar« »baz« $ /bin/pdksh foo.sh foo.sh[3]: syntax error: `(' unexpected $ /bin/ksh foo.sh foo.sh[3]: syntax error: `(' unexpected $ /bin/ash foo.sh foo.sh: 3: Syntax error: word unexpected (expecting ")") $ /bin/dash foo.sh foo.sh: 3: foo.sh: Syntax error: "(" unexpected (expecting "}") $ /usr/bin/busybox sh foo.sh foo.sh: line 3: syntax error: unexpected "(" (expecting "}") $ /bin/sash -c 'x=("foo" "bar" "fu bar" "baz"); for i in "${x[@]}"; > do > printf " »%s«" "$i"; > done; > echo;' »foo« »bar« »fu bar« »baz« (but sash won't handle the foo.sh script) -- "I have a very firm grasp on reality! I can reach out and strangle it any time!" -- from the BSD fortune file -- To unsubscribe, e-mail: opensuse-packaging+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-packaging+owner@opensuse.org
participants (4)
-
Andreas Schwab
-
David Haller
-
Jan Engelhardt
-
Johannes Meixner