-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
setup-util-bash
executable file
Β·181 lines (169 loc) Β· 6.4 KB
/
setup-util-bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env bash
# https://repology.org/project/bash/versions
function setup_util_bash() (
source "$DOROTHY/sources/bash.bash"
# imports:
# IS_BASH_VERSION_OUTDATED
# BASH_VERSION_CURRENT
# BASH_VERSION_LATEST
# improve performance for detectable utilities with conditional assets
if test "$IS_BASH_VERSION_OUTDATED" = 'no' -a "${RELOADED_IN_SYSTEM_BASH-}" != 'yes' && setup-util "$@" --check --cli=bash; then
return 0
fi
# check if we are macos, in which we need special handling
if test "${RELOADED_IN_SYSTEM_BASH-}" != 'yes'; then
if is-needle --upgrade -- "$@" || is-needle --uninstall -- "$@"; then
# upgrading or uninstalling
if is-mac && test -x /bin/bash && brew-installed --formula --quiet -- bash; then
# reload in system bash to pevent brew's upgrade/uninstall from crashing us
env RELOADED_IN_SYSTEM_BASH=yes /bin/bash "${BASH_SOURCE[0]}" "$@"
return
fi
else
# not upgrading or uninstalling
if test "$IS_BASH_VERSION_OUTDATED" = 'yes'; then
# bash is terrible outdated
if is-mac && test -x /bin/bash; then
# run in system bash to prevent possible upgrade crash
env RELOADED_IN_SYSTEM_BASH=yes /bin/bash "${BASH_SOURCE[0]}" --upgrade "$@"
return
else
# run ourself again with upgrade
env RELOADED_IN_SYSTEM_BASH=yes "${BASH_SOURCE[0]}" --upgrade "$@"
return
fi
fi
fi
fi
# enable DOWNLOAD_BUILD_INSTALL
source "$(type -P setup-util)"
# setup bash
local bottle_url='' macos_release arch options=(
--cli='bash'
"$@"
APK='bash' # ALPINE
APT='bash' # UBUNTU
AUR='bash' # ARCH
BREW='bash'
EMERGE='app-shells/bash' # GENTOO
NIX='nixpkgs.bash'
RPM='bash' # FEDORA
URPMI='bash' # MAGEIA
XBPS='bash' # VOID
ZYPPER='bash' # SUSE
)
function do_install {
# dependencies
setup-util-devel --quiet
source "$DOROTHY/sources/environment.sh"
# build
./configure
make install
}
function do_uninstall {
# dependencies
setup-util-devel --quiet
source "$DOROTHY/sources/environment.sh"
# build
./configure
make uninstall
}
arch="$(get-arch)"
if is-mac; then
# fetch the bottle urls via: brew info --json bash | jq -r ".[].bottle.stable.files"
macos_release="$(get-macos-release-name)"
if test "$arch" = 'a64'; then
if test "$macos_release" = 'sequoia'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:066b7eba204091b70860d2f17d0dd65201900b3e3ca32de87a746ed1baf13332'
elif test "$macos_release" = 'sonoma'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:bd484090760c2736fa30e29a7861aaf115330bfb10178ce398e1f927a056a047'
elif test "$macos_release" = 'ventura'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:f3a42b9282e6779504034485634a2f3e6e3bddfc70b9990e09e66e3c8c926b7d'
elif test "$macos_release" = 'monterey'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:5e7e3e3387fc60e907683b437ac6e64879e117a3c5c1421fe6e6257f6aaa3c69'
elif test "$macos_release" = 'big_sur'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:d19858831275271cc8aa9a1a28de6223faa44c6ebbc88e83898fd559de5b627e'
fi
elif test "$arch" = 'x64'; then
if test "$macos_release" = 'sonoma'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:354e107695c01f1b970174487d0f5e501774c485b60e13f95141884b31ba883d'
elif test "$macos_release" = 'ventura'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:fd01a9dbdc56f6313a725cb345a3b991cfdaa9e1a91b08fd9791a0e695b55723'
elif test "$macos_release" = 'monterey'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:05a5f9435c9e9ffe8377b03e0ca6b27bbb32cc01aff47dd1692cd8d7e735ab3a'
elif test "$macos_release" = 'big_sur'; then
bottle_url='https://ghcr.io/v2/homebrew/core/bash/blobs/sha256:680dd3b37e17cc4fa1af6dd8c51c774dd0c9aa3e594e96527020845516b1ea77'
fi
fi
fi # don't use linux bottle, as linux is too varied, and doesn't work on opensuse/leap: https://github.com/bevry/dorothy/actions/runs/6048593518/job/16414257095
if test -n "$bottle_url" && fetch --bearer-token='QQ==' --ok "$bottle_url"; then
options+=(
DOWNLOAD="$bottle_url"
DOWNLOAD_BEARER_TOKEN='QQ=='
DOWNLOAD_ARCHIVE_FORMAT='tar'
DOWNLOAD_ARCHIVE_GLOB='bash/*/bin/bash'
)
else
options+=(
DOWNLOAD="https://ftp.gnu.org/gnu/bash/bash-${BASH_VERSION_LATEST}.tar.gz"
DOWNLOAD_ARCHIVE_FORMAT='tar'
DOWNLOAD_ARCHIVE_GLOB='bash-*/*'
DOWNLOAD_TARGET_PATH='/usr/local/bin/bash'
DOWNLOAD_BUILD_INSTALL='do_install'
DOWNLOAD_BUILD_UNINSTALL='do_uninstall'
)
fi
setup_util "${options[@]}"
# check if the updated bash outdated, if so, install via building instead
# this works as it is new invocation so has refreshed env vars inside it
if is-bash-version-outdated --quiet; then
options+=(
--upgrade
--order='download ...'
)
setup_util "${options[@]}"
fi
# setup bash completions
# https://github.com/scop/bash-completion
options=(
"${extras[@]}"
--optional
--no-fallback
--name='Bash Completions'
"$@"
APK='bash-completion' # ALPINE
APT='bash-completion' # UBUNTU
AUR='bash-completion' # ARCH
BREW='bash-completion'
RPM='bash-completion' # FEDORA
ZYPPER='bash-completion' # SUSE
)
setup_util "${options[@]}"
# if we are reactive, allow shell modification
if get-terminal-reactivity-support --quiet; then
# if the login shell is outdated bash, and if the new bash is installed, then update the login shell to the newer bash
# @todo figure out how this works if login shell is the now uninstall bash
local login_shell bash_shell
login_shell="${SHELL-}"
bash_shell="$(type -P bash)"
if test -n "$login_shell"; then
login_shell_name="$(basename "$login_shell")"
if test "$login_shell_name" = 'bash' -a "$login_shell" != "$bash_shell"; then
login_shell_version="$("$login_shell" -c -- 'printf "%s\n" "$BASH_VERSION"')"
bash_shell_version="$("$bash_shell" -c -- 'printf "%s\n" "$BASH_VERSION"')"
if test "$login_shell_version" != "$bash_shell_version"; then
echo-style \
--header2='Your login shell is an outdated version of bash.' --newline \
--header2='You will now be prompted now to change it to a more modern shell.'
setup-shell
echo-style --header2='Close this terminal, open a new one, then run the command you ran again.'
return 0
fi
fi
fi
fi
)
# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
setup_util_bash "$@"
fi