2 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
24 echo "rustup: WARNING: $1"
28 echo "rustup: error: $1"
46 printf "rustup: %-20s := %.35s ...\n" $1 "$T"
48 printf "rustup: %-20s := %s %s\n" $1 "$T" "$2"
62 VER0=$($P --version 2>/dev/null | head -1 \
63 | sed -e 's/[^0-9]*\([vV]\?[0-9.]\+[^ ]*\).*/\1/' )
64 if [ $? -eq 0 -a "x${VER0}" != "x" ]
86 err "needed, but unable to find any of: $*"
92 VAL_OPTIONS="$VAL_OPTIONS $1"
101 local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
106 if echo "$arg" | grep -q -- "--$OP="
108 val=$(echo "$arg" | cut -f2 -d=)
118 OP="${OP}=[${DEFAULT}]"
119 printf " --%-30s %s\n" "$OP" "$DOC"
124 BOOL_OPTIONS="$BOOL_OPTIONS $1"
133 if [ $DEFAULT -eq 0 ]
145 if [ "$arg" = "--${FLAG}-${OP}" ]
147 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
148 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
149 local V="CFG_${FLAG}_${OP}"
159 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
164 BOOL_OPTIONS="$BOOL_OPTIONS $1"
174 if [ "$arg" = "--${OP}" ]
176 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
187 printf " --%-30s %s\n" "$OP" "$DOC"
195 for option in $BOOL_OPTIONS
197 if test --disable-$option = $arg
201 if test --enable-$option = $arg
205 if test --$option = $arg
210 for option in $VAL_OPTIONS
212 if echo "$arg" | grep -q -- "--$option="
217 if [ "$arg" = "--help" ]
220 echo "No more help available for Configure options,"
221 echo "check the Wiki or join our IRC channel"
224 if test $isArgValid -eq 0
226 err "Option '$arg' is not recognized"
233 local TMP_DIR=`pwd`/rustup-tmp-install
236 need_ok "failed to remove temporary installation directory"
238 mkdir -p "${TMP_DIR}"
239 need_ok "failed to create create temporary installation directory"
244 probe_need CFG_CURL curl
245 probe_need CFG_TAR tar
246 probe_need CFG_FILE file
248 probe CFG_SHA256SUM sha256sum
249 probe CFG_SHASUM shasum
251 if [ -z "$CFG_SHA256SUM" -a -z "$CFG_SHASUM" ]; then
252 err "unable to find either sha256sum or shasum"
256 if [ -n "$CFG_SHA256SUM" ]; then
259 ${CFG_SHASUM} -a 256 $@
263 CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
268 if [ "$1" = "--help" ]
273 echo "Usage: $CFG_SELF [options]"
278 step_msg "processing $CFG_SELF args"
285 flag uninstall "only uninstall from the installation prefix"
286 valopt prefix "" "set installation prefix"
287 valopt date "" "use the YYYY-MM-DD nightly instead of the current nightly"
288 flag save "save the downloaded nightlies to ~/.rustup"
296 step_msg "validating $CFG_SELF args"
300 # Platform detection copied from `configure`
302 CFG_OSTYPE=$(uname -s)
303 CFG_CPUTYPE=$(uname -m)
305 if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
307 # Darwin's `uname -s` lies and always returns i386. We have to use sysctl
309 if sysctl hw.optional.x86_64 | grep -q ': 1'
315 # The goal here is to come up with the same triple as LLVM would,
316 # at least for the subset of platforms we're willing to target.
321 CFG_OSTYPE=unknown-linux-gnu
325 CFG_OSTYPE=unknown-freebsd
329 CFG_OSTYPE=apple-darwin
333 CFG_OSTYPE=pc-mingw32
335 # Thad's Cygwin identifers below
339 CFG_OSTYPE=pc-mingw32
345 CFG_OSTYPE=w64-mingw32
351 CFG_OSTYPE=pc-mingw32
357 CFG_OSTYPE=w64-mingw32
361 # We do not detect other OS such as XP/2003 using 64 bit using uname.
362 # If we want to in the future, we will need to use Cygwin
363 # Chuck's csih helper in /usr/lib/csih/winProductName.exe or alternative.
365 err "unknown OS type: $CFG_OSTYPE"
372 i386 | i486 | i686 | i786 | x86)
380 x86_64 | x86-64 | x64 | amd64)
385 err "unknown CPU type: $CFG_CPUTYPE"
388 # Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
389 if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
391 "${CFG_FILE}" -L "$SHELL" | grep -q "x86[_-]64"
397 HOST_TRIPLE="${CFG_CPUTYPE}-${CFG_OSTYPE}"
399 # Is this a triple we have nightlies for?
402 x86_64-unknown-linux-gnu)
405 i686-unknown-linux-gnu)
415 err "rustup.sh doesn't work for host $HOST_TRIPLE"
419 msg "host triple: ${HOST_TRIPLE}"
422 if [ -n "${CFG_UNINSTALL}" ]
424 CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --uninstall"
427 if [ -n "${CFG_PREFIX}" ]
429 CFG_INSTALL_FLAGS="${CFG_INSTALL_FLAGS} --prefix=${CFG_PREFIX}"
432 CFG_TMP_DIR=$(mktemp -d 2>/dev/null \
433 || mktemp -d -t 'rustup-tmp-install' 2>/dev/null \
436 # If we're saving nightlies and we didn't specify which one, grab todays.
437 # Otherwise we'll use the latest version.
438 if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ];
440 CFG_DATE=`date "+%Y-%m-%d"`
443 RUST_URL="https://static.rust-lang.org/dist"
444 RUST_PACKAGE_NAME=rust-nightly
445 RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}"
446 RUST_TARBALL_NAME="${RUST_PACKAGE_NAME_AND_TRIPLE}.tar.gz"
447 RUST_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${RUST_PACKAGE_NAME_AND_TRIPLE}"
448 RUST_LOCAL_INSTALL_SCRIPT="${RUST_LOCAL_INSTALL_DIR}/install.sh"
450 # add a date suffix if we want a particular nighly.
451 if [ -n "${CFG_DATE}" ];
453 RUST_URL="${RUST_URL}/${CFG_DATE}"
460 msg "Downloading ${remote_sha256}"
461 remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"`
462 if [ "$?" -ne 0 ]; then
463 rm -Rf "${CFG_TMP_DIR}"
464 err "Failed to download ${remote_url}"
468 local_sha256=$(calculate_hash "${local_file}")
469 if [ "$?" -ne 0 ]; then
470 rm -Rf "${CFG_TMP_DIR}"
471 err "Failed to compute hash for ${local_tarball}"
474 # We only need the sha, not the filenames
475 remote_sha256=`echo ${remote_sha256} | cut -f 1 -d ' '`
476 local_sha256=`echo ${local_sha256} | cut -f 1 -d ' '`
478 if [ "${remote_sha256}" != "${local_sha256}" ]; then
479 rm -Rf "${CFG_TMP_DIR}"
480 errmsg="invalid sha256.\n"
481 errmsg="$errmsg ${remote_sha256}\t${remote_tarball}\n"
482 errmsg="$errmsg ${local_sha256}\t${local_tarball}"
487 # Fetch the package. Optionally caches the tarballs.
491 remote_sha256="${remote_tarball}.sha256"
493 # Check if we've already downloaded this file.
494 if [ -e "${local_tarball}.tmp" ]; then
495 msg "Resuming ${remote_tarball} to ${local_tarball}"
497 "${CFG_CURL}" -f -C - -o "${local_tarball}.tmp" "${remote_tarball}"
500 rm -Rf "${CFG_TMP_DIR}"
501 err "failed to download installer"
504 mv "${local_tarball}.tmp" "${local_tarball}"
505 elif [ ! -e "${local_tarball}" ]; then
506 msg "Downloading ${remote_tarball} to ${local_tarball}"
508 "${CFG_CURL}" -f -o "${local_tarball}.tmp" "${remote_tarball}"
511 rm -Rf "${CFG_TMP_DIR}"
512 err "failed to download installer"
515 mv "${local_tarball}.tmp" "${local_tarball}"
518 verify_hash "${remote_sha256}" "${local_tarball}"
521 # Wrap all the commands needed to install a package.
526 msg "Extracting ${local_tarball}"
527 (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${local_tarball}")
528 if [ $? -ne 0 ]; then
529 rm -Rf "${CFG_TMP_DIR}"
530 err "failed to unpack installer"
533 sh "${install_script}" "${CFG_INSTALL_FLAGS}"
536 rm -Rf "${CFG_TMP_DIR}"
537 err "failed to install Rust"
541 # It's possible that curl could be interrupted partway though downloading
542 # `rustup.sh`, truncating the file. This could be especially bad if we were in
543 # the middle of a line that would run "rm -rf ". To protect against this, we
544 # wrap up the `rustup.sh` destructive functionality in this helper function,
545 # which we call as the last thing we do. This means we will not do anything
546 # unless we have the entire file downloaded.
548 rm -Rf "${CFG_TMP_DIR}"
549 need_ok "failed to remove temporary installation directory"
551 mkdir -p "${CFG_TMP_DIR}"
552 need_ok "failed to create create temporary installation directory"
554 # If we're saving our nightlies, put them in $HOME/.rustup.
555 if [ -n "${CFG_SAVE}" ]
557 RUST_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_DATE}"
559 RUST_DOWNLOAD_DIR="${CFG_TMP_DIR}"
562 mkdir -p "${RUST_DOWNLOAD_DIR}"
563 need_ok "failed to create create download directory"
565 RUST_LOCAL_TARBALL="${RUST_DOWNLOAD_DIR}/${RUST_TARBALL_NAME}"
568 "${RUST_URL}/${RUST_TARBALL_NAME}" \
569 "${RUST_LOCAL_TARBALL}"
572 "${RUST_LOCAL_TARBALL}" \
573 "${RUST_LOCAL_INSTALL_SCRIPT}"
575 rm -Rf "${CFG_TMP_DIR}"
576 need_ok "couldn't rm temporary installation directory"