Fix homelab directory detection when running with sudo

When running with sudo, $HOME becomes /root instead of the actual user's home.
Use $SUDO_USER to get the original user's home directory for HOPS deployment.

Fixes: ERROR: Homelab directory not found: /root/hops

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Stephen Klein
2025-07-20 08:07:52 -04:00
parent 736ed1b098
commit a28a6e5007
+7 -1
View File
@@ -665,7 +665,13 @@ EOF
log "🚀 Starting deployment..."
# Ensure we're in the correct directory
local HOMELAB_DIR="$HOME/hops"
# When running with sudo, use the original user's home directory
local HOMELAB_DIR
if [[ -n "$SUDO_USER" ]]; then
HOMELAB_DIR="$(eval echo ~$SUDO_USER)/hops"
else
HOMELAB_DIR="$HOME/hops"
fi
if [[ ! -d "$HOMELAB_DIR" ]]; then
error_exit_with_rollback "Homelab directory not found: $HOMELAB_DIR"
fi