Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 714634

Summary: gentoo-prefix project bootstrap-bash.sh has bashisms and invalid code
Product: Gentoo/Alt Reporter: Chris Slycord <cslycord>
Component: Prefix SupportAssignee: Gentoo Prefix <prefix>
Status: RESOLVED FIXED    
Severity: normal CC: jstein
Priority: Normal Keywords: PATCH
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: diff -u bootstrap-bash_orig.sh bootstrap-bash.sh

Description Chris Slycord 2020-03-25 07:27:49 UTC
https://gitweb.gentoo.org/repo/proj/prefix.git/plain/scripts/bootstrap-bash.sh

bootstrap-bash.sh is meant to be a posix-compliant script run on /bin/sh to allow one to install bash.

type -t (lines 30, 33, 36,38)
type -P (line 39)
string comparison using globs (lines 32, 39)
comparisons with '==' instead of '=' (lines 30, 32, 33, 36, 38)
comparing equality of two files using '-ef'
modification of string variable with "+=" (line 32)

All of these are not present posix.

Also, on line 13 it has "exit -1", but exit codes can only be 0-255

Reproducible: Always

Steps to Reproduce:
1. Download bootstrap-bash.sh and run it on a posix shell
2.
3.
Actual Results:  
POSIX non-compliant code in script

Ex: The script refuses to run on a busybox /bin/sh

Expected Results:  
script to comply with POSIX

The type -t/-P usages can be replaced with "command -v" for portability
The glob comparisons can be swapped for case statements
And the "-ef" comparison can be replaced using a call to "stat"
Comment 1 Chris Slycord 2020-03-25 07:41:06 UTC
Created attachment 625438 [details, diff]
diff -u bootstrap-bash_orig.sh bootstrap-bash.sh

unified diff of a working and posix-compliant bootstrap-bash.sh

Moved the checks for commands into a function using "command -v" and moved the check for files being the same in the cygwin case into its own function for readability.
Comment 2 Larry the Git Cow gentoo-dev 2020-03-30 17:11:44 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=39f5044b32d30c5296fc103cd573737c084e3787

commit 39f5044b32d30c5296fc103cd573737c084e3787
Author:     Chris Slycord <cslycord@gmail.com>
AuthorDate: 2020-03-30 17:10:56 +0000
Commit:     Fabian Groffen <grobian@gentoo.org>
CommitDate: 2020-03-30 17:10:56 +0000

    scripts/bootstrap-bash: fix bashisms, bug #714634
    
    Closes: https://bugs.gentoo.org/714634
    Signed-off-by: Fabian Groffen <grobian@gentoo.org>

 scripts/bootstrap-bash.sh | 43 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 8 deletions(-)
Comment 3 Fabian Groffen gentoo-dev 2020-03-30 17:12:07 UTC
applied your patch, thanks