From 13839041ff33e299b9f4691079be7807504b6975 Mon Sep 17 00:00:00 2001 From: kristof Date: Sun, 15 Jun 2025 18:09:34 +0200 Subject: [PATCH] ... --- tools/install_rust.sh | 67 +++++++++++++++++++++++++++++---------- tools/install_rust_sal.sh | 8 ++--- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/tools/install_rust.sh b/tools/install_rust.sh index 023749f..afd9cb4 100755 --- a/tools/install_rust.sh +++ b/tools/install_rust.sh @@ -40,14 +40,20 @@ fi # Check if Rust is already installed if command -v rustc &> /dev/null; then - RUST_VERSION=$(rustc --version) - warn "Rust is already installed: $RUST_VERSION" - read -p "Do you want to update/reinstall? (y/N): " -n 1 -r - echo - if [[ ! $REPLY =~ ^[Yy]$ ]]; then - log "Installation cancelled" - exit 0 + RUST_VERSION=$(rustc --version 2>/dev/null || echo "") + if [ -n "$RUST_VERSION" ]; then + warn "Rust is already installed: $RUST_VERSION" + read -p "Do you want to update/reinstall? (y/N): " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + log "Installation cancelled" + exit 0 + fi + else + warn "Rust tools found but no default toolchain set. Will configure default toolchain." fi +elif command -v rustup &> /dev/null; then + warn "Rustup found but no default toolchain set. Will configure default toolchain." fi # Check for required dependencies @@ -85,11 +91,20 @@ log "Starting Rust installation..." log "CARGO_HOME: $CARGO_HOME" log "RUSTUP_HOME: $RUSTUP_HOME" -# Download and run rustup installer -log "Downloading rustup installer..." -if [ "$EUID" -eq 0 ]; then - # For root installation, we need to handle it differently - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path +# Check if rustup is already installed but needs default toolchain +if command -v rustup &> /dev/null; then + log "Rustup already installed. Setting up default toolchain..." + if [ "$EUID" -eq 0 ]; then + /usr/local/bin/rustup default stable || rustup default stable + else + "$CARGO_HOME/bin/rustup" default stable || rustup default stable + fi +else + # Download and run rustup installer + log "Downloading rustup installer..." + if [ "$EUID" -eq 0 ]; then + # For root installation, we need to handle it differently + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path # Create symlinks for system-wide access ln -sf "$CARGO_HOME/bin/cargo" /usr/local/bin/cargo @@ -118,28 +133,44 @@ else log "Rust installed for current user." log "To use Rust in new shells, run: source ~/.cargo/env" log "Or add ~/.cargo/bin to your PATH in your shell profile" + fi fi # Verify installation log "Verifying Rust installation..." if [ "$EUID" -eq 0 ]; then + # Source the environment first + export PATH="/usr/local/cargo/bin:$PATH" RUST_VERSION=$(/usr/local/bin/rustc --version 2>/dev/null || echo "") CARGO_VERSION=$(/usr/local/bin/cargo --version 2>/dev/null || echo "") + RUSTUP_VERSION=$(/usr/local/bin/rustup --version 2>/dev/null || echo "") else - RUST_VERSION=$("$CARGO_HOME/bin/rustc" --version 2>/dev/null || echo "") - CARGO_VERSION=$("$CARGO_HOME/bin/cargo" --version 2>/dev/null || echo "") + # Source the cargo environment + if [ -f "$CARGO_HOME/env" ]; then + source "$CARGO_HOME/env" + fi + RUST_VERSION=$("$CARGO_HOME/bin/rustc" --version 2>/dev/null || rustc --version 2>/dev/null || echo "") + CARGO_VERSION=$("$CARGO_HOME/bin/cargo" --version 2>/dev/null || cargo --version 2>/dev/null || echo "") + RUSTUP_VERSION=$("$CARGO_HOME/bin/rustup" --version 2>/dev/null || rustup --version 2>/dev/null || echo "") fi if [ -n "$RUST_VERSION" ] && [ -n "$CARGO_VERSION" ]; then log "✅ Rust installation successful!" log "Rust compiler: $RUST_VERSION" log "Cargo package manager: $CARGO_VERSION" + if [ -n "$RUSTUP_VERSION" ]; then + log "Rustup toolchain manager: $RUSTUP_VERSION" + fi - # Install common components - log "Installing common Rust components..." + # Set default toolchain and install common components + log "Setting default Rust toolchain..." if [ "$EUID" -eq 0 ]; then + /usr/local/bin/rustup default stable + log "Installing common Rust components..." /usr/local/bin/rustup component add clippy rustfmt else + "$CARGO_HOME/bin/rustup" default stable + log "Installing common Rust components..." "$CARGO_HOME/bin/rustup" component add clippy rustfmt fi @@ -157,4 +188,6 @@ if [ -n "$RUST_VERSION" ] && [ -n "$CARGO_VERSION" ]; then log "- Build and run: cd my_project && cargo run" else error "Rust installation failed. Please check the output above for errors." -fi \ No newline at end of file +fi + +rustup default stable \ No newline at end of file diff --git a/tools/install_rust_sal.sh b/tools/install_rust_sal.sh index ffd7526..ec68896 100755 --- a/tools/install_rust_sal.sh +++ b/tools/install_rust_sal.sh @@ -36,7 +36,7 @@ log "Script directory: $SCRIPT_DIR" # Define target directory for SAL repository SAL_TARGET_DIR="/root/code/git.threefold.info/herocode/sal" -SAL_REPO_URL="git@git.ourworld.tf:herocode/sal.git" +SAL_REPO_URL="git@git.threefold.info:herocode/sal.git" # Function to check if ssh-agent is loaded and has keys check_ssh_agent() { @@ -59,10 +59,10 @@ check_ssh_agent() { # Function to test SSH connection to git server test_ssh_connection() { - log "Testing SSH connection to git.ourworld.tf..." + log "Testing SSH connection to git.threefold.info..." - if ssh -T -o ConnectTimeout=10 -o StrictHostKeyChecking=no git@git.ourworld.tf 2>&1 | grep -q "successfully authenticated"; then - log "✅ SSH connection to git.ourworld.tf successful" + if ssh -T -o ConnectTimeout=10 -o StrictHostKeyChecking=no git@git.threefold.info 2>&1 | grep -q "successfully authenticated"; then + log "✅ SSH connection to git.threefold.info successful" return 0 else warn "SSH connection test failed. Continuing anyway..."