Last active
January 4, 2023 23:05
-
-
Save djpadz/044ab74ba954aea387eaf9b3383fd1c2 to your computer and use it in GitHub Desktop.
Homebrew: make a bottle dependent-only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
import sys | |
import os | |
kvp = (("installed_as_dependency", True), ("installed_on_request", False)) | |
for i in sys.argv[1:]: | |
filename = f"/usr/local/opt/{i}/INSTALL_RECEIPT.json" | |
with open(filename, "r", encoding="utf-8") as f: | |
j = json.load(f) | |
if "installed_as_dependency" not in j or "installed_on_request" not in j: | |
raise ValueError(f"{filename} doesn't look like an INSTALL_RECEIPT") | |
print(f"{i}:") | |
old = {} | |
rewrite = False | |
for key, val in kvp: | |
print(f" {key}: {j[key]}{f' --> {val}' if j[key] != val else ''}") | |
rewrite |= j[key] != val | |
j[key] = val | |
if rewrite: | |
os.rename(filename, f"{filename}.bak") | |
with open(filename, "w", encoding="utf-8") as f: | |
f.write(json.dumps(j, indent=2)) | |
os.chmod(filename, 0o0644) | |
else: | |
print(" (no change)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a script I wrote after realizing that running
brew install <everything that was on the other machine>
breaks housekeeping features likebrew autoremove
. Use this to make a formula or cask dependency-only, setting that flag, and clearing the flag that says that you explicitly installed it.