Skip to content

Commit

Permalink
Merge pull request #725 from lemonrock/terminal
Browse files Browse the repository at this point in the history
Made outputting of ANSI terminal escapes codes defensive
  • Loading branch information
brson authored Sep 30, 2016
2 parents 58969d2 + b69f55c commit 8d5c597
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions rustup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,30 @@ main() {

local _dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t rustup)"
local _file="$_dir/rustup-init$_ext"

printf "\33[1minfo:\33[0m downloading installer\n"


local _ansiEscapesAreValid=false
if [ -t 2 ]; then
if [ "${TERM+set}" = 'set' ]; then
case "$TERM" in
xterm*|rxvt*|urxvt*|linux*|vt*)
_ansiEscapesAreValid=true
;;
esac
fi
fi

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

ensure mkdir -p "$_dir"
ensure curl -sSfL "$_url" -o "$_file"
ensure chmod u+x "$_file"
if [ ! -x "$_file" ]; then
echo "Cannot execute $_file (likely because of mounting /tmp as noexec)."
echo "Please copy the file to a location where you can execute binaries and run ./rustup-init$_ext."
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
exit 1
fi

Expand Down

0 comments on commit 8d5c597

Please sign in to comment.