Skip to content

Commit 14e2888

Browse files
author
sheeek
committed
Fix user switch: Use proper login shell with .bashrc sourcing
- Create ~/.clawdbot-init that displays welcome message once - Add sourcing to .bashrc (removes itself after first run) - Use simple 'exec sudo -i -u clawdbot' without complex redirects - This ensures proper login shell initialization and user switch
1 parent 324bf01 commit 14e2888

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

roles/clawdbot/files/clawdbot-setup.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ echo ""
5252
echo -e "${YELLOW}Switching to clawdbot user for setup...${NC}"
5353
echo ""
5454

55-
# Create a .bashrc snippet that shows the welcome message once
56-
cat > /tmp/.clawdbot-motd << 'MOTD_EOF'
55+
# Create init script that will be sourced on login
56+
cat > /home/clawdbot/.clawdbot-init << 'INIT_EOF'
57+
# Display welcome message
5758
echo "============================================"
5859
echo "📋 Clawdbot Setup - Next Steps"
5960
echo "============================================"
@@ -85,10 +86,19 @@ echo "============================================"
8586
echo ""
8687
echo "Type 'exit' to return to previous user"
8788
echo ""
88-
# Remove this file so it only shows once
89-
rm -f /tmp/.clawdbot-motd
90-
MOTD_EOF
89+
90+
# Remove this init file after first login
91+
rm -f ~/.clawdbot-init
92+
INIT_EOF
93+
94+
chown clawdbot:clawdbot /home/clawdbot/.clawdbot-init
95+
96+
# Add one-time sourcing to .bashrc if not already there
97+
if ! grep -q '.clawdbot-init' /home/clawdbot/.bashrc; then
98+
echo '' >> /home/clawdbot/.bashrc
99+
echo '# One-time setup message' >> /home/clawdbot/.bashrc
100+
echo '[ -f ~/.clawdbot-init ] && source ~/.clawdbot-init' >> /home/clawdbot/.bashrc
101+
fi
91102

92103
# Switch to clawdbot user with login shell
93-
# Use bash --rcfile to source the MOTD before starting interactive shell
94-
exec sudo -i -u clawdbot bash --rcfile <(cat ~/.bashrc 2>/dev/null; cat /tmp/.clawdbot-motd 2>/dev/null)
104+
exec sudo -i -u clawdbot

0 commit comments

Comments
 (0)