From 5312189ed142e86bdb5b237329ef488eef6efd72 Mon Sep 17 00:00:00 2001 From: Aditya Gupta Date: Sat, 20 Jun 2026 14:10:53 +0530 Subject: [PATCH] feat: Add rustup installer --- VERSION | 2 +- installers/install_rust.sh | 82 ++++++++++++++++++++++++++++++++++++++ readme.md | 1 + routes.sh | 3 +- 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 installers/install_rust.sh diff --git a/VERSION b/VERSION index ee90284..90a27f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.4 +1.0.5 diff --git a/installers/install_rust.sh b/installers/install_rust.sh new file mode 100644 index 0000000..0464087 --- /dev/null +++ b/installers/install_rust.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +# +# Rust Installer Script +# + +# Run metascript to check if the shell is bash and load libraries +PARENT_DIR="$(dirname "$0")/.." +METASCRIPT_LOCAL="$PARENT_DIR/bootstrap.sh" +METASCRIPT_URL="https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/bootstrap.sh" + +if [ -f "$METASCRIPT_LOCAL" ]; then + . "$METASCRIPT_LOCAL" +else + if command -v wget >/dev/null 2>&1; then + eval "$(wget -qO- "$METASCRIPT_URL")" + elif command -v curl >/dev/null 2>&1; then + eval "$(curl -fsSL "$METASCRIPT_URL")" + else + echo "Error: Neither wget nor curl is installed to fetch bootstrap.sh." >&2 + exit 1 + fi +fi + +set -euo pipefail + +install_curl() { + if ! has_command curl; then + log_info "curl not found. Installing curl..." + pkg_install curl + fi +} + +install_rust() { + if has_command rustup || [ -f "$HOME/.cargo/bin/rustup" ]; then + if ! confirm "Rust (rustup) is already installed. Reinstall/Upgrade?"; then + log_info "Skipping Rust installation." + return + fi + else + if ! confirm "Install Rust (rustup)?"; then + log_info "Skipping Rust installation." + return + fi + fi + + install_curl + + log_info "Downloading and running the official rustup installer..." + # The -s -- -y flag runs the rustup installer non-interactively, accepting defaults. + # --no-modify-path prevents the installer from modifying the shell startup files, + # as we handle this cleanly ourselves using bootstrap's configure_shell. + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path +} + +configure_shell() { + # Add ~/.cargo/bin to PATH for the current process + export PATH="$HOME/.cargo/bin:$PATH" + + IFS=' ' read -ra target_files <<< "$(get_shell_configs)" + + for config_file in "${target_files[@]}"; do + log_info "Configuring Rust environment in $config_file..." + local content='. "$HOME/.cargo/env"' + + inject_block "$config_file" "rust init" "$content" + + # Source if modified (only for bashrc) + if [ "$config_file" = "$HOME/.bashrc" ]; then + . "$config_file" 2>/dev/null || true + fi + done +} + +main() { + install_rust + configure_shell + + echo + log_success "Rust (rustup) installation and configuration complete." +} + +main "$@" diff --git a/readme.md b/readme.md index 2a973f7..3bcf07a 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,7 @@ The goal is simple: reduce the number of manual steps required after installing | `install_bat.sh` | Installs Bat (alternative to cat) and configures alias. | | `install_node.sh` | Installs Node.js (LTS) and NVM (Node Version Manager). | | `install_nvim.sh` | Installs Neovim 0.11.7 and clones my Neovim configuration repository. | +| `install_rust.sh` | Installs Rust (rustup) and configures cargo environment. | | `install_yazi.sh` | Installs Yazi terminal file manager and its dependencies. | | `install_zoxide.sh` | Installs Zoxide directory jumper and configures shell integrations. | diff --git a/routes.sh b/routes.sh index af3d37e..8a80aca 100755 --- a/routes.sh +++ b/routes.sh @@ -22,13 +22,14 @@ declare -A INSTALLERS=( [node]="Install Node.js (LTS) and NVM" [nvim]="Install Neovim 0.11.7 and configuration" [pnpm]="Install pnpm package manager" + [rust]="Install Rustup and Rust compiler/toolchain" [starship]="Install Starship shell prompt" [yay]="Install Yay AUR helper" [yazi]="Install Yazi terminal file manager and dependencies" [zoxide]="Install Zoxide directory jumper" ) # Order in which installers should be displayed -INSTALLER_KEYS=(agy bat node nvim pnpm starship yay yazi zoxide) +INSTALLER_KEYS=(agy bat node nvim pnpm rust starship yay yazi zoxide) SCRIPT_NAMES="${1:-}" if [ -z "$SCRIPT_NAMES" ] || [ "$SCRIPT_NAMES" = "-h" ] || [ "$SCRIPT_NAMES" = "--help" ]; then