Skip to content

Commit 785176b

Browse files
committed
rustup: Don't attempt to download SHA if it exists
This way installer can work fully in offline mode. Put pre-downloaded files (rust-nightly-x86_64-unknown-linux-gnu.tar.gz and rust-nightly-x86_64-unknown-linux-gnu.tar.gz.sha256) into the $HOME/.rustup/YYYY-MM-DD directory as it would be done by script itself. Specify --save and --date=YYYY-MM-DD when running. Files will be picked up and used to install in offline mode.
1 parent d52398e commit 785176b

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/etc/rustup.sh

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,33 @@ then
453453
RUST_URL="${RUST_URL}/${CFG_DATE}"
454454
fi
455455

456-
verify_hash() {
457-
remote_sha256="$1"
458-
local_file="$2"
459-
456+
download_hash() {
460457
msg "Downloading ${remote_sha256}"
461458
remote_sha256=`"${CFG_CURL}" -f "${remote_sha256}"`
459+
if [ -n "${CFG_SAVE}" ]; then
460+
echo "${remote_sha256}" > "${local_sha_file}"
461+
fi
462462
if [ "$?" -ne 0 ]; then
463463
rm -Rf "${CFG_TMP_DIR}"
464464
err "Failed to download ${remote_url}"
465465
fi
466+
}
467+
468+
verify_hash() {
469+
remote_sha256="$1"
470+
local_file="$2"
471+
local_sha_file="${local_file}.sha256"
472+
473+
if [ -n "${CFG_SAVE}" ]; then
474+
if [ -f "${local_sha_file}" ]; then
475+
msg "Local ${local_sha_file} exists, treating as remote hash"
476+
remote_sha256=`cat "${local_sha_file}"`
477+
else
478+
download_hash
479+
fi
480+
else
481+
download_hash
482+
fi
466483

467484
msg "Verifying hash"
468485
local_sha256=$(calculate_hash "${local_file}")

0 commit comments

Comments
 (0)