# Bootstrapping from scratch, set the channel and date from src/stage0.txt
PKGNAM=rustc
VERSION=${VERSION:-1.15.1}

BOOTSTRAP_CHANNEL=$(tar -x $PKGNAM-$VERSION-src/src/stage0.txt -f $PKGNAM-$VERSION-src.tar.?z* -O | grep ^rust | cut -d\  -f2 | cut -d- -f1)
BOOTSTRAP_DATE=$(tar -x $PKGNAM-$VERSION-src/src/stage0.txt -f $PKGNAM-$VERSION-src.tar.?z* -O | grep ^rust | cut -d\  -f2 | cut -d- -f2-4)
BOOTSTRAP_CARGO=$(tar -x $PKGNAM-$VERSION-src/src/stage0.txt -f $PKGNAM-$VERSION-src.tar.?z* -O | grep ^cargo | cut -d\  -f2)

( cd bootstrap/
  rm -f *gz *sha256
  for i in i686 x86_64; do
    wget https://static.rust-lang.org/dist/$BOOTSTRAP_DATE/rust-std-$BOOTSTRAP_CHANNEL-$i-unknown-linux-gnu.tar.gz
    wget https://static.rust-lang.org/dist/$BOOTSTRAP_DATE/rust-std-$BOOTSTRAP_CHANNEL-$i-unknown-linux-gnu.tar.gz.sha256
    wget https://static.rust-lang.org/dist/$BOOTSTRAP_DATE/rustc-$BOOTSTRAP_CHANNEL-$i-unknown-linux-gnu.tar.gz
    wget https://static.rust-lang.org/dist/$BOOTSTRAP_DATE/rustc-$BOOTSTRAP_CHANNEL-$i-unknown-linux-gnu.tar.gz.sha256
    wget https://s3.amazonaws.com/rust-lang-ci/cargo-builds/$BOOTSTRAP_CARGO/cargo-nightly-$i-unknown-linux-gnu.tar.gz 
    wget https://s3.amazonaws.com/rust-lang-ci/cargo-builds/$BOOTSTRAP_CARGO/cargo-nightly-$i-unknown-linux-gnu.tar.gz.sha256
  done )
