-
Notifications
You must be signed in to change notification settings - Fork 36
/
blastoff.sh
executable file
·318 lines (253 loc) · 6.87 KB
/
blastoff.sh
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/bin/sh
# NB: If you change this script you must also change quick-install.sh
say() {
echo "blastoff: $1"
}
verbose_say() {
if [ "$flag_verbose" = true ]; then
say "$1"
fi
}
err() {
say "$1" >&2
exit 1
}
need_cmd() {
if ! command -v $1 > /dev/null 2>&1
then err "need $1"
fi
}
need_ok() {
if [ $? != 0 ]; then
err "$1"
fi
}
assert_nz() {
if [ -z "$1" ]; then
err "assert_nz $2"
fi
}
create_tmp_dir() {
local tmp_dir="`pwd`/multirust-tmp-install"
rm -Rf "${tmp_dir}"
need_ok "failed to remove temporary installation directory"
mkdir -p "${tmp_dir}"
need_ok "failed to create create temporary installation directory"
echo $tmp_dir
}
# Copied from rustup.sh
get_architecture() {
verbose_say "detecting architecture"
local _ostype="$(uname -s)"
local _cputype="$(uname -m)"
verbose_say "uname -s reports: $_ostype"
verbose_say "uname -m reports: $_cputype"
if [ "$_ostype" = Darwin -a "$_cputype" = i386 ]; then
# Darwin `uname -s` lies
if sysctl hw.optional.x86_64 | grep -q ': 1'; then
local _cputype=x86_64
fi
fi
case "$_ostype" in
Linux)
local _ostype=unknown-linux-gnu
;;
FreeBSD)
local _ostype=unknown-freebsd
;;
DragonFly)
local _ostype=unknown-dragonfly
;;
Darwin)
local _ostype=apple-darwin
;;
MINGW* | MSYS*)
local _ostype=pc-windows-gnu
;;
*)
err "unrecognized OS type: $_ostype"
;;
esac
case "$_cputype" in
i386 | i486 | i686 | i786 | x86)
local _cputype=i686
;;
xscale | arm)
local _cputype=arm
;;
armv6l)
local _cputype=arm
local _ostype="${_ostype}eabihf"
;;
armv7l)
local _cputype=armv7
local _ostype="${_ostype}eabihf"
;;
x86_64 | x86-64 | x64 | amd64)
local _cputype=x86_64
;;
*)
err "unknown CPU type: $CFG_CPUTYPE"
esac
# Detect 64-bit linux with 32-bit userland
if [ $_ostype = unknown-linux-gnu -a $_cputype = x86_64 ]; then
# $SHELL does not exist in standard 'sh', so probably only exists
# if configure is running in an interactive bash shell. /usr/bin/env
# exists *everywhere*.
local _bin_to_probe="${SHELL-bogus_shell}"
if [ ! -e "$_bin_to_probe" -a -e "/usr/bin/env" ]; then
_bin_to_probe="/usr/bin/env"
fi
if [ -e "$_bin_to_probe" ]; then
file -L "$_bin_to_probe" | grep -q "x86[_-]64"
if [ $? != 0 ]; then
local _cputype=i686
fi
fi
fi
local _arch="$_cputype-$_ostype"
verbose_say "architecture is $_arch"
RETVAL="$_arch"
}
check_for_windows() {
get_architecture
case "$RETVAL" in
*pc-windows*)
return 0
;;
*)
return 1
;;
esac
}
run() {
need_cmd rm
need_cmd git
need_cmd sed
need_cmd sh
need_cmd sleep
need_cmd file
GIT_REPO=https://github.com/brson/multirust.git
UNINSTALL=
YES=
for arg in "$@"; do
case "$arg" in
--uninstall)
UNINSTALL=true
;;
--yes)
YES=true
;;
*)
err "unrecognized argument '$arg'"
;;
esac
done
if [ ! -e "/dev/tty" ]; then
err "/dev/tty does not exist"
fi
check_for_windows
if [ "$?" = 0 ]; then
local _is_windows=true
else
local _is_windows=false
fi
if [ "$_is_windows" = "false" ]; then
if [ -z "$UNINSTALL" ]; then
cat <<EOF
Welcome to Rust.
This script will download, build, and install multirust as root, then
configure multirust with the most common options. It may prompt for
your password for installation via 'sudo'.
You may run /usr/local/lib/rustlib/uninstall.sh to uninstall multirust.
EOF
else
echo "This script will uninstall multirust. It may prompt for your password via 'sudo'."
fi
else
if [ -z "$UNINSTALL" ]; then
cat <<EOF
Welcome to Rust.
This script will download, build, and install multirust as root, then
configure multirust with the most common options.
You may run /usr/local/lib/rustlib/uninstall.sh to uninstall multirust.
EOF
else
echo "This script will uninstall multirust."
fi
fi
echo
if [ -z "$YES" ]; then
local _yn=""
read -p "Ready? (y/N) " _yn < /dev/tty
echo
if [ "$_yn" != "y" -a "$_yn" != "Y" ]; then
exit 0
fi
fi
tmp_dir="$(mktemp -d 2>/dev/null \
|| mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
|| create_tmp_dir)"
if [ -z "$tmp_dir" ]; then
err "empty temp dir"
fi
original_dir=`pwd`
say "working in temporary directory $tmp_dir"
cd "$tmp_dir"
need_ok "failed to cd to temporary install directory"
local _branch="${MULTIRUST_BLASTOFF_BRANCH-master}"
# Clone git repo
say "cloning multirust git repo"
git clone "$GIT_REPO" -b "$_branch" --depth 1
if [ $? != 0 ]; then
cd "$original_dir" && rm -Rf "$tmp_dir"
err "failed to clone git repo $GIT_REPO"
fi
cd multirust
if [ $? != 0 ]; then
cd "$original_dir" && rm -Rf "$tmp_dir"
err "failed to cd to git repo"
fi
say "building"
sh ./build.sh
if [ $? != 0 ]; then
cd "$original_dir" && rm -Rf "$tmp_dir"
err "failed to build multirust"
fi
if [ -z "$UNINSTALL" ]; then
say "installing"
if [ "$_is_windows" = "false" ]; then
sudo sh ./install.sh
else
sh ./install.sh
fi
if [ $? != 0 ]; then
cd "$original_dir" && rm -Rf "$tmp_dir"
err "failed to install multirust"
fi
else
say "uninstalling"
if [ "$_is_windows" = "false" ]; then
sudo sh ./install.sh --uninstall
else
sh ./install.sh --uninstall
fi
if [ $? != 0 ]; then
cd "$original_dir" && rm -Rf "$tmp_dir"
err "failed to uninstall multirust"
fi
fi
cd "$original_dir" && rm -Rf "$tmp_dir"
need_ok "failed to remove temporary install directory"
if [ -n "$UNINSTALL" ]; then
exit 0
fi
if ! command -v multirust > /dev/null 2>&1; then
err 'unable to run `multirust` after install. this is odd. not finishing configuration'
fi
say "installing stable toolchain"
multirust default stable
need_ok 'failed to install stable toolchain. if this appears to be a network problem retry with `multirust default stable`'
say "all systems go"
}
run "$@"