Homebrew / brew

🍺 The missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
41.45k stars 9.75k forks source link

`brew install` commands quit my script upon `brew cleanup WHATEVER` #13809

Closed trusktr closed 2 years ago

trusktr commented 2 years ago

brew config output

trusktr@trusktrs-MacBook-Air ~ % brew config
HOMEBREW_VERSION: 3.5.10
ORIGIN: https://github.com/Homebrew/brew
HEAD: c5731faf8be1ddc1eeae4b162b88bd76318fc279
Last commit: 2 weeks ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: bb6e33d26b844ec871712e6264ae79e368c0d157
Core tap last commit: 8 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit dunno
Clang: 13.1.6 build 1316
Git: 2.37.3 => /opt/homebrew/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.5-arm64
CLT: 13.4.0.0.1.1651278267
Xcode: N/A
Rosetta 2: false

brew doctor output

trusktr@trusktrs-MacBook-Air ~ % brew doctor
Your system is ready to brew.

Verification

What were you trying to do (and why)?

I have a setup.sh script that I run on brand new machines. Essentially it looks like this:

set -e
set -x
trap "exit" INT

# if `brew` command does not exist
if ! quiet command -v brew; then 
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/trusktr/.zprofile 
    eval "$(/opt/homebrew/bin/brew shellenv)" 
fi 

brew tap homebrew/cask # add community packages 
brew tap homebrew/cask-fonts # add community fonts 

brew install zsh
brew install git
# ... brew install etc ...

Longer version:

https://github.com/trusktr/dotfiles/blob/f64c2cd7d28b50efe3cc6e5d376f44972c45ac0d/setup.sh

(I will verify the simplest possible reproduction steps when I get a chance).

What happened (include all command output)?

On the very first brew install command in my script, it exits (code zero) with this last output:

...
==> Running `brew cleanup zsh`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

If I run the script again, it will skip the first brew install zsh because it is already installed, then the same thing will (may?) happen on the next line:

...
==> Running `brew cleanup git`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

What did you expect to happen?

I expect brew not to exit on any brew install command.

This wasn't happening when Homebrew was on Ruby. This is my first time trying this while on Bash Homebrew.

Step-by-step reproduction instructions (by running brew commands)

Boot into out-of-the-box MacBook Air M2 2022 with

trusktr commented 2 years ago

I will publish my install script in a bit.

It doesn't seem to happen on every brew install line, but when it does, it always ends with the brew cleanup process.

For now, my workaround is to simply keep re-running the script until it goes through each install.

carlocab commented 2 years ago

The output of brew config and brew doctor is required for all bug reports to this repository. Please see the information in the bug report template.

We can reopen this when you provide the requested information.

trusktr commented 2 years ago

Here it is:

trusktr@trusktrs-MacBook-Air ~ % brew config
HOMEBREW_VERSION: 3.5.10
ORIGIN: https://github.com/Homebrew/brew
HEAD: c5731faf8be1ddc1eeae4b162b88bd76318fc279
Last commit: 2 weeks ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: bb6e33d26b844ec871712e6264ae79e368c0d157
Core tap last commit: 8 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit dunno
Clang: 13.1.6 build 1316
Git: 2.37.3 => /opt/homebrew/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.5-arm64
CLT: 13.4.0.0.1.1651278267
Xcode: N/A
Rosetta 2: false

trusktr@trusktrs-MacBook-Air ~ % brew doctor
Your system is ready to brew.

The above script (except my script has a lot more additional brew install commands) reproduces it on a brand new MacBook Air (M2 2022) with macOS 12.5 (21G72), fresh out of the box today.

carlocab commented 2 years ago

The above script (except my script has a lot more additional brew install commands) reproduces it on a brand new MacBook Air (M2 2022) with macOS 12.5 (21G72), fresh out of the box today.

You seem to have forgotten to attach your script.

trusktr commented 2 years ago

I mentioned I'd publish it in a bit

carlocab commented 2 years ago

Right, but you also said "the above script" which is very strongly suggestive of where one ought to find the said script.

trusktr commented 2 years ago

The above script was abbreviated. This seems to be true so far:

set -e
set -x
trap "exit" INT

# if `brew` command does not exist
if ! quiet command -v brew; then 
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/trusktr/.zprofile 
    eval "$(/opt/homebrew/bin/brew shellenv)" 
fi 

brew tap homebrew/cask # add community packages 
brew tap homebrew/cask-fonts # add community fonts 

brew install git # <--------------------------------------- HERE, it exits with code 0.
brew install zsh # <-------------------- on subsequent run, it exits here with code 0.

Maybe it is a macOS problem on these new M chips. I just discovered that the same issue happens with one other non-brew command so far:

nvim +PlugInstall +UpdateRemotePlugins +qa! # this is NeoVim, exits the same with zero.

This is a completely fresh macOS. I opened the laptop out of the box, started the above script, and it quit right on that first brew install line.

I did not tweak the system or install anything except Chrome browser, and the running the git command installed macOS devtools, but that's it.


Next week once I've caught up on some work I can try a factory reset and try to reproduce it again.

trusktr commented 2 years ago

Alright, here's my actual script, but basically it boils down to anything that is inside of if $isMacOS branches. The other stuff is for variants of Linux and is ignored.

https://github.com/trusktr/dotfiles/blob/f64c2cd7d28b50efe3cc6e5d376f44972c45ac0d/setup.sh

When I get some free time after some critical things I need to deliver, I will make verify the simplest reproduction possible.

MikeMcQuaid commented 2 years ago

This is better handled in Homebrew/discussions. It's very unclear to me that the problem here is with Homebrew rather than your script.

If you're wanting to install multiple packages like this: use brew bundle in your script instead.

carlocab commented 2 years ago

I ran your script under /bin/bash and added an echo finished at the end to make sure it made it there.

It ran as expected: the commands were printed and executed, and it echoed finished upon completion.

This doesn't seem to be a problem in brew.

trusktr commented 2 years ago

Might be a problem in brand new macOS on M2. I will try again with a factory reset this weekend.

trusktr commented 2 years ago

(I've been running this same script on brand new macs for several years (with small tweaks to the specific packages, and now the brew install command), but only now has this problem started, and it is the first time that I'm using the Bash version of brew and on an M2 coincidentally. Not to say it must be Homebrew's issue, but it seems correlated with now being on Bash and/or M2)

MikeMcQuaid commented 2 years ago

@trusktr I maintain https://github.com/mikemcquaid/strap that does something similar for me and many other people. I'd strongly recommend that you should use brew bundle here instead. It's literally designed for this case.

I'm afraid we can't keep an issue open here that is "my script doesn't work any more".