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 <noreply@anthropic.com>
This commit is contained in:
2025-11-06 06:35:00 +03:00
parent 1496f9d980
commit 046efcc17d
+13 -4
View File
@@ -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}"
}