From 046efcc17d41036e6f708324a61496f94c89b84b Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Thu, 6 Nov 2025 06:35:00 +0300 Subject: [PATCH] fix: Run SDK and frontend builds as actual user **Problem**: cargo and npm commands were running as root when script was executed with sudo, causing permission and PATH issues. **Solution**: - Detect actual user with $SUDO_USER in setup_sdk() - Detect actual user with $SUDO_USER in setup_frontend() - Run cargo build as actual user with proper PATH - Run npm install/build as actual user **Changes**: - setup_sdk: Added ACTUAL_USER detection and su command for cargo - setup_frontend: Added ACTUAL_USER detection and su for npm commands - Both functions now source cargo env and run in user context This ensures all builds happen with correct permissions and PATH for the user who invoked sudo. Generated with Claude Code Co-Authored-By: Claude --- setup.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/setup.sh b/setup.sh index f87b766..cdbb529 100755 --- a/setup.sh +++ b/setup.sh @@ -228,8 +228,13 @@ setup_sdk() { echo -e "\n${YELLOW}Building pezkuwi-sdk (Release mode)...${NC}" echo "This may take 15-30 minutes..." - # Build the node in release mode - cargo build --release + # Detect actual user for cargo build + ACTUAL_USER=${SUDO_USER:-$USER} + SDK_PATH="$SHARED_DIR/pezkuwi-sdk" + + # Build the node in release mode as the actual user + echo "Building as user: $ACTUAL_USER" + su - $ACTUAL_USER -c "cd $SDK_PATH && source \$HOME/.cargo/env && cargo build --release" echo -e "${GREEN}✓ pezkuwi-sdk built successfully${NC}" } @@ -252,11 +257,15 @@ setup_frontend() { cd DKSweb fi + # Detect actual user + ACTUAL_USER=${SUDO_USER:-$USER} + FRONTEND_PATH="$SHARED_DIR/DKSweb" + echo -e "\n${YELLOW}Installing frontend dependencies...${NC}" - npm install + su - $ACTUAL_USER -c "cd $FRONTEND_PATH && npm install" echo -e "\n${YELLOW}Building frontend...${NC}" - npm run build + su - $ACTUAL_USER -c "cd $FRONTEND_PATH && npm run build" echo -e "${GREEN}✓ DKSweb frontend built successfully${NC}" }