Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For cleaner upgrade, have Homebrew .munki recipe delete old Homebrew subdirs first #103

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

aysiu
Copy link
Contributor

@aysiu aysiu commented Feb 10, 2025

To avoid an install loop. More details in #102

@aysiu
Copy link
Contributor Author

aysiu commented Feb 10, 2025

Actually, I think the fix has to be slightly more complicated than what I've proposed here. If you blow out the entire /opt/homebrew dir, that actually deletes all the homebrew-installed stuff as well. Will have to look into this more...

@aysiu
Copy link
Contributor Author

aysiu commented Feb 10, 2025

Very odd. I don't see why it wouldn't update. The package seems to deliver the new payload, which should overwrite the old payload. The postinstall script in the package does seem cleanup, but it shouldn't prevent the version reported from updating...

@aysiu
Copy link
Contributor Author

aysiu commented Feb 10, 2025

Filed an issue with brew: Homebrew/brew#19287

@nstrauss
Copy link
Contributor

@aysiu Played around with this and think I have a solution. The Homebrew installer and supporting commands are heavily entrenched in git. Best I can tell /opt/.git and /opt/homebrew/Library/Homebrew aren't being updated by the package as they should be. If it were done with brew upgrade I assume the version would be updated accurately. Definitely a bug. Thanks for opening the issue. Workaround for now...

#!/bin/zsh

if [[ $(uname -m) == "x86_64" ]]; then
  brew_dir="/usr/local/Homebrew"
else
  brew_dir="/opt/homebrew"
fi

if [[ -d "$brew_dir" ]]; then
  /bin/rm -rf "$brew_dir/.git"
  /bin/rm -rf "$brew_dir/Library/Homebrew"
fi

If I only remove .git and install the latest package, brew --version is correct but I get the error...

Warning: You have uncommitted modifications to Homebrew/brew.
If this is a surprise to you, then you should stash these modifications.
Stashing returns Homebrew to a pristine state but can be undone
should you later need to do so for some reason.
  cd /opt/homebrew && git stash -u && git clean -d -f

Uncommitted files:
  ?? Library/Homebrew/test/support/fixtures/bottles/testball_bottle-0.1.aarch64_linux.bottle.tar.gz

Which clued me into the diff at $brew_dir/Library/Homebrew being location of Homebrew's own formula. Delete both and brew chugs on happy as ever. Please test yourself and see if it works as I described. If so, append the PR and I'll merge. Thanks.

@aysiu
Copy link
Contributor Author

aysiu commented Feb 11, 2025

Great find, @nstrauss !

Yean, that tracks with my testing:

> sudo installer -pkg ~/Downloads/Homebrew-4.4.17.pkg -target /
installer: Package name is Homebrew
installer: Upgrading at base path /
installer: The upgrade was successful.
> /opt/homebrew/bin/brew --version
Homebrew 4.4.17
> sudo /bin/rm -rf /opt/homebrew/.git
> sudo /bin/rm -rf /opt/homebrew/Library/Homebrew 
> sudo installer -pkg ~/Downloads/Homebrew-4.4.20.pkg -target /
installer: Package name is Homebrew
installer: Upgrading at base path /
installer: The upgrade was successful.
> /opt/homebrew/bin/brew --version            
Homebrew 4.4.20

@aysiu aysiu changed the title Have Homebrew Munki recipe delete old Homebrew subdir first For cleaner upgrade, have Homebrew .munki recipe delete old Homebrew subdirs first Feb 11, 2025
@aysiu
Copy link
Contributor Author

aysiu commented Feb 11, 2025

@nstrauss I think this commit should do it. Let me know what you think.

@nstrauss nstrauss merged commit 08e25a1 into autopkg:master Feb 11, 2025
@aysiu aysiu deleted the patch-1 branch February 11, 2025 17:36
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.

2 participants