Created
May 9, 2014 06:23
-
-
Save lifthrasiir/95c6d4943865ff12f673 to your computer and use it in GitHub Desktop.
A script for downloading and extracting the official Rust nightly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# A script for downloading and extracting the official Rust nightly | |
# Written by Kang Seonghoon, put in the public domain. No warranty. | |
# | |
# LOCALRUST should be set to a directory to hold all Rust-related files | |
# including `bin`, `lib` etc. Since the script tries to erase all files | |
# and extract new files, LOCALRUST should be dedicated to this purpose only | |
# (i.e. do not set it to `/usr/local` or similar, you've been warned). | |
# | |
# The script will create `update-rust.last` file to track the most recent update. | |
# It does not try to update when there is no update available, | |
# so it is also suitable for crontab uses. Please also note that the script will | |
# silently abort when several assertions are not satisfied with an exit code of 1. | |
LASTFILE="$(dirname $0)/update-rust.last" | |
LOCALRUST=/usr/local/rust | |
TMPDIR=/tmp/$$-rust-nightly | |
RUST_NIGHTLY=http://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz | |
RUST_ARCNAME=rust-nightly.tar.gz | |
RUST_ARCTARGET=rust-nightly-x86_64-unknown-linux-gnu | |
LAST="$([ -r "$LASTFILE" ] && cat "$LASTFILE")" | |
LAST="${LAST:-Thu, 01 Jan 1970 00:00:00 GMT}" | |
curl -s --connect-timeout 3 -I ${RUST_NIGHTLY} -H "If-Modified-Since: ${LAST}" | awk -F 'Last-Modified:' ' | |
BEGIN { changed=0 } | |
/^HTTP\/[^ ]* 200 / { changed=1 } | |
/^Last-Modified:/ { print $2 > "'$LASTFILE'" } | |
END { exit changed } | |
' && exit 0 | |
mkdir -p ${TMPDIR} | |
trap 'rm -rf ${TMPDIR}' INT KILL QUIT EXIT | |
cd ${TMPDIR} | |
curl ${RUST_NIGHTLY} -o ${RUST_ARCNAME} || exit 1 | |
tar xzvf ${RUST_ARCNAME} | |
[ -d "${RUST_ARCTARGET}" ] || exit 1 | |
rm -rf ${LOCALRUST}/* | |
mv ${RUST_ARCTARGET}/* ${LOCALRUST} | |
${LOCALRUST}/bin/rustc -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment