@@ -62,10 +62,11 @@ main() {
62
62
;;
63
63
esac
64
64
65
- local _url=" $RUSTUP_UPDATE_ROOT /dist/$_arch /rustup-init$_ext "
65
+ local _url=" ${ RUSTUP_UPDATE_ROOT} /dist/${ _arch} /rustup-init${ _ext} "
66
66
67
- local _dir=" $( mktemp -d 2> /dev/null || ensure mktemp -d -t rustup) "
68
- local _file=" $_dir /rustup-init$_ext "
67
+ local _dir
68
+ _dir=" $( mktemp -d 2> /dev/null || ensure mktemp -d -t rustup) "
69
+ local _file=" ${_dir} /rustup-init${_ext} "
69
70
70
71
local _ansi_escapes_are_valid=false
71
72
if [ -t 2 ]; then
@@ -106,7 +107,7 @@ main() {
106
107
ensure chmod u+x " $_file "
107
108
if [ ! -x " $_file " ]; then
108
109
printf ' %s\n' " Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
109
- printf ' %s\n' " Please copy the file to a location where you can execute binaries and run ./rustup-init$_ext ." 1>&2
110
+ printf ' %s\n' " Please copy the file to a location where you can execute binaries and run ./rustup-init${ _ext} ." 1>&2
110
111
exit 1
111
112
fi
112
113
@@ -142,7 +143,8 @@ get_bitness() {
142
143
# 0x02 for 64-bit.
143
144
# The printf builtin on some shells like dash only supports octal
144
145
# escape sequences, so we use those.
145
- local _current_exe_head=$( head -c 5 /proc/self/exe )
146
+ local _current_exe_head
147
+ _current_exe_head=$( head -c 5 /proc/self/exe )
146
148
if [ " $_current_exe_head " = " $( printf ' \177ELF\001' ) " ]; then
147
149
echo 32
148
150
elif [ " $_current_exe_head " = " $( printf ' \177ELF\002' ) " ]; then
@@ -161,7 +163,8 @@ get_endianness() {
161
163
need_cmd head
162
164
need_cmd tail
163
165
164
- local _current_exe_endianness=" $( head -c 6 /proc/self/exe | tail -c 1) "
166
+ local _current_exe_endianness
167
+ _current_exe_endianness=" $( head -c 6 /proc/self/exe | tail -c 1) "
165
168
if [ " $_current_exe_endianness " = " $( printf ' \001' ) " ]; then
166
169
echo " ${cputype}${suffix_el} "
167
170
elif [ " $_current_exe_endianness " = " $( printf ' \002' ) " ]; then
@@ -172,51 +175,51 @@ get_endianness() {
172
175
}
173
176
174
177
get_architecture () {
175
-
176
- local _ostype=" $( uname -s) "
177
- local _cputype=" $( uname -m) "
178
+ local _ostype _cputype
179
+ _ostype=" $( uname -s) "
180
+ _cputype=" $( uname -m) "
178
181
179
182
if [ " $_ostype " = Linux ]; then
180
183
if [ " $( uname -o) " = Android ]; then
181
- local _ostype=Android
184
+ _ostype=Android
182
185
fi
183
186
fi
184
187
185
- if [ " $_ostype " = Darwin -a " $_cputype " = i386 ]; then
188
+ if [ " $_ostype " = Darwin ] && [ " $_cputype " = i386 ]; then
186
189
# Darwin `uname -s` lies
187
190
if sysctl hw.optional.x86_64 | grep -q ' : 1' ; then
188
- local _cputype=x86_64
191
+ _cputype=x86_64
189
192
fi
190
193
fi
191
194
192
195
case " $_ostype " in
193
196
194
197
Android)
195
- local _ostype=linux-android
198
+ _ostype=linux-android
196
199
;;
197
200
198
201
Linux)
199
- local _ostype=unknown-linux-gnu
202
+ _ostype=unknown-linux-gnu
200
203
;;
201
204
202
205
FreeBSD)
203
- local _ostype=unknown-freebsd
206
+ _ostype=unknown-freebsd
204
207
;;
205
208
206
209
NetBSD)
207
- local _ostype=unknown-netbsd
210
+ _ostype=unknown-netbsd
208
211
;;
209
212
210
213
DragonFly)
211
- local _ostype=unknown-dragonfly
214
+ _ostype=unknown-dragonfly
212
215
;;
213
216
214
217
Darwin)
215
- local _ostype=apple-darwin
218
+ _ostype=apple-darwin
216
219
;;
217
220
218
221
MINGW* | MSYS* | CYGWIN* )
219
- local _ostype=pc-windows-gnu
222
+ _ostype=pc-windows-gnu
220
223
;;
221
224
222
225
* )
@@ -228,72 +231,72 @@ get_architecture() {
228
231
case " $_cputype " in
229
232
230
233
i386 | i486 | i686 | i786 | x86)
231
- local _cputype=i686
234
+ _cputype=i686
232
235
;;
233
236
234
237
xscale | arm)
235
- local _cputype=arm
238
+ _cputype=arm
236
239
if [ " $_ostype " = " linux-android" ]; then
237
- local _ostype=linux-androideabi
240
+ _ostype=linux-androideabi
238
241
fi
239
242
;;
240
243
241
244
armv6l)
242
- local _cputype=arm
245
+ _cputype=arm
243
246
if [ " $_ostype " = " linux-android" ]; then
244
- local _ostype=linux-androideabi
247
+ _ostype=linux-androideabi
245
248
else
246
- local _ostype=" ${_ostype} eabihf"
249
+ _ostype=" ${_ostype} eabihf"
247
250
fi
248
251
;;
249
252
250
253
armv7l | armv8l)
251
- local _cputype=armv7
254
+ _cputype=armv7
252
255
if [ " $_ostype " = " linux-android" ]; then
253
- local _ostype=linux-androideabi
256
+ _ostype=linux-androideabi
254
257
else
255
- local _ostype=" ${_ostype} eabihf"
258
+ _ostype=" ${_ostype} eabihf"
256
259
fi
257
260
;;
258
261
259
262
aarch64)
260
- local _cputype=aarch64
263
+ _cputype=aarch64
261
264
;;
262
265
263
266
x86_64 | x86-64 | x64 | amd64)
264
- local _cputype=x86_64
267
+ _cputype=x86_64
265
268
;;
266
269
267
270
mips)
268
- local _cputype=" $( get_endianness $_cputype " " ' el' ) "
271
+ _cputype=" $( get_endianness $_cputype " " ' el' ) "
269
272
;;
270
273
271
274
mips64)
272
- local _bitness=" $( get_bitness) "
273
- if [ $_bitness = " 32 " ]; then
274
- if [ $_ostype = " unknown-linux-gnu" ]; then
275
+ _bitness=" $( get_bitness) "
276
+ if [ " $_bitness " -eq 32 ]; then
277
+ if [ " $_ostype " = " unknown-linux-gnu" ]; then
275
278
# 64-bit kernel with 32-bit userland
276
279
# endianness suffix is appended later
277
- local _cputype=mips
280
+ _cputype=mips
278
281
fi
279
282
else
280
283
# only n64 ABI is supported for now
281
- local _ostype=" ${_ostype} abi64"
284
+ _ostype=" ${_ostype} abi64"
282
285
fi
283
286
284
- local _cputype=" $( get_endianness $_cputype " " ' el' ) "
287
+ _cputype=" $( get_endianness " $_cputype " " " ' el' ) "
285
288
;;
286
289
287
290
ppc)
288
- local _cputype=powerpc
291
+ _cputype=powerpc
289
292
;;
290
293
291
294
ppc64)
292
- local _cputype=powerpc64
295
+ _cputype=powerpc64
293
296
;;
294
297
295
298
ppc64le)
296
- local _cputype=powerpc64le
299
+ _cputype=powerpc64le
297
300
;;
298
301
299
302
* )
@@ -302,14 +305,14 @@ get_architecture() {
302
305
esac
303
306
304
307
# Detect 64-bit linux with 32-bit userland for x86
305
- if [ $_ostype = unknown-linux-gnu -a $_cputype = x86_64 ]; then
308
+ if [ " $_ostype " = unknown-linux-gnu ] && [ " $_cputype " = x86_64 ]; then
306
309
if [ " $( get_bitness) " = " 32" ]; then
307
- local _cputype=i686
310
+ _cputype=i686
308
311
fi
309
312
fi
310
313
311
314
# Detect 64-bit linux with 32-bit userland for powerpc
312
- if [ $_ostype = unknown-linux-gnu -a $_cputype = powerpc64 ]; then
315
+ if [ $_ostype = unknown-linux-gnu ] && [ $_cputype = powerpc64 ]; then
313
316
if [ " $( get_bitness) " = " 32" ]; then
314
317
local _cputype=powerpc
315
318
fi
@@ -318,20 +321,20 @@ get_architecture() {
318
321
# Detect armv7 but without the CPU features Rust needs in that build,
319
322
# and fall back to arm.
320
323
# See https://github.com/rust-lang/rustup.rs/issues/587.
321
- if [ $_ostype = " unknown-linux-gnueabihf" -a $_cputype = armv7 ]; then
324
+ if [ " $_ostype " = " unknown-linux-gnueabihf" ] && [ " $_cputype " = armv7 ]; then
322
325
if ensure grep ' ^Features' /proc/cpuinfo | grep -q -v neon; then
323
326
# At least one processor does not have NEON.
324
- local _cputype=arm
327
+ _cputype=arm
325
328
fi
326
329
fi
327
330
328
- local _arch=" $_cputype - $ _ostype"
331
+ _arch=" ${ _cputype} - ${ _ostype} "
329
332
330
333
RETVAL=" $_arch "
331
334
}
332
335
333
336
say () {
334
- echo " rustup: $1 "
337
+ printf ' rustup: %s\n ' " $1 "
335
338
}
336
339
337
340
err () {
@@ -340,18 +343,17 @@ err() {
340
343
}
341
344
342
345
need_cmd () {
343
- if ! check_cmd " $1 "
344
- then err " need '$1 ' (command not found)"
346
+ if ! check_cmd " $1 " ; then
347
+ err " need '$1 ' (command not found)"
345
348
fi
346
349
}
347
350
348
351
check_cmd () {
349
352
command -v " $1 " > /dev/null 2>&1
350
- return $?
351
353
}
352
354
353
355
need_ok () {
354
- if [ $? != 0 ]; then err " $1 " ; fi
356
+ if [ $? -ne 0 ]; then err " $1 " ; fi
355
357
}
356
358
357
359
assert_nz () {
@@ -376,20 +378,22 @@ ignore() {
376
378
# This wraps curl or wget. Try curl first, if not installed,
377
379
# use wget instead.
378
380
downloader () {
379
- if check_cmd curl
380
- then _dld=curl
381
- elif check_cmd wget
382
- then _dld=wget
383
- else _dld=' curl or wget' # to be used in error message of need_cmd
381
+ if check_cmd curl; then
382
+ _dld=curl
383
+ elif check_cmd wget; then
384
+ _dld=wget
385
+ else
386
+ _dld=' curl or wget' # to be used in error message of need_cmd
384
387
fi
385
388
386
- if [ " $1 " = --check ]
387
- then need_cmd " $_dld "
388
- elif [ " $_dld " = curl ]
389
- then curl -sSfL " $1 " -o " $2 "
390
- elif [ " $_dld " = wget ]
391
- then wget " $1 " -O " $2 "
392
- else err " Unknown downloader" # should not reach here
389
+ if [ " $1 " = --check ]; then
390
+ need_cmd " $_dld "
391
+ elif [ " $_dld " = curl ]; then
392
+ curl -sSfL " $1 " -o " $2 "
393
+ elif [ " $_dld " = wget ]; then
394
+ wget " $1 " -O " $2 "
395
+ else
396
+ err " Unknown downloader" # should not reach here
393
397
fi
394
398
}
395
399
0 commit comments