Skip to content

Instantly share code, notes, and snippets.

@lifthrasiir
Created May 9, 2014 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifthrasiir/95c6d4943865ff12f673 to your computer and use it in GitHub Desktop.
Save lifthrasiir/95c6d4943865ff12f673 to your computer and use it in GitHub Desktop.
A script for downloading and extracting the official Rust nightly
#!/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