This commit is contained in:
kristof 2025-06-15 18:09:34 +02:00
parent d6362a5152
commit 13839041ff
2 changed files with 54 additions and 21 deletions

View File

@ -40,14 +40,20 @@ fi
# Check if Rust is already installed # Check if Rust is already installed
if command -v rustc &> /dev/null; then if command -v rustc &> /dev/null; then
RUST_VERSION=$(rustc --version) RUST_VERSION=$(rustc --version 2>/dev/null || echo "")
warn "Rust is already installed: $RUST_VERSION" if [ -n "$RUST_VERSION" ]; then
read -p "Do you want to update/reinstall? (y/N): " -n 1 -r warn "Rust is already installed: $RUST_VERSION"
echo read -p "Do you want to update/reinstall? (y/N): " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo
log "Installation cancelled" if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 0 log "Installation cancelled"
exit 0
fi
else
warn "Rust tools found but no default toolchain set. Will configure default toolchain."
fi fi
elif command -v rustup &> /dev/null; then
warn "Rustup found but no default toolchain set. Will configure default toolchain."
fi fi
# Check for required dependencies # Check for required dependencies
@ -85,11 +91,20 @@ log "Starting Rust installation..."
log "CARGO_HOME: $CARGO_HOME" log "CARGO_HOME: $CARGO_HOME"
log "RUSTUP_HOME: $RUSTUP_HOME" log "RUSTUP_HOME: $RUSTUP_HOME"
# Download and run rustup installer # Check if rustup is already installed but needs default toolchain
log "Downloading rustup installer..." if command -v rustup &> /dev/null; then
if [ "$EUID" -eq 0 ]; then log "Rustup already installed. Setting up default toolchain..."
# For root installation, we need to handle it differently if [ "$EUID" -eq 0 ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path /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 # Create symlinks for system-wide access
ln -sf "$CARGO_HOME/bin/cargo" /usr/local/bin/cargo ln -sf "$CARGO_HOME/bin/cargo" /usr/local/bin/cargo
@ -118,28 +133,44 @@ else
log "Rust installed for current user." log "Rust installed for current user."
log "To use Rust in new shells, run: source ~/.cargo/env" log "To use Rust in new shells, run: source ~/.cargo/env"
log "Or add ~/.cargo/bin to your PATH in your shell profile" log "Or add ~/.cargo/bin to your PATH in your shell profile"
fi
fi fi
# Verify installation # Verify installation
log "Verifying Rust installation..." log "Verifying Rust installation..."
if [ "$EUID" -eq 0 ]; then 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 "") RUST_VERSION=$(/usr/local/bin/rustc --version 2>/dev/null || echo "")
CARGO_VERSION=$(/usr/local/bin/cargo --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 else
RUST_VERSION=$("$CARGO_HOME/bin/rustc" --version 2>/dev/null || echo "") # Source the cargo environment
CARGO_VERSION=$("$CARGO_HOME/bin/cargo" --version 2>/dev/null || echo "") 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 fi
if [ -n "$RUST_VERSION" ] && [ -n "$CARGO_VERSION" ]; then if [ -n "$RUST_VERSION" ] && [ -n "$CARGO_VERSION" ]; then
log "✅ Rust installation successful!" log "✅ Rust installation successful!"
log "Rust compiler: $RUST_VERSION" log "Rust compiler: $RUST_VERSION"
log "Cargo package manager: $CARGO_VERSION" log "Cargo package manager: $CARGO_VERSION"
if [ -n "$RUSTUP_VERSION" ]; then
log "Rustup toolchain manager: $RUSTUP_VERSION"
fi
# Install common components # Set default toolchain and install common components
log "Installing common Rust components..." log "Setting default Rust toolchain..."
if [ "$EUID" -eq 0 ]; then if [ "$EUID" -eq 0 ]; then
/usr/local/bin/rustup default stable
log "Installing common Rust components..."
/usr/local/bin/rustup component add clippy rustfmt /usr/local/bin/rustup component add clippy rustfmt
else else
"$CARGO_HOME/bin/rustup" default stable
log "Installing common Rust components..."
"$CARGO_HOME/bin/rustup" component add clippy rustfmt "$CARGO_HOME/bin/rustup" component add clippy rustfmt
fi fi
@ -157,4 +188,6 @@ if [ -n "$RUST_VERSION" ] && [ -n "$CARGO_VERSION" ]; then
log "- Build and run: cd my_project && cargo run" log "- Build and run: cd my_project && cargo run"
else else
error "Rust installation failed. Please check the output above for errors." error "Rust installation failed. Please check the output above for errors."
fi fi
rustup default stable

View File

@ -36,7 +36,7 @@ log "Script directory: $SCRIPT_DIR"
# Define target directory for SAL repository # Define target directory for SAL repository
SAL_TARGET_DIR="/root/code/git.threefold.info/herocode/sal" 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 # Function to check if ssh-agent is loaded and has keys
check_ssh_agent() { check_ssh_agent() {
@ -59,10 +59,10 @@ check_ssh_agent() {
# Function to test SSH connection to git server # Function to test SSH connection to git server
test_ssh_connection() { 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 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.ourworld.tf successful" log "✅ SSH connection to git.threefold.info successful"
return 0 return 0
else else
warn "SSH connection test failed. Continuing anyway..." warn "SSH connection test failed. Continuing anyway..."