refactor: make install noninteractive terminal friendly

This commit is contained in:
robcholz
2026-02-07 22:25:26 -05:00
parent 57ebe7ffee
commit 75adb1696a
+26 -22
View File
@@ -47,36 +47,40 @@ ensure_cargo() {
print_message warning "Rust (cargo) is required but not found."
print_message info "You should review and approve the Rust installer before proceeding."
reply=""
if [[ -t 0 ]]; then
read -r -p "Install Rust using rustup now? (y/N) " reply
case "${reply}" in
y|Y)
if command -v curl >/dev/null 2>&1; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
elif command -v wget >/dev/null 2>&1; then
wget -qO- https://sh.rustup.rs | sh -s -- -y
else
print_message error "Missing required command: curl or wget"
print_message info "Install Rust manually from https://rustup.rs and retry."
exit 1
fi
# shellcheck source=/dev/null
if [[ -f "$HOME/.cargo/env" ]]; then
# shellcheck disable=SC1090
source "$HOME/.cargo/env"
fi
;;
*)
print_message info "Install Rust manually from https://rustup.rs and retry."
exit 1
;;
esac
elif [[ -r /dev/tty ]]; then
read -r -p "Install Rust using rustup now? (y/N) " reply </dev/tty
else
print_message error "Non-interactive shell: cannot prompt to install Rust."
print_message info "Install Rust manually from https://rustup.rs and retry."
exit 1
fi
case "${reply}" in
y|Y)
if command -v curl >/dev/null 2>&1; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
elif command -v wget >/dev/null 2>&1; then
wget -qO- https://sh.rustup.rs | sh -s -- -y
else
print_message error "Missing required command: curl or wget"
print_message info "Install Rust manually from https://rustup.rs and retry."
exit 1
fi
# shellcheck source=/dev/null
if [[ -f "$HOME/.cargo/env" ]]; then
# shellcheck disable=SC1090
source "$HOME/.cargo/env"
fi
;;
*)
print_message info "Install Rust manually from https://rustup.rs and retry."
exit 1
;;
esac
if ! command -v cargo >/dev/null 2>&1; then
print_message error "Cargo still not available after installation."
print_message info "Open a new shell or run: source \"$HOME/.cargo/env\""