27
27
28
28
# If RUSTUP_UPDATE_ROOT is unset or empty, default it.
29
29
RUSTUP_UPDATE_ROOT=" ${RUSTUP_UPDATE_ROOT:- https:// static.rust-lang.org/ rustup} "
30
+ # Set quiet as a global for ease of use
31
+ RUSTUP_QUIET=no
30
32
31
33
# NOTICE: If you change anything here, please make the same changes in setup_mode.rs
32
34
usage () {
@@ -114,19 +116,25 @@ main() {
114
116
usage
115
117
exit 0
116
118
;;
119
+ --quiet)
120
+ RUSTUP_QUIET=yes
121
+ ;;
117
122
* )
118
123
OPTIND=1
119
124
if [ " ${arg%% --* } " = " " ]; then
120
125
# Long option (other than --help);
121
126
# don't attempt to interpret it.
122
127
continue
123
128
fi
124
- while getopts :hy sub_arg " $arg " ; do
129
+ while getopts :hqy sub_arg " $arg " ; do
125
130
case " $sub_arg " in
126
131
h)
127
132
usage
128
133
exit 0
129
134
;;
135
+ q)
136
+ RUSTUP_QUIET=yes
137
+ ;;
130
138
y)
131
139
# user wants to skip the prompt --
132
140
# we don't need /dev/tty
@@ -140,18 +148,14 @@ main() {
140
148
esac
141
149
done
142
150
143
- if $_ansi_escapes_are_valid ; then
144
- printf " \33[1minfo:\33[0m downloading installer\n" 1>&2
145
- else
146
- printf ' %s\n' ' info: downloading installer' 1>&2
147
- fi
151
+ say ' downloading installer'
148
152
149
153
ensure mkdir -p " $_dir "
150
154
ensure downloader " $_url " " $_file " " $_arch "
151
155
ensure chmod u+x " $_file "
152
156
if [ ! -x " $_file " ]; then
153
- printf ' %s\n ' " Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
154
- printf ' %s\n ' " Please copy the file to a location where you can execute binaries and run ./rustup-init${_ext} ." 1>&2
157
+ err " Cannot execute $_file (likely because of mounting /tmp as noexec)."
158
+ err " Please copy the file to a location where you can execute binaries and run ./rustup-init${_ext} ."
155
159
exit 1
156
160
fi
157
161
@@ -162,6 +166,7 @@ main() {
162
166
# to explicitly connect /dev/tty to the installer's stdin.
163
167
if [ ! -t 1 ]; then
164
168
err " Unable to run interactively. Run with -y to accept defaults, --help for additional options"
169
+ exit 1;
165
170
fi
166
171
167
172
ignore " $_file " " $@ " < /dev/tty
@@ -184,14 +189,14 @@ get_current_exe() {
184
189
if test -L /proc/self/exe ; then
185
190
_current_exe=/proc/self/exe
186
191
else
187
- printf ' %s\n ' " Warning: Unable to find /proc/self/exe. System architecture detection might be inaccurate." 1>&2
192
+ warn " Unable to find /proc/self/exe. System architecture detection might be inaccurate."
188
193
if test -n " $SHELL " ; then
189
194
_current_exe=$SHELL
190
195
else
191
196
need_cmd /bin/sh
192
197
_current_exe=/bin/sh
193
198
fi
194
- printf ' %s\n ' " Warning: Falling back to $_current_exe ." 1>&2
199
+ warn " Falling back to $_current_exe ."
195
200
fi
196
201
echo " $_current_exe "
197
202
}
@@ -213,6 +218,7 @@ get_bitness() {
213
218
echo 64
214
219
else
215
220
err " unknown platform bitness"
221
+ exit 1;
216
222
fi
217
223
}
218
224
@@ -247,6 +253,7 @@ get_endianness() {
247
253
echo " ${cputype}${suffix_eb} "
248
254
else
249
255
err " unknown platform endianness"
256
+ exit 1
250
257
fi
251
258
}
252
259
@@ -294,19 +301,14 @@ ensure_loongarch_uapi() {
294
301
return 0
295
302
;;
296
303
234)
297
- echo >&2
298
- echo ' Your Linux kernel does not provide the ABI required by this Rust' >&2
299
- echo ' distribution. Please check with your OS provider for how to obtain a' >&2
300
- echo ' compatible Rust package for your system.' >&2
301
- echo >&2
304
+ err ' Your Linux kernel does not provide the ABI required by this Rust distribution.'
305
+ err ' Please check with your OS provider for how to obtain a compatible Rust package for your system.'
302
306
exit 1
303
307
;;
304
308
* )
305
- echo " warn: Cannot determine current system's ABI flavor, continuing anyway." >&2
306
- echo >&2
307
- echo ' Note that the official Rust distribution only works with the upstream' >&2
308
- echo ' kernel ABI. Installation will fail if your running kernel happens to be' >&2
309
- echo ' incompatible.' >&2
309
+ warn " Cannot determine current system's ABI flavor, continuing anyway."
310
+ warn ' Note that the official Rust distribution only works with the upstream kernel ABI.'
311
+ warn ' Installation will fail if your running kernel happens to be incompatible.'
310
312
;;
311
313
esac
312
314
}
@@ -410,6 +412,7 @@ get_architecture() {
410
412
411
413
* )
412
414
err " unrecognized OS type: $_ostype "
415
+ exit 1
413
416
;;
414
417
415
418
esac
@@ -489,6 +492,7 @@ get_architecture() {
489
492
;;
490
493
* )
491
494
err " unknown CPU type: $_cputype "
495
+ exit 1
492
496
493
497
esac
494
498
@@ -501,14 +505,10 @@ get_architecture() {
501
505
else {
502
506
# 32-bit executable for amd64 = x32
503
507
if is_host_amd64_elf " $_current_exe " ; then {
504
- echo " This host is running an x32 userland; as it stands, x32 support is poor," 1>&2
505
- echo " and there isn't a native toolchain -- you will have to install" 1>&2
506
- echo " multiarch compatibility with i686 and/or amd64, then select one" 1>&2
507
- echo " by re-running this script with the RUSTUP_CPUTYPE environment variable" 1>&2
508
- echo " set to i686 or x86_64, respectively." 1>&2
509
- echo 1>&2
510
- echo " You will be able to add an x32 target after installation by running" 1>&2
511
- echo " rustup target add x86_64-unknown-linux-gnux32" 1>&2
508
+ err " This host is running an x32 userland, for which no native toolchain is provided."
509
+ err " You will have to install multiarch compatibility with i686 or amd64."
510
+ err " To do so, set the RUSTUP_CPUTYPE environment variable set to i686 or amd64 and re-run this script."
511
+ err " You will be able to add an x32 target after installation by running \` rustup target add x86_64-unknown-linux-gnux32\` ."
512
512
exit 1
513
513
}; else
514
514
_cputype=i686
@@ -531,6 +531,7 @@ get_architecture() {
531
531
;;
532
532
riscv64gc)
533
533
err " riscv64 with 32-bit userland unsupported"
534
+ exit 1
534
535
;;
535
536
esac
536
537
fi
@@ -551,18 +552,34 @@ get_architecture() {
551
552
RETVAL=" $_arch "
552
553
}
553
554
555
+ __print () {
556
+ if $_ansi_escapes_are_valid ; then
557
+ printf ' \33[1m%s:\33[0m %s\n' " $1 " " $2 " >&2
558
+ else
559
+ printf ' %s: %s\n' " $1 " " $2 " >&2
560
+ fi
561
+ }
562
+
563
+ warn () {
564
+ __print ' warn' " $1 " >&2
565
+ }
566
+
554
567
say () {
555
- printf ' rustup: %s\n' " $1 "
568
+ if [ " $RUSTUP_QUIET " = " no" ]; then
569
+ __print ' info' " $1 " >&2
570
+ fi
556
571
}
557
572
573
+ # NOTE: you are required to exit yourself
574
+ # we don't do it here because of multiline errors
558
575
err () {
559
- say " $1 " >&2
560
- exit 1
576
+ __print ' error' " $1 " >&2
561
577
}
562
578
563
579
need_cmd () {
564
580
if ! check_cmd " $1 " ; then
565
581
err " need '$1 ' (command not found)"
582
+ exit 1
566
583
fi
567
584
}
568
585
@@ -571,14 +588,20 @@ check_cmd() {
571
588
}
572
589
573
590
assert_nz () {
574
- if [ -z " $1 " ]; then err " assert_nz $2 " ; fi
591
+ if [ -z " $1 " ]; then
592
+ err " assert_nz $2 "
593
+ exit 1
594
+ fi
575
595
}
576
596
577
597
# Run a command that should never fail. If the command fails execution
578
598
# will immediately terminate with an error showing the failing
579
599
# command.
580
600
ensure () {
581
- if ! " $@ " ; then err " command failed: $* " ; fi
601
+ if ! " $@ " ; then
602
+ err " command failed: $* "
603
+ exit 1
604
+ fi
582
605
}
583
606
584
607
# This is just for indicating that commands' results are being
@@ -618,9 +641,9 @@ downloader() {
618
641
_err=$( curl $_retry --proto ' =https' --tlsv1.2 --ciphers " $_ciphersuites " --silent --show-error --fail --location " $1 " --output " $2 " 2>&1 )
619
642
_status=$?
620
643
else
621
- echo " warn: Not enforcing strong cipher suites for TLS, this is potentially less secure"
644
+ warn " Not enforcing strong cipher suites for TLS, this is potentially less secure"
622
645
if ! check_help_for " $3 " curl --proto --tlsv1.2; then
623
- echo " warn: Not enforcing TLS v1.2, this is potentially less secure"
646
+ warn " Not enforcing TLS v1.2, this is potentially less secure"
624
647
_err=$( curl $_retry --silent --show-error --fail --location " $1 " --output " $2 " 2>&1 )
625
648
_status=$?
626
649
else
@@ -629,15 +652,16 @@ downloader() {
629
652
fi
630
653
fi
631
654
if [ -n " $_err " ]; then
632
- echo " $_err " >&2
655
+ warn " $_err "
633
656
if echo " $_err " | grep -q 404$; then
634
657
err " installer for platform '$3 ' not found, this may be unsupported"
658
+ exit 1
635
659
fi
636
660
fi
637
661
return $_status
638
662
elif [ " $_dld " = wget ]; then
639
663
if [ " $( wget -V 2>&1 | head -2| tail -1| cut -f1 -d" " ) " = " BusyBox" ]; then
640
- echo " warn: using the BusyBox version of wget. Not enforcing strong cipher suites for TLS or TLS v1.2, this is potentially less secure"
664
+ warn " using the BusyBox version of wget. Not enforcing strong cipher suites for TLS or TLS v1.2, this is potentially less secure"
641
665
_err=$( wget " $1 " -O " $2 " 2>&1 )
642
666
_status=$?
643
667
else
@@ -647,9 +671,9 @@ downloader() {
647
671
_err=$( wget --https-only --secure-protocol=TLSv1_2 --ciphers " $_ciphersuites " " $1 " -O " $2 " 2>&1 )
648
672
_status=$?
649
673
else
650
- echo " warn: Not enforcing strong cipher suites for TLS, this is potentially less secure"
674
+ warn " Not enforcing strong cipher suites for TLS, this is potentially less secure"
651
675
if ! check_help_for " $3 " wget --https-only --secure-protocol; then
652
- echo " warn: Not enforcing TLS v1.2, this is potentially less secure"
676
+ warn " Not enforcing TLS v1.2, this is potentially less secure"
653
677
_err=$( wget " $1 " -O " $2 " 2>&1 )
654
678
_status=$?
655
679
else
@@ -659,14 +683,16 @@ downloader() {
659
683
fi
660
684
fi
661
685
if [ -n " $_err " ]; then
662
- echo " $_err " >&2
686
+ warn " $_err "
663
687
if echo " $_err " | grep -q ' 404 Not Found$' ; then
664
688
err " installer for platform '$3 ' not found, this may be unsupported"
689
+ exit 1
665
690
fi
666
691
fi
667
692
return $_status
668
693
else
669
694
err " Unknown downloader" # should not reach here
695
+ exit 1
670
696
fi
671
697
}
672
698
@@ -696,7 +722,7 @@ check_help_for() {
696
722
# fail to find these options to force fallback
697
723
if [ " $( sw_vers -productVersion | cut -d. -f2) " -lt 13 ]; then
698
724
# Older than 10.13
699
- echo " warn: Detected macOS platform older than 10.13"
725
+ warn " Detected macOS platform older than 10.13"
700
726
return 1
701
727
fi
702
728
;;
@@ -705,8 +731,8 @@ check_help_for() {
705
731
;;
706
732
* )
707
733
# Unknown product version, warn and continue
708
- echo " warn: Detected unknown macOS major version: $( sw_vers -productVersion) "
709
- echo " Warning TLS capabilities detection may fail"
734
+ warn " Detected unknown macOS major version: $( sw_vers -productVersion) "
735
+ warn " TLS capabilities detection may fail"
710
736
;;
711
737
esac
712
738
fi
0 commit comments