@@ -62,10 +62,11 @@ main() {
6262 ;;
6363 esac
6464
65- local _url=" $RUSTUP_UPDATE_ROOT /dist/$_arch /rustup-init$_ext "
65+ local _url=" ${ RUSTUP_UPDATE_ROOT} /dist/${ _arch} /rustup-init${ _ext} "
6666
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} "
6970
7071 local _ansi_escapes_are_valid=false
7172 if [ -t 2 ]; then
@@ -106,7 +107,7 @@ main() {
106107 ensure chmod u+x " $_file "
107108 if [ ! -x " $_file " ]; then
108109 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
110111 exit 1
111112 fi
112113
@@ -142,7 +143,8 @@ get_bitness() {
142143 # 0x02 for 64-bit.
143144 # The printf builtin on some shells like dash only supports octal
144145 # 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 )
146148 if [ " $_current_exe_head " = " $( printf ' \177ELF\001' ) " ]; then
147149 echo 32
148150 elif [ " $_current_exe_head " = " $( printf ' \177ELF\002' ) " ]; then
@@ -161,7 +163,8 @@ get_endianness() {
161163 need_cmd head
162164 need_cmd tail
163165
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) "
165168 if [ " $_current_exe_endianness " = " $( printf ' \001' ) " ]; then
166169 echo " ${cputype}${suffix_el} "
167170 elif [ " $_current_exe_endianness " = " $( printf ' \002' ) " ]; then
@@ -172,51 +175,51 @@ get_endianness() {
172175}
173176
174177get_architecture () {
175-
176- local _ostype=" $( uname -s) "
177- local _cputype=" $( uname -m) "
178+ local _ostype _cputype
179+ _ostype=" $( uname -s) "
180+ _cputype=" $( uname -m) "
178181
179182 if [ " $_ostype " = Linux ]; then
180183 if [ " $( uname -o) " = Android ]; then
181- local _ostype=Android
184+ _ostype=Android
182185 fi
183186 fi
184187
185- if [ " $_ostype " = Darwin -a " $_cputype " = i386 ]; then
188+ if [ " $_ostype " = Darwin ] && [ " $_cputype " = i386 ]; then
186189 # Darwin `uname -s` lies
187190 if sysctl hw.optional.x86_64 | grep -q ' : 1' ; then
188- local _cputype=x86_64
191+ _cputype=x86_64
189192 fi
190193 fi
191194
192195 case " $_ostype " in
193196
194197 Android)
195- local _ostype=linux-android
198+ _ostype=linux-android
196199 ;;
197200
198201 Linux)
199- local _ostype=unknown-linux-gnu
202+ _ostype=unknown-linux-gnu
200203 ;;
201204
202205 FreeBSD)
203- local _ostype=unknown-freebsd
206+ _ostype=unknown-freebsd
204207 ;;
205208
206209 NetBSD)
207- local _ostype=unknown-netbsd
210+ _ostype=unknown-netbsd
208211 ;;
209212
210213 DragonFly)
211- local _ostype=unknown-dragonfly
214+ _ostype=unknown-dragonfly
212215 ;;
213216
214217 Darwin)
215- local _ostype=apple-darwin
218+ _ostype=apple-darwin
216219 ;;
217220
218221 MINGW* | MSYS* | CYGWIN* )
219- local _ostype=pc-windows-gnu
222+ _ostype=pc-windows-gnu
220223 ;;
221224
222225 * )
@@ -228,72 +231,72 @@ get_architecture() {
228231 case " $_cputype " in
229232
230233 i386 | i486 | i686 | i786 | x86)
231- local _cputype=i686
234+ _cputype=i686
232235 ;;
233236
234237 xscale | arm)
235- local _cputype=arm
238+ _cputype=arm
236239 if [ " $_ostype " = " linux-android" ]; then
237- local _ostype=linux-androideabi
240+ _ostype=linux-androideabi
238241 fi
239242 ;;
240243
241244 armv6l)
242- local _cputype=arm
245+ _cputype=arm
243246 if [ " $_ostype " = " linux-android" ]; then
244- local _ostype=linux-androideabi
247+ _ostype=linux-androideabi
245248 else
246- local _ostype=" ${_ostype} eabihf"
249+ _ostype=" ${_ostype} eabihf"
247250 fi
248251 ;;
249252
250253 armv7l | armv8l)
251- local _cputype=armv7
254+ _cputype=armv7
252255 if [ " $_ostype " = " linux-android" ]; then
253- local _ostype=linux-androideabi
256+ _ostype=linux-androideabi
254257 else
255- local _ostype=" ${_ostype} eabihf"
258+ _ostype=" ${_ostype} eabihf"
256259 fi
257260 ;;
258261
259262 aarch64)
260- local _cputype=aarch64
263+ _cputype=aarch64
261264 ;;
262265
263266 x86_64 | x86-64 | x64 | amd64)
264- local _cputype=x86_64
267+ _cputype=x86_64
265268 ;;
266269
267270 mips)
268- local _cputype=" $( get_endianness $_cputype " " ' el' ) "
271+ _cputype=" $( get_endianness $_cputype " " ' el' ) "
269272 ;;
270273
271274 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
275278 # 64-bit kernel with 32-bit userland
276279 # endianness suffix is appended later
277- local _cputype=mips
280+ _cputype=mips
278281 fi
279282 else
280283 # only n64 ABI is supported for now
281- local _ostype=" ${_ostype} abi64"
284+ _ostype=" ${_ostype} abi64"
282285 fi
283286
284- local _cputype=" $( get_endianness $_cputype " " ' el' ) "
287+ _cputype=" $( get_endianness " $_cputype " " " ' el' ) "
285288 ;;
286289
287290 ppc)
288- local _cputype=powerpc
291+ _cputype=powerpc
289292 ;;
290293
291294 ppc64)
292- local _cputype=powerpc64
295+ _cputype=powerpc64
293296 ;;
294297
295298 ppc64le)
296- local _cputype=powerpc64le
299+ _cputype=powerpc64le
297300 ;;
298301
299302 * )
@@ -302,14 +305,14 @@ get_architecture() {
302305 esac
303306
304307 # 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
306309 if [ " $( get_bitness) " = " 32" ]; then
307- local _cputype=i686
310+ _cputype=i686
308311 fi
309312 fi
310313
311314 # 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
313316 if [ " $( get_bitness) " = " 32" ]; then
314317 local _cputype=powerpc
315318 fi
@@ -318,20 +321,20 @@ get_architecture() {
318321 # Detect armv7 but without the CPU features Rust needs in that build,
319322 # and fall back to arm.
320323 # 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
322325 if ensure grep ' ^Features' /proc/cpuinfo | grep -q -v neon; then
323326 # At least one processor does not have NEON.
324- local _cputype=arm
327+ _cputype=arm
325328 fi
326329 fi
327330
328- local _arch=" $_cputype - $ _ostype"
331+ _arch=" ${ _cputype} - ${ _ostype} "
329332
330333 RETVAL=" $_arch "
331334}
332335
333336say () {
334- echo " rustup: $1 "
337+ printf ' rustup: %s\n ' " $1 "
335338}
336339
337340err () {
@@ -340,18 +343,17 @@ err() {
340343}
341344
342345need_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)"
345348 fi
346349}
347350
348351check_cmd () {
349352 command -v " $1 " > /dev/null 2>&1
350- return $?
351353}
352354
353355need_ok () {
354- if [ $? != 0 ]; then err " $1 " ; fi
356+ if [ $? -ne 0 ]; then err " $1 " ; fi
355357}
356358
357359assert_nz () {
@@ -376,20 +378,22 @@ ignore() {
376378# This wraps curl or wget. Try curl first, if not installed,
377379# use wget instead.
378380downloader () {
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
384387 fi
385388
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
393397 fi
394398}
395399
0 commit comments