Skip to content

fix(osx): use console owner instead of $USER in postinstall script#2279

Open
Copilot wants to merge 3 commits intomainfrom
copilot/create-answer-for-issue-1982
Open

fix(osx): use console owner instead of $USER in postinstall script#2279
Copilot wants to merge 3 commits intomainfrom
copilot/create-answer-for-issue-1982

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

  • Fix postinstall script: replace ${USER} with stat -f%Su /dev/console
  • Address review comment: handle SSH/headless installs where no console user exists
    • Try SUDO_USER first (set by sudo, reliable in both GUI/Homebrew and SSH contexts)
    • Fall back to stat -f%Su /dev/console for GUI sessions without sudo
    • If real user can't be determined (result is root or empty), skip configure and print a warning with manual instructions

💡 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.

…nstall script

Co-authored-by: marekzmyslowski <1062877+marekzmyslowski@users.noreply.github.com>
Copilot AI changed the title [WIP] Add response to user in issue 1982 fix(osx): use console owner instead of $USER in postinstall script Mar 4, 2026
@marekzmyslowski marekzmyslowski marked this pull request as ready for review March 12, 2026 08:03
@marekzmyslowski marekzmyslowski requested a review from a team as a code owner March 12, 2026 08:03
# from taking ownership of ~/.gitconfig).
# Use stat to determine the console user since the installer may be invoked with
# USER unset (e.g. when run via Homebrew which explicitly clears USER).
REAL_USER=$(stat -f%Su /dev/console)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if someone is installing GCM (either via Homebrew or the installer command line) from an SSH session where there is no console user? We need to make sure this works for remote/multi-user scenarios.

…fallback

Co-authored-by: marekzmyslowski <1062877+marekzmyslowski@users.noreply.github.com>
# from taking ownership of ~/.gitconfig)
sudo -u ${USER} "$INSTALL_DESTINATION/git-credential-manager" configure
# from taking ownership of ~/.gitconfig).
# Determine the real (non-root) user via multiple methods since the installer
Copy link
Contributor

Choose a reason for hiding this comment

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

USER/LOGNAME [..] when run via Homebrew which explicitly clears those environment variables

So in my testing I do NOT find this to be the case. If I modify the GCM Cask with a locally built pkg file that has env > /tmp/pkgenv.log in the postinstall script I see the following variables set (amongst others):

USER=mattche
HOME=/Users/mattche
LOGNAME=root
COMMAND_LINE_INSTALL=1

Specifically I see USER is set to the correct local username (mattche in my case). It is also not possible to run brew as sudo, at least with the latest version (I'm on 5.1.0).

I also tested the output of env from postinstall when installing the pkg file directly using

  1. Finder
USER=mattche
HOME=/Users/mattche
LOGNAME=root
  1. Terminal with sudo installer -target / -pkg gcm.pkg
USER=root
HOME=/Users/mattche
LOGNAME=root
COMMAND_LINE_INSTALL=1

Note that I do not see SUDO_USER set in any of these instances.

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.

3 participants