From 1496f9d9807664ae24943e93fa818f53fe74caa0 Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Thu, 6 Nov 2025 05:45:19 +0300 Subject: [PATCH] fix: Install Rust for actual user when running with sudo **Problem**: When setup script runs with sudo, Rust was installed in root's home directory (/root/.cargo), making it inaccessible to the actual user running the script. **Solution**: - Detect actual user using $SUDO_USER environment variable - Use 'su - $ACTUAL_USER -c' to run Rust installation commands - Install Rust in the actual user's home directory (~/.cargo) - Run all rustup commands (default, update, target add) as actual user **Testing**: Designed for 'mesut' user running 'sudo ./setup.sh 8' This ensures Rust is accessible to the user and can be used for SDK compilation without permission issues. Generated with Claude Code Co-Authored-By: Claude --- setup.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/setup.sh b/setup.sh index fd36c26..f87b766 100755 --- a/setup.sh +++ b/setup.sh @@ -170,25 +170,30 @@ install_dependencies() { if [ $RUST_MISSING -eq 1 ]; then echo -e "\n${YELLOW}Installing Rust...${NC}" echo "This may take a few minutes. Please wait..." - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --verbose - # Source cargo env - if [ -f "$HOME/.cargo/env" ]; then - source "$HOME/.cargo/env" - fi + # Detect actual user (not root when using sudo) + ACTUAL_USER=${SUDO_USER:-$USER} + ACTUAL_HOME=$(eval echo ~$ACTUAL_USER) + echo "Installing Rust for user: $ACTUAL_USER" + + # Install Rust as the actual user + su - $ACTUAL_USER -c 'curl --proto "=https" --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --verbose' + + # Configure Rust toolchain as the actual user echo -e "\n${YELLOW}Configuring Rust toolchain...${NC}" - rustup default stable - rustup update + su - $ACTUAL_USER -c 'source $HOME/.cargo/env && rustup default stable' + su - $ACTUAL_USER -c 'source $HOME/.cargo/env && rustup update' echo -e "\n${YELLOW}Adding WebAssembly target...${NC}" - rustup target add wasm32-unknown-unknown + su - $ACTUAL_USER -c 'source $HOME/.cargo/env && rustup target add wasm32-unknown-unknown' - echo -e "${GREEN}✓ Rust installed successfully${NC}" + echo -e "${GREEN}✓ Rust installed successfully for $ACTUAL_USER${NC}" else # Ensure wasm target is installed echo -e "\n${YELLOW}Ensuring wasm32-unknown-unknown target...${NC}" - rustup target add wasm32-unknown-unknown 2>/dev/null || true + ACTUAL_USER=${SUDO_USER:-$USER} + su - $ACTUAL_USER -c 'source $HOME/.cargo/env && rustup target add wasm32-unknown-unknown 2>/dev/null' || true fi # Install Node.js if missing