diff --git a/ansible/roles/dev-desktop/files/scripts/help.sh b/ansible/roles/dev-desktop/files/scripts/help.sh index e8060d4dc..2be716d77 100644 --- a/ansible/roles/dev-desktop/files/scripts/help.sh +++ b/ansible/roles/dev-desktop/files/scripts/help.sh @@ -1,11 +1,11 @@ #!/usr/bin/env bash echo "# Available scripts for managing your Rust checkouts" -echo "init.sh | first time setup, you should only have to execute this once on a new machine" +echo "setup_rustup.sh | first time setup, you should only have to execute this once on a new machine" echo "status.sh | list the branches and git status of all copies of the Rust repo" echo "new_worktree.sh | creates a worktree (shallow copy of the main git checkout of Rust, sharing the .git folder)" echo "detach_merged_prs.sh | invokes \"git pull --fast-forward-only\" on all worktrees and detaches those that are equal to the \"master\" branch" echo "" echo "# Rarer commands:" -echo "set_defaults.sh | connects the global config.toml with all worktrees. Use this when your setup is broken" - +echo "set_defaults.sh | connects the global config.toml with all worktrees. Use this when your setup is broken" +echo "setup_rust.sh | Clone your fork of rust-lang/rust, compile, and then link it" diff --git a/ansible/roles/dev-desktop/files/scripts/init.sh b/ansible/roles/dev-desktop/files/scripts/init.sh old mode 100755 new mode 100644 index 64a35e11e..94c210a69 --- a/ansible/roles/dev-desktop/files/scripts/init.sh +++ b/ansible/roles/dev-desktop/files/scripts/init.sh @@ -1,15 +1,9 @@ #!/usr/bin/env bash -username=`id -u -n` -gh_name=${username#"gh-"} - -# Using https instead of git urls because vscode only handles login on push/pull -git clone https://github.com/$gh_name/rust.git -pushd rust -git remote add upstream https://github.com/rust-lang/rust.git -git fetch upstream -git checkout upstream/master -popd +# Enable strict mode for Bash +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' init_git.py setup_rustup.sh diff --git a/ansible/roles/dev-desktop/files/scripts/link_rust.sh b/ansible/roles/dev-desktop/files/scripts/link_rust.sh new file mode 100755 index 000000000..61092e5d1 --- /dev/null +++ b/ansible/roles/dev-desktop/files/scripts/link_rust.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Enable strict mode for Bash +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + +# Discover target triple (e.g. "aarch64-unknown-linux-gnu") +target="$(rustc -vV | awk '/host/ { print $2 }')" + +rustc_dummy=$( + cat <> "${directory}/bin/rustc" + chmod +x "${directory}/bin/rustc" + fi + + rustup toolchain link "${D}_${stage}" "$directory" + done + + popd + fi +done diff --git a/ansible/roles/dev-desktop/files/scripts/new_worktree.sh b/ansible/roles/dev-desktop/files/scripts/new_worktree.sh index 1e10a6942..8e1127ffd 100755 --- a/ansible/roles/dev-desktop/files/scripts/new_worktree.sh +++ b/ansible/roles/dev-desktop/files/scripts/new_worktree.sh @@ -13,4 +13,4 @@ git checkout upstream/master ln -s ../config.toml popd -setup_rustup.sh +link_rust.sh diff --git a/ansible/roles/dev-desktop/files/scripts/set_defaults.sh b/ansible/roles/dev-desktop/files/scripts/set_defaults.sh index d068783c8..ab56eed2c 100755 --- a/ansible/roles/dev-desktop/files/scripts/set_defaults.sh +++ b/ansible/roles/dev-desktop/files/scripts/set_defaults.sh @@ -1,9 +1,16 @@ #!/usr/bin/env bash +# Enable strict mode for Bash +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + for D in rust*; do if [ -d "${D}" ]; then - pushd $D - ln -s ../config.toml - popd + pushd "${D}" || exit + if [[ ! -f config.toml ]]; then + ln -s ~/config.toml . + fi + popd || exit fi done diff --git a/ansible/roles/dev-desktop/files/scripts/setup_rust.sh b/ansible/roles/dev-desktop/files/scripts/setup_rust.sh new file mode 100755 index 000000000..5cf0fae11 --- /dev/null +++ b/ansible/roles/dev-desktop/files/scripts/setup_rust.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Enable strict mode for Bash +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + +username=$(id -u -n) +gh_name=${username#"gh-"} + +set -x + +if [[ ! -d "rust" ]]; then + # Using https instead of git urls because vscode only handles login on push/pull + git clone "https://github.com/${gh_name}/rust.git" +fi + +pushd rust + +if ! git remote | grep upstream; then + git remote add upstream https://github.com/rust-lang/rust.git +fi + +git fetch upstream +git checkout upstream/master +popd + +set_defaults.sh +link_rust.sh diff --git a/ansible/roles/dev-desktop/files/scripts/setup_rustup.sh b/ansible/roles/dev-desktop/files/scripts/setup_rustup.sh old mode 100644 new mode 100755 index 9a4d26cfd..862309b3f --- a/ansible/roles/dev-desktop/files/scripts/setup_rustup.sh +++ b/ansible/roles/dev-desktop/files/scripts/setup_rustup.sh @@ -1,14 +1,15 @@ #!/usr/bin/env bash -set -x - -rustup --version || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y - -source "$HOME/.cargo/env" - -for D in rust*; do - if [ -d "${D}" ]; then - rustup toolchain link "$D"_stage1 "$D/build/x86_64-unknown-linux-gnu/stage1" - rustup toolchain link "$D"_stage2 "$D/build/x86_64-unknown-linux-gnu/stage2" - fi -done +# Enable strict mode for Bash +# http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail +IFS=$'\n\t' + +# Check if rustup is already installed and exit if that's the case. +if command -v rustup &>/dev/null; then + rustup --version + exit 0 +fi + +echo "Installing rustup..." +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y