-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: rustup | ||
when: family == "unix" | ||
|
||
provision: | ||
when: declaration == "rustup" | ||
|
||
executable: rustup.sh | ||
|
||
schema: | ||
$schema: https://json-schema.org/draft/2020-12/schema | ||
type: "null" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
# NOTE: DOES NOT APPLY TO FUNCTIONS CALLED INSIDE IF CONDITIONS OR WITH ||/&& CHAINS | ||
set -e | ||
|
||
eval "$(nk plugin helper bash 2>/dev/null)" | ||
|
||
rustup::provision_rustup() { | ||
if ! type 'rustup' >/dev/null 2>&1; then | ||
action='install' | ||
|
||
# download init script | ||
declare rustup_init_script | ||
rustup_init_script="$(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs)" \ | ||
|| return "$(nk::error "$?" 'failed downloading rustup installer')" | ||
|
||
# install rustup | ||
sh -s - -y --no-modify-path <<< "$rustup_init_script" \ | ||
|| return "$(nk::error "$?" 'failed installing rustup cli')" | ||
changed='true' | ||
else | ||
action='update' | ||
|
||
declare rustup_check_output | ||
rustup_check_output="$(rustup check)" \ | ||
|| return "$(nk::error "$?" 'failed checking for updates')" | ||
|
||
if [[ "$rustup_check_output" == *'Update available'* ]]; then | ||
rustup update \ | ||
|| return "$(nk::error "$?" 'failed updating')" | ||
changed='true' | ||
fi | ||
fi | ||
} | ||
|
||
rustup::provision() { | ||
# install rustup | ||
declare action='install' | ||
declare status='success' | ||
declare changed='false' | ||
declare output='' | ||
if ! nk::run_for_output output rustup::provision_rustup; then | ||
status='failed' | ||
fi | ||
nk::log_result \ | ||
"$status" \ | ||
"$changed" \ | ||
"${action} rustup" \ | ||
"$output" | ||
} | ||
|
||
case "$1" in | ||
provision) | ||
rustup::provision "${@:2}" | ||
;; | ||
*) | ||
echo "rustup: unrecognized subcommand ${1}" 1>&2 | ||
exit 1 | ||
;; | ||
esac |