Skip to content

Commit

Permalink
rustup plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ciiqr committed Oct 16, 2023
1 parent 5c969eb commit 0caaaf1
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rustup/plugin.yml
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"
60 changes: 60 additions & 0 deletions rustup/rustup.sh
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

0 comments on commit 0caaaf1

Please sign in to comment.