Skip to content

implements quiet flag in rustup-init.sh #3910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 69 additions & 43 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ set -u

# If RUSTUP_UPDATE_ROOT is unset or empty, default it.
RUSTUP_UPDATE_ROOT="${RUSTUP_UPDATE_ROOT:-https://static.rust-lang.org/rustup}"
# Set quiet as a global for ease of use
RUSTUP_QUIET=no

# NOTICE: If you change anything here, please make the same changes in setup_mode.rs
usage() {
Expand Down Expand Up @@ -114,19 +116,25 @@ main() {
usage
exit 0
;;
--quiet)
RUSTUP_QUIET=yes
;;
*)
OPTIND=1
if [ "${arg%%--*}" = "" ]; then
# Long option (other than --help);
# don't attempt to interpret it.
continue
fi
while getopts :hy sub_arg "$arg"; do
while getopts :hqy sub_arg "$arg"; do
case "$sub_arg" in
h)
usage
exit 0
;;
q)
RUSTUP_QUIET=yes
;;
y)
# user wants to skip the prompt --
# we don't need /dev/tty
Expand All @@ -140,18 +148,14 @@ main() {
esac
done

if $_ansi_escapes_are_valid; then
printf "\33[1minfo:\33[0m downloading installer\n" 1>&2
else
printf '%s\n' 'info: downloading installer' 1>&2
fi
say 'downloading installer'

ensure mkdir -p "$_dir"
ensure downloader "$_url" "$_file" "$_arch"
ensure chmod u+x "$_file"
if [ ! -x "$_file" ]; then
printf '%s\n' "Cannot execute $_file (likely because of mounting /tmp as noexec)." 1>&2
printf '%s\n' "Please copy the file to a location where you can execute binaries and run ./rustup-init${_ext}." 1>&2
err "Cannot execute $_file (likely because of mounting /tmp as noexec)."
err "Please copy the file to a location where you can execute binaries and run ./rustup-init${_ext}."
exit 1
fi

Expand All @@ -162,6 +166,7 @@ main() {
# to explicitly connect /dev/tty to the installer's stdin.
if [ ! -t 1 ]; then
err "Unable to run interactively. Run with -y to accept defaults, --help for additional options"
exit 1;
fi

ignore "$_file" "$@" < /dev/tty
Expand All @@ -184,14 +189,14 @@ get_current_exe() {
if test -L /proc/self/exe ; then
_current_exe=/proc/self/exe
else
printf '%s\n' "Warning: Unable to find /proc/self/exe. System architecture detection might be inaccurate." 1>&2
warn "Unable to find /proc/self/exe. System architecture detection might be inaccurate."
if test -n "$SHELL" ; then
_current_exe=$SHELL
else
need_cmd /bin/sh
_current_exe=/bin/sh
fi
printf '%s\n' "Warning: Falling back to $_current_exe." 1>&2
warn "Falling back to $_current_exe."
fi
echo "$_current_exe"
}
Expand All @@ -213,6 +218,7 @@ get_bitness() {
echo 64
else
err "unknown platform bitness"
exit 1;
fi
}

Expand Down Expand Up @@ -247,6 +253,7 @@ get_endianness() {
echo "${cputype}${suffix_eb}"
else
err "unknown platform endianness"
exit 1
fi
}

Expand Down Expand Up @@ -294,19 +301,14 @@ ensure_loongarch_uapi() {
return 0
;;
234)
echo >&2
echo 'Your Linux kernel does not provide the ABI required by this Rust' >&2
echo 'distribution. Please check with your OS provider for how to obtain a' >&2
echo 'compatible Rust package for your system.' >&2
echo >&2
err 'Your Linux kernel does not provide the ABI required by this Rust distribution.'
err 'Please check with your OS provider for how to obtain a compatible Rust package for your system.'
exit 1
;;
*)
echo "warn: Cannot determine current system's ABI flavor, continuing anyway." >&2
echo >&2
echo 'Note that the official Rust distribution only works with the upstream' >&2
echo 'kernel ABI. Installation will fail if your running kernel happens to be' >&2
echo 'incompatible.' >&2
warn "Cannot determine current system's ABI flavor, continuing anyway."
warn 'Note that the official Rust distribution only works with the upstream kernel ABI.'
warn 'Installation will fail if your running kernel happens to be incompatible.'
;;
esac
}
Expand Down Expand Up @@ -410,6 +412,7 @@ get_architecture() {

*)
err "unrecognized OS type: $_ostype"
exit 1
;;

esac
Expand Down Expand Up @@ -489,6 +492,7 @@ get_architecture() {
;;
*)
err "unknown CPU type: $_cputype"
exit 1

esac

Expand All @@ -501,14 +505,10 @@ get_architecture() {
else {
# 32-bit executable for amd64 = x32
if is_host_amd64_elf "$_current_exe"; then {
echo "This host is running an x32 userland; as it stands, x32 support is poor," 1>&2
echo "and there isn't a native toolchain -- you will have to install" 1>&2
echo "multiarch compatibility with i686 and/or amd64, then select one" 1>&2
echo "by re-running this script with the RUSTUP_CPUTYPE environment variable" 1>&2
echo "set to i686 or x86_64, respectively." 1>&2
echo 1>&2
echo "You will be able to add an x32 target after installation by running" 1>&2
echo " rustup target add x86_64-unknown-linux-gnux32" 1>&2
err "This host is running an x32 userland, for which no native toolchain is provided."
err "You will have to install multiarch compatibility with i686 or amd64."
err "To do so, set the RUSTUP_CPUTYPE environment variable set to i686 or amd64 and re-run this script."
err "You will be able to add an x32 target after installation by running \`rustup target add x86_64-unknown-linux-gnux32\`."
exit 1
}; else
_cputype=i686
Expand All @@ -531,6 +531,7 @@ get_architecture() {
;;
riscv64gc)
err "riscv64 with 32-bit userland unsupported"
exit 1
;;
esac
fi
Expand All @@ -551,18 +552,34 @@ get_architecture() {
RETVAL="$_arch"
}

__print() {
if $_ansi_escapes_are_valid; then
printf '\33[1m%s:\33[0m %s\n' "$1" "$2" >&2
else
printf '%s: %s\n' "$1" "$2" >&2
fi
}

warn() {
__print 'warn' "$1" >&2
}

say() {
printf 'rustup: %s\n' "$1"
if [ "$RUSTUP_QUIET" = "no" ]; then
__print 'info' "$1" >&2
fi
}

# NOTE: you are required to exit yourself
# we don't do it here because of multiline errors
err() {
say "$1" >&2
exit 1
__print 'error' "$1" >&2
}

need_cmd() {
if ! check_cmd "$1"; then
err "need '$1' (command not found)"
exit 1
fi
}

Expand All @@ -571,14 +588,20 @@ check_cmd() {
}

assert_nz() {
if [ -z "$1" ]; then err "assert_nz $2"; fi
if [ -z "$1" ]; then
err "assert_nz $2"
exit 1
fi
}

# Run a command that should never fail. If the command fails execution
# will immediately terminate with an error showing the failing
# command.
ensure() {
if ! "$@"; then err "command failed: $*"; fi
if ! "$@"; then
err "command failed: $*"
exit 1
fi
}

# This is just for indicating that commands' results are being
Expand Down Expand Up @@ -618,9 +641,9 @@ downloader() {
_err=$(curl $_retry --proto '=https' --tlsv1.2 --ciphers "$_ciphersuites" --silent --show-error --fail --location "$1" --output "$2" 2>&1)
_status=$?
else
echo "warn: Not enforcing strong cipher suites for TLS, this is potentially less secure"
warn "Not enforcing strong cipher suites for TLS, this is potentially less secure"
if ! check_help_for "$3" curl --proto --tlsv1.2; then
echo "warn: Not enforcing TLS v1.2, this is potentially less secure"
warn "Not enforcing TLS v1.2, this is potentially less secure"
_err=$(curl $_retry --silent --show-error --fail --location "$1" --output "$2" 2>&1)
_status=$?
else
Expand All @@ -629,15 +652,16 @@ downloader() {
fi
fi
if [ -n "$_err" ]; then
echo "$_err" >&2
warn "$_err"
if echo "$_err" | grep -q 404$; then
err "installer for platform '$3' not found, this may be unsupported"
exit 1
fi
fi
return $_status
elif [ "$_dld" = wget ]; then
if [ "$(wget -V 2>&1|head -2|tail -1|cut -f1 -d" ")" = "BusyBox" ]; then
echo "warn: using the BusyBox version of wget. Not enforcing strong cipher suites for TLS or TLS v1.2, this is potentially less secure"
warn "using the BusyBox version of wget. Not enforcing strong cipher suites for TLS or TLS v1.2, this is potentially less secure"
_err=$(wget "$1" -O "$2" 2>&1)
_status=$?
else
Expand All @@ -647,9 +671,9 @@ downloader() {
_err=$(wget --https-only --secure-protocol=TLSv1_2 --ciphers "$_ciphersuites" "$1" -O "$2" 2>&1)
_status=$?
else
echo "warn: Not enforcing strong cipher suites for TLS, this is potentially less secure"
warn "Not enforcing strong cipher suites for TLS, this is potentially less secure"
if ! check_help_for "$3" wget --https-only --secure-protocol; then
echo "warn: Not enforcing TLS v1.2, this is potentially less secure"
warn "Not enforcing TLS v1.2, this is potentially less secure"
_err=$(wget "$1" -O "$2" 2>&1)
_status=$?
else
Expand All @@ -659,14 +683,16 @@ downloader() {
fi
fi
if [ -n "$_err" ]; then
echo "$_err" >&2
warn "$_err"
if echo "$_err" | grep -q ' 404 Not Found$'; then
err "installer for platform '$3' not found, this may be unsupported"
exit 1
fi
fi
return $_status
else
err "Unknown downloader" # should not reach here
exit 1
fi
}

Expand Down Expand Up @@ -696,7 +722,7 @@ check_help_for() {
# fail to find these options to force fallback
if [ "$(sw_vers -productVersion | cut -d. -f2)" -lt 13 ]; then
# Older than 10.13
echo "warn: Detected macOS platform older than 10.13"
warn "Detected macOS platform older than 10.13"
return 1
fi
;;
Expand All @@ -705,8 +731,8 @@ check_help_for() {
;;
*)
# Unknown product version, warn and continue
echo "warn: Detected unknown macOS major version: $(sw_vers -productVersion)"
echo "Warning TLS capabilities detection may fail"
warn "Detected unknown macOS major version: $(sw_vers -productVersion)"
warn "TLS capabilities detection may fail"
;;
esac
fi
Expand Down
Loading