From b59d4e7295258d5e0d2f2c1a41bdad5c547a170e Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Sun, 30 Nov 2014 23:14:37 -0800 Subject: [PATCH 1/6] rustup: Add support for verifying remote hashes --- src/etc/rustup.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index 85e15e363271b..ab6823cf6c4a4 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -244,6 +244,7 @@ create_tmp_dir() { probe_need CFG_CURL curl probe_need CFG_TAR tar probe_need CFG_FILE file +probe_need CFG_SHASUM shasum CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/" CFG_SELF="$0" @@ -431,10 +432,39 @@ CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz" CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}" CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh" +verify_hash() { + remote_sha256="$1" + local_file="$2" + + msg "Downloading ${remote_sha256}" + remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"` + if [ "$?" -ne 0 ]; then + rm -Rf "${CFG_TMP_DIR}" + err "Failed to download ${remote_url}" + fi + + msg "Verifying hash" + local_sha256=`"${CFG_SHASUM}" -a 256 "${local_file}"` + if [ "$?" -ne 0 ]; then + rm -Rf "${CFG_TMP_DIR}" + err "Failed to compute hash for ${local_tarball}" + fi + + # We only need the sha, not the filenames + remote_sha256=`echo ${remote_sha256} | cut -f 1 -d ' '` + local_sha256=`echo ${local_sha256} | cut -f 1 -d ' '` + + if [ "${remote_sha256}" != "${local_sha256}" ]; then + rm -Rf "${CFG_TMP_DIR}" + err "invalid sha256.\n ${remote_sha256}\t${remote_tarball}\n ${local_sha256}\t${local_tarball}" + fi +} + # Fetch the package. download_package() { remote_tarball="$1" local_tarball="$2" + remote_sha256="${remote_tarball}.sha256" msg "Downloading ${remote_tarball} to ${local_tarball}" @@ -444,6 +474,8 @@ download_package() { rm -Rf "${CFG_TMP_DIR}" err "failed to download installer" fi + + verify_hash "${remote_sha256}" "${local_tarball}" } # Wrap all the commands needed to install a package. From 32c187a879eae148b86f4c6650c0479f5e9662a3 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 18 Dec 2014 06:30:08 -0800 Subject: [PATCH 2/6] rustup: add caching of old nightlies --- src/etc/rustup.sh | 49 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index ab6823cf6c4a4..ee62cfe8cee93 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -230,7 +230,7 @@ validate_opt() { } create_tmp_dir() { - local TMP_DIR=./rustup-tmp-install + local TMP_DIR=`pwd`/rustup-tmp-install rm -Rf "${TMP_DIR}" need_ok "failed to remove temporary installation directory" @@ -271,6 +271,8 @@ VAL_OPTIONS="" flag uninstall "only uninstall from the installation prefix" valopt prefix "" "set installation prefix" opt cargo 1 "install cargo with rust" +valopt date "" "use the YYYY-MM-DD nightly instead of the current nightly" +flag save "save the downloaded nightlies to ~/.rustup" if [ $HELP -eq 1 ] then @@ -418,6 +420,21 @@ CFG_TMP_DIR=$(mktemp -d 2>/dev/null \ || mktemp -d -t 'rustup-tmp-install' 2>/dev/null \ || create_tmp_dir) +# If we're saving nightlies and we didn't specify which one, grab todays. +# Otherwise we'll use the latest version. +if [ -n "${CFG_SAVE}" -a -z "${CFG_DATE}" ]; +then + CFG_DATE=`date "+%Y-%m-%d"` +fi + +# If we're saving our nightlies, put them in $HOME/.rustup. +if [ -n "${CFG_SAVE}" ] +then + CFG_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_DATE}" +else + CFG_DOWNLOAD_DIR="${CFG_TMP_DIR}" +fi + RUST_URL="https://static.rust-lang.org/dist" RUST_PACKAGE_NAME=rust-nightly RUST_PACKAGE_NAME_AND_TRIPLE="${RUST_PACKAGE_NAME}-${HOST_TRIPLE}" @@ -432,6 +449,13 @@ CARGO_TARBALL_NAME="${CARGO_PACKAGE_NAME_AND_TRIPLE}.tar.gz" CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}" CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh" +# add a date suffix if we want a particular nighly. +if [ -n "${CFG_DATE}" ]; +then + RUST_URL="${RUST_URL}/${CFG_DATE}" + CARGO_URL="${CARGO_URL}/${CFG_DATE}" +fi + verify_hash() { remote_sha256="$1" local_file="$2" @@ -460,19 +484,25 @@ verify_hash() { fi } -# Fetch the package. +# Fetch the package. Optionally caches the tarballs. download_package() { remote_tarball="$1" local_tarball="$2" remote_sha256="${remote_tarball}.sha256" - msg "Downloading ${remote_tarball} to ${local_tarball}" + # Check if we've already downloaded this file. + if [ ! -e "${local_tarball}" ]; then + msg "Downloading ${remote_tarball} to ${local_tarball}" - "${CFG_CURL}" -f -o "${local_tarball}" "${remote_tarball}" - if [ $? -ne 0 ] - then - rm -Rf "${CFG_TMP_DIR}" - err "failed to download installer" + mkdir -p "${CFG_DOWNLOAD_DIR}" + need_ok "failed to create create download directory" + + "${CFG_CURL}" -f -o "${local_tarball} "${remote_tarball}" + if [ $? -ne 0 ] + then + rm -Rf "${CFG_TMP_DIR}" + err "failed to download installer" + fi fi verify_hash "${remote_sha256}" "${local_tarball}" @@ -482,9 +512,10 @@ download_package() { install_package() { tarball_name="$1" install_script="$2" + local_tarball="${CFG_DOWNLOAD_DIR}/${tarball_name}" msg "Extracting ${tarball_name}" - (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xzf "${tarball_name}") + (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xvf "${local_tarball}") if [ $? -ne 0 ]; then rm -Rf "${CFG_TMP_DIR}" err "failed to unpack installer" From b2fbed6e70cf99bd80fab1ea10ea605b612341c4 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 1 Dec 2014 00:20:43 -0800 Subject: [PATCH 3/6] rustup: allow rust and cargo snapshot dates to be different --- src/etc/rustup.sh | 56 +++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index ee62cfe8cee93..fa163b23529f5 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -272,6 +272,8 @@ flag uninstall "only uninstall from the installation prefix" valopt prefix "" "set installation prefix" opt cargo 1 "install cargo with rust" valopt date "" "use the YYYY-MM-DD nightly instead of the current nightly" +valopt rust-date "" "use the YYYY-MM-DD rust nightly instead of the current nightly" +valopt cargo-date "" "use the YYYY-MM-DD cargo nightly instead of the current nightly" flag save "save the downloaded nightlies to ~/.rustup" if [ $HELP -eq 1 ] @@ -427,12 +429,12 @@ then CFG_DATE=`date "+%Y-%m-%d"` fi -# If we're saving our nightlies, put them in $HOME/.rustup. -if [ -n "${CFG_SAVE}" ] -then - CFG_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_DATE}" -else - CFG_DOWNLOAD_DIR="${CFG_TMP_DIR}" +if [ -z "${CFG_RUST_DATE}" ]; then + CFG_RUST_DATE="${CFG_DATE}" +fi + +if [ -z "${CFG_CARGO_DATE}" ]; then + CFG_CARGO_DATE="${CFG_DATE}" fi RUST_URL="https://static.rust-lang.org/dist" @@ -450,10 +452,14 @@ CARGO_LOCAL_INSTALL_DIR="${CFG_TMP_DIR}/${CARGO_PACKAGE_NAME_AND_TRIPLE}" CARGO_LOCAL_INSTALL_SCRIPT="${CARGO_LOCAL_INSTALL_DIR}/install.sh" # add a date suffix if we want a particular nighly. -if [ -n "${CFG_DATE}" ]; +if [ -n "${CFG_RUST_DATE}" ]; +then + RUST_URL="${RUST_URL}/${CFG_RUST_DATE}" +fi + +if [ -n "${CFG_CARGO_DATE}" ]; then - RUST_URL="${RUST_URL}/${CFG_DATE}" - CARGO_URL="${CARGO_URL}/${CFG_DATE}" + CARGO_URL="${CARGO_URL}/${CFG_CARGO_DATE}" fi verify_hash() { @@ -494,9 +500,6 @@ download_package() { if [ ! -e "${local_tarball}" ]; then msg "Downloading ${remote_tarball} to ${local_tarball}" - mkdir -p "${CFG_DOWNLOAD_DIR}" - need_ok "failed to create create download directory" - "${CFG_CURL}" -f -o "${local_tarball} "${remote_tarball}" if [ $? -ne 0 ] then @@ -510,11 +513,10 @@ download_package() { # Wrap all the commands needed to install a package. install_package() { - tarball_name="$1" + local_tarball="$1" install_script="$2" - local_tarball="${CFG_DOWNLOAD_DIR}/${tarball_name}" - msg "Extracting ${tarball_name}" + msg "Extracting ${local_tarball}" (cd "${CFG_TMP_DIR}" && "${CFG_TAR}" -xvf "${local_tarball}") if [ $? -ne 0 ]; then rm -Rf "${CFG_TMP_DIR}" @@ -542,8 +544,24 @@ install_packages() { mkdir -p "${CFG_TMP_DIR}" need_ok "failed to create create temporary installation directory" - RUST_LOCAL_TARBALL="${CFG_TMP_DIR}/${RUST_TARBALL_NAME}" - CARGO_LOCAL_TARBALL="${CFG_TMP_DIR}/${CARGO_TARBALL_NAME}" + # If we're saving our nightlies, put them in $HOME/.rustup. + if [ -n "${CFG_SAVE}" ] + then + RUST_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_RUST_DATE}" + CARGO_DOWNLOAD_DIR="${HOME}/.rustup/${CFG_CARGO_DATE}" + else + RUST_DOWNLOAD_DIR="${CFG_TMP_DIR}" + CARGO_DOWNLOAD_DIR="${CFG_TMP_DIR}" + fi + + mkdir -p "${RUST_DOWNLOAD_DIR}" + need_ok "failed to create create download directory" + + mkdir -p "${CARGO_DOWNLOAD_DIR}" + need_ok "failed to create create download directory" + + RUST_LOCAL_TARBALL="${RUST_DOWNLOAD_DIR}/${RUST_TARBALL_NAME}" + CARGO_LOCAL_TARBALL="${CARGO_DOWNLOAD_DIR}/${CARGO_TARBALL_NAME}" download_package \ "${RUST_URL}/${RUST_TARBALL_NAME}" \ @@ -556,12 +574,12 @@ install_packages() { fi install_package \ - "${RUST_TARBALL_NAME}" \ + "${RUST_LOCAL_TARBALL}" \ "${RUST_LOCAL_INSTALL_SCRIPT}" if [ -z "${CFG_DISABLE_CARGO}" ]; then install_package \ - "${CARGO_TARBALL_NAME}" \ + "${CARGO_LOCAL_TARBALL}" \ "${CARGO_LOCAL_INSTALL_SCRIPT}" fi From 590499eb3c886bf7f6b3a732816ea263f1777886 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 1 Dec 2014 10:37:00 -0800 Subject: [PATCH 4/6] syntax: whitespace cleanup --- src/libsyntax/ast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0c8c17b080bf3..4dee6e8d66e27 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -983,7 +983,7 @@ impl LitIntType { #[deriving(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] pub enum Lit_ { LitStr(InternedString, StrStyle), - LitBinary(Rc >), + LitBinary(Rc>), LitByte(u8), LitChar(char), LitInt(u64, LitIntType), From 13aac00fa26103b2028e9dc203aae8e998b43ca7 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 3 Dec 2014 14:38:59 -0800 Subject: [PATCH 5/6] rustup: Add support for resuming downloads --- src/etc/rustup.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index fa163b23529f5..653eb96fa209a 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -497,15 +497,28 @@ download_package() { remote_sha256="${remote_tarball}.sha256" # Check if we've already downloaded this file. - if [ ! -e "${local_tarball}" ]; then + if [ -e "${local_tarball}.tmp" ]; then + msg "Resuming ${remote_tarball} to ${local_tarball}" + + "${CFG_CURL}" -f -C - -o "${local_tarball}.tmp" "${remote_tarball}" + if [ $? -ne 0 ] + then + rm -Rf "${CFG_TMP_DIR}" + err "failed to download installer" + fi + + mv "${local_tarball}.tmp" "${local_tarball}" + elif [ ! -e "${local_tarball}" ]; then msg "Downloading ${remote_tarball} to ${local_tarball}" - "${CFG_CURL}" -f -o "${local_tarball} "${remote_tarball}" + "${CFG_CURL}" -f -o "${local_tarball}.tmp" "${remote_tarball}" if [ $? -ne 0 ] then rm -Rf "${CFG_TMP_DIR}" err "failed to download installer" fi + + mv "${local_tarball}.tmp" "${local_tarball}" fi verify_hash "${remote_sha256}" "${local_tarball}" From 6465cb85a73fc1f0465d56867d6c3cee71d44b67 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 29 Dec 2014 11:33:57 -0500 Subject: [PATCH 6/6] rustup: allow the use of either sha256sum or shasum to verify the download hash --- src/etc/rustup.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/etc/rustup.sh b/src/etc/rustup.sh index 653eb96fa209a..b41d3db22e49e 100755 --- a/src/etc/rustup.sh +++ b/src/etc/rustup.sh @@ -244,7 +244,21 @@ create_tmp_dir() { probe_need CFG_CURL curl probe_need CFG_TAR tar probe_need CFG_FILE file -probe_need CFG_SHASUM shasum + +probe CFG_SHA256SUM sha256sum +probe CFG_SHASUM shasum + +if [ -z "$CFG_SHA256SUM" -a -z "$CFG_SHASUM" ]; then + err "unable to find either sha256sum or shasum" +fi + +calculate_hash() { + if [ -n "$CFG_SHA256SUM" ]; then + ${CFG_SHA256SUM} $@ + else + ${CFG_SHASUM} -a 256 $@ + fi +} CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/" CFG_SELF="$0" @@ -474,7 +488,7 @@ verify_hash() { fi msg "Verifying hash" - local_sha256=`"${CFG_SHASUM}" -a 256 "${local_file}"` + local_sha256=$(calculate_hash "${local_file}") if [ "$?" -ne 0 ]; then rm -Rf "${CFG_TMP_DIR}" err "Failed to compute hash for ${local_tarball}"