Skip to content

Commit 12db6d4

Browse files
committed
arch: guard against empty CONFIG_HOME in config.sh
If getent fails (user doesn't exist, auth service outage), CONFIG_HOME would be empty, causing secrets to be written to /.baudbot on the root filesystem. Now exits with a clear error instead.
1 parent 02192b6 commit 12db6d4

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

bin/config.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,25 @@ dim() { echo -e "${DIM}$1${RESET}"; }
3131
# BAUDBOT_CONFIG_USER env var overrides detection (used by install.sh)
3232
if [ -n "${BAUDBOT_CONFIG_USER:-}" ]; then
3333
CONFIG_USER="$BAUDBOT_CONFIG_USER"
34-
CONFIG_HOME=$(getent passwd "$CONFIG_USER" | cut -d: -f6)
3534
elif [ "$(id -u)" -eq 0 ]; then
3635
CONFIG_USER="${SUDO_USER:-root}"
3736
if [ "$CONFIG_USER" = "root" ]; then
3837
echo "Run as: sudo baudbot config (not as root directly)"
3938
exit 1
4039
fi
41-
CONFIG_HOME=$(getent passwd "$CONFIG_USER" | cut -d: -f6)
4240
else
4341
CONFIG_USER="$(whoami)"
42+
fi
43+
44+
if [ "$CONFIG_USER" = "$(whoami)" ] && [ -n "$HOME" ]; then
4445
CONFIG_HOME="$HOME"
46+
else
47+
CONFIG_HOME=$(getent passwd "$CONFIG_USER" | cut -d: -f6)
48+
fi
49+
50+
if [ -z "$CONFIG_HOME" ]; then
51+
echo "❌ Could not resolve home directory for user '$CONFIG_USER'"
52+
exit 1
4553
fi
4654

4755
CONFIG_DIR="$CONFIG_HOME/.baudbot"

0 commit comments

Comments
 (0)