Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

homebrew: programmatically replicate an installation?

Tags:

macos

homebrew

I would like to replicate my macos brew configuration to several machines.

Is there a way to programmatically inspect brew's state or have it generate a set of commands to synchronize state with another machine?

update: There doesn't seem to be anything, so I put together a quick package that does this. It's working well for me so far.

https://github.com/marhar/brewmaster
like image 907
Mark Harrison Avatar asked Nov 18 '15 19:11

Mark Harrison


People also ask

How do I install a Homebrew package?

Homebrew installs packages to their own directory and then symlinks their files into /usr/local. Homebrew won’t install files outside its prefix and you can place a Homebrew installation wherever you like. Trivially create your own Homebrew packages.

What is homebrew and how does it work?

What Does Homebrew Do? Homebrew installs the stuff you need that Apple (or your Linux system) didn’t. Homebrew installs packages to their own directory and then symlinks their files into /usr/local. Homebrew won’t install files outside its prefix and you can place a Homebrew installation wherever you like.

How do I deploy a replica set in production?

Before you can deploy a replica set, you must install MongoDB on each system that will be part of your replica set . If you have not already installed MongoDB, see the installation tutorials. In production, deploy each member of the replica set to its own machine and if possible bind to the standard MongoDB port of 27017.

What does Wget homebrew install on Mac?

Homebrew installs the stuff you need that Apple (or your Linux system) didn’t. $ brew install wget Homebrew installs packages to their own directory and then symlinks their files into /usr/local.


1 Answers

Good question!!!!

Not sure if there is a "correct" way to do this but it is something I wanted to do as well to keep my laptop's Homebrew in sync with my desktop. I started writing something with a view to having an export settings command and an import settings command and to save the settings in Dropbox between the two machines.

I can list all the installed packages and iterate through them and then get the options that were used to install each particular package - I used JSON output and the jq home-brew package to parse the options.

I then ran into issues...

1) When you go to install on the second machine, there are dependencies and sometimes home-brew installs a dependency for you, but it installs it with the default options unless you install it first with the correct options. One way around this would be to forcibly reinstall things from your list of packages with the options even if they had already been installed in their default state as a result of installing a previous package.

2) The second issue is pinned packages that are pinned at a certain version. That started to blow my mind and I gave up as I am not THAT worried about differing setups on my laptop.

FWIW, here are the bones of the code I started writing - it is incomplete and may be wrong but ten again it may get the ball rolling for you, or someone else.

   first=1
   # Start output file with array so we can use map()
   echo "["                                                               >  "$f"
   # Iterate over all installed packages
   for pkg in $(brew list); do
      [ $first -ne 1 ] && echo ","                                        >> "$f"
      [ $verbose -gt 0 ] && echo Processing package: $pkg
      # Find options used for this package
      options=$(brew info --json=v1 $pkg | jq '.[].installed[0].used_options')
      echo "{\"name\":\"$pkg\",\"used_options\":$options}"                >> "$f"
      first=0
   done
   # Close array in output file
   echo "]"                                                               >> "$f"

A useful piece of information is that there is a parseable file called "INSTALL_RECEIPT.json" in each installed package that tells you lots of useful stuff...

find /usr/local -name "INSTALL_RECEIPT*"

Here are a couple of other fragments that I was using to parse them

# List package names
#jq -r '.packages[] | .["package-name"]' < *json

# List options for package "imagemagick"
#jq -r '.packages[] | select(."package-name"=="imagemagick") | .options[]' < *json
like image 167
Mark Setchell Avatar answered Nov 15 '22 04:11

Mark Setchell