1 |
commit: 39f5044b32d30c5296fc103cd573737c084e3787 |
2 |
Author: Chris Slycord <cslycord <AT> gmail <DOT> com> |
3 |
AuthorDate: Mon Mar 30 17:10:56 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Mar 30 17:10:56 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=39f5044b |
7 |
|
8 |
scripts/bootstrap-bash: fix bashisms, bug #714634 |
9 |
|
10 |
Closes: https://bugs.gentoo.org/714634 |
11 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
12 |
|
13 |
scripts/bootstrap-bash.sh | 43 +++++++++++++++++++++++++++++++++++-------- |
14 |
1 file changed, 35 insertions(+), 8 deletions(-) |
15 |
|
16 |
diff --git a/scripts/bootstrap-bash.sh b/scripts/bootstrap-bash.sh |
17 |
index a3d78afea0..b24015fc19 100755 |
18 |
--- a/scripts/bootstrap-bash.sh |
19 |
+++ b/scripts/bootstrap-bash.sh |
20 |
@@ -10,7 +10,7 @@ |
21 |
|
22 |
if [ -z "$1" ] ; then |
23 |
echo "usage: ${0} <location>" > /dev/stderr |
24 |
- exit -1 |
25 |
+ exit 255 |
26 |
fi |
27 |
|
28 |
mkdir -p "$1" |
29 |
@@ -20,6 +20,22 @@ cd bash-build |
30 |
|
31 |
GENTOO_MIRRORS=${GENTOO_MIRRORS:="http://distfiles.gentoo.org/distfiles"} |
32 |
|
33 |
+command_exists() { |
34 |
+ check_cmd="$1" |
35 |
+ command -v $check_cmd >/dev/null 2>&1 |
36 |
+} |
37 |
+ |
38 |
+same_file() { |
39 |
+ file1="$1" |
40 |
+ file2="$2" |
41 |
+ |
42 |
+ if [ "$(stat -c '%i%d' "$file1" "$file2" | sort -u | wc -l)" -eq 1 ]; then |
43 |
+ return 0 |
44 |
+ else |
45 |
+ return 1 |
46 |
+ fi |
47 |
+} |
48 |
+ |
49 |
if [ ! -e bash-4.2.tar.gz ] ; then |
50 |
eerror() { echo "!!! $*" 1>&2; } |
51 |
einfo() { echo "* $*"; } |
52 |
@@ -27,18 +43,29 @@ if [ ! -e bash-4.2.tar.gz ] ; then |
53 |
if [ -z ${FETCH_COMMAND} ] ; then |
54 |
# Try to find a download manager, we only deal with wget, |
55 |
# curl, FreeBSD's fetch and ftp. |
56 |
- if [ x$(type -t wget) == "xfile" ] ; then |
57 |
+ if command_exists wget; then |
58 |
FETCH_COMMAND="wget" |
59 |
- [ $(wget -h) == *"--no-check-certificate"* ] && FETCH_COMMAND+=" --no-check-certificate" |
60 |
- elif [ x$(type -t curl) == "xfile" ] ; then |
61 |
+ case "$(wget -h 2>&1)" in |
62 |
+ *"--no-check-certificate"*) |
63 |
+ FETCH_COMMAND="$FETCH_COMMAND --no-check-certificate" |
64 |
+ ;; |
65 |
+ esac |
66 |
+ elif command_exists curl; then |
67 |
einfo "WARNING: curl doesn't fail when downloading fails, please check its output carefully!" |
68 |
FETCH_COMMAND="curl -f -L -O" |
69 |
- elif [ x$(type -t fetch) == "xfile" ] ; then |
70 |
+ elif command_exists fetch; then |
71 |
FETCH_COMMAND="fetch" |
72 |
- elif [ x$(type -t ftp) == "xfile" ] && |
73 |
- [ ${CHOST} != *-cygwin* || ! $(type -P ftp) -ef $(cygpath -S)/ftp ] ; then |
74 |
+ elif command_exists ftp; then |
75 |
FETCH_COMMAND="ftp" |
76 |
- else |
77 |
+ case "${CHOST}" in |
78 |
+ *-cygwin*) |
79 |
+ if same_file "$(command -v ftp)" "$(cygpath -S)/ftp"; then |
80 |
+ FETCH_COMMAND='' |
81 |
+ fi |
82 |
+ ;; |
83 |
+ esac |
84 |
+ fi |
85 |
+ if [ -z ${FETCH_COMMAND} ]; then |
86 |
eerror "no suitable download manager found (need wget, curl, fetch or ftp)" |
87 |
eerror "could not download ${1##*/}" |
88 |
eerror "download the file manually, and put it in ${PWD}" |