Skip to content

Instantly share code, notes, and snippets.

@sbstp
Last active May 22, 2016 17:27
Show Gist options
  • Save sbstp/ffa56fedbb31ae8557da4ec98201beca to your computer and use it in GitHub Desktop.
Save sbstp/ffa56fedbb31ae8557da4ec98201beca to your computer and use it in GitHub Desktop.
Rust stable installer for Linux, includes the source code for tools like racer.
#!/bin/bash
#
# Installs the specified rust-stable version with the source code.
#
# The binaries are installed using the rust installer.
# They are located in /usr/local/bin.
#
# The source is installed in /usr/local/src/rust.
set -eu
uninstall() {
if [ -f "/usr/local/lib/rustlib/uninstall.sh" ] ; then
bash /usr/local/lib/rustlib/uninstall.sh
fi
if [ -d "/usr/local/src/rust" ] ; then
rm -r "/usr/local/src/rust"
fi
}
download() {
if ! wget -q --show-progress -O "$2" "$1" ; then
echo "Failed to download $1. Check your Internet connection."
exit
fi
}
if [ "$UID" -ne "0" ] ; then
echo "You must run this script as root."
exit
fi
if [ "$1" == "--uninstall" ] ; then
uninstall
echo "Rust has been uninstalled."
exit
fi
version="$1"
if [ -z "$version" ] ; then
echo "You must specify a version, e.g. './install 1.8.0' ."
exit
fi
if [[ ! "$version" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]] ; then
echo "The specified version is invalid. The format is 'x.y.z' ."
exit
fi
tmp=$(mktemp -d)
echo "Installing rust '$version' ..."
uninstall
echo "Downloading binaries"
download "https://static.rust-lang.org/dist/rust-$version-x86_64-unknown-linux-gnu.tar.gz" "$tmp/rust-bin.tar.gz"
echo "Downloading source"
download "https://static.rust-lang.org/dist/rustc-$version-src.tar.gz" "$tmp/rust-src.tar.gz"
echo "Installing binaries..."
tar -xzf "$tmp/rust-bin.tar.gz" -C "$tmp"
bash "$tmp/rust-$version-x86_64-unknown-linux-gnu/install.sh"
echo "Installing source..."
tar -xzf "$tmp/rust-src.tar.gz" -C "$tmp"
mkdir -p "/usr/local/src"
mv "$tmp/rustc-$version/src" "/usr/local/src/rust"
echo "Removing installation files..."
rm -r "$tmp"
echo "Installation complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment