Skip to content

Fix mkdir permission error for /opt/gh-aw on Linux#20399

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-mkdir-permission-error
Draft

Fix mkdir permission error for /opt/gh-aw on Linux#20399
Copilot wants to merge 3 commits intomainfrom
copilot/fix-mkdir-permission-error

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

create_dir() in setup.sh only used sudo on macOS, but /opt is root-owned on Linux too. Users who preinstall packages into /opt on ubuntu-latest runners hit mkdir: cannot create directory '/opt/gh-aw': Permission denied.

  • Replace OS-detection logic with a try-first approach: attempt mkdir -p without sudo, fall back to sudo only on failure
# Before: only handled macOS
create_dir() {
  if [[ "$(uname -s)" == "Darwin" ]]; then
    sudo mkdir -p "$1"
    sudo chown -R "$(whoami)" "$1"
  else
    mkdir -p "$1"
  fi
}

# After: platform-agnostic, least-privilege
create_dir() {
  if mkdir -p "$1" 2>/dev/null; then
    return
  fi
  sudo mkdir -p "$1"
  sudo chown -R "$(whoami)" "$1"
}

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI linked an issue Mar 10, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits March 10, 2026 17:48
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
…wned

The create_dir() function previously only used sudo on macOS (Darwin), but
/opt is root-owned on Linux as well. This caused "Permission denied" errors
when creating /opt/gh-aw directories on Linux runners.

The fix tries mkdir without sudo first, and falls back to sudo only if
the regular mkdir fails. This handles both Linux and macOS, and avoids
unnecessary sudo when permissions already allow the operation.

Fixes the issue where preinstalling packages that write to /opt caused
setup failures on ubuntu-latest runners.

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix mkdir permission error during setup Fix mkdir permission error for /opt/gh-aw on Linux Mar 10, 2026
@pelikhan
Copy link
Contributor

@Mossaka related to #20143 ? We should finish this PR before doing this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error mkdir setting up /opt

3 participants