Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
LAYER2_IMAGE="py-bench:latest"
USER_IMAGE="py-bench:$USER"
GITCONFIG_PATH="${HOME}/.gitconfig"

ensure_host_gitconfig() {
if [ -d "$GITCONFIG_PATH" ]; then
if [ -n "$(find "$GITCONFIG_PATH" -mindepth 1 -print -quit 2>/dev/null)" ]; then
echo "❌ '$GITCONFIG_PATH' is a non-empty directory; refusing to remove it."
echo " Move or inspect its contents, then replace it with a regular file."
return 1
fi

echo "⚠️ '$GITCONFIG_PATH' is an empty directory; replacing it with a regular file..."
rmdir "$GITCONFIG_PATH"
Comment on lines +12 to +21

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The return status of ensure_host_gitconfig is not used, so failure won’t stop the script.

The function returns non-zero in several failure modes (non-empty directory, non-regular file, bad permissions), but the caller ignores this, so the container still starts after a failed gitconfig check. Please gate the rest of the script on ensure_host_gitconfig, e.g.:

  • ensure_host_gitconfig || exit 1 (or return 1 if sourced), or
  • if ensure_host_gitconfig; then docker-compose ...; fi

This prevents proceeding with a misconfigured ~/.gitconfig.

fi

if [ ! -e "$GITCONFIG_PATH" ]; then
echo "🔧 Creating host Git configuration file: $GITCONFIG_PATH"
(umask 077 && : > "$GITCONFIG_PATH")
fi

if [ ! -f "$GITCONFIG_PATH" ]; then
echo "❌ '$GITCONFIG_PATH' exists but is not a regular file."
return 1
fi

if [ ! -r "$GITCONFIG_PATH" ] || [ ! -w "$GITCONFIG_PATH" ]; then
echo "❌ '$GITCONFIG_PATH' must be readable and writable by '$USER'."
echo " Fix it with: sudo chown $USER:$(id -gn) '$GITCONFIG_PATH' && chmod 600 '$GITCONFIG_PATH'"
return 1
fi
}

echo "🚀 Starting the pyBench container"
echo " User: $USER"
Expand All @@ -21,6 +51,8 @@ else
"$REPO_DIR/scripts/ensure-layer3.sh" --base "$LAYER2_IMAGE" --user "$USER"
fi

ensure_host_gitconfig

echo "🔧 Starting container with user mapping..."
"$SCRIPT_DIR/scripts/configure-amd-rocm-wsl.sh"
docker-compose \
Expand Down