-
-
Save jpawlowski/5248465 to your computer and use it in GitHub Desktop.
| #!/bin/bash | |
| # Sync Homebrew installations between Macs via Dropbox | |
| # | |
| BREW="/usr/local/bin/brew" | |
| # first get local settings | |
| echo "Reading local settings ..." | |
| rm -f /tmp/brew-sync.* | |
| $BREW tap > /tmp/brew-sync.taps | |
| $BREW list > /tmp/brew-sync.installed | |
| # then combine it with list in Dropbox | |
| echo "Reading settings from Dropbox ..." | |
| [ -e ~/Dropbox/Apps/Homebrew/brew-sync.taps ] && cat ~/Dropbox/Apps/Homebrew/brew-sync.taps >> /tmp/brew-sync.taps | |
| [ -e ~/Dropbox/Apps/Homebrew/brew-sync.installed ] && cat ~/Dropbox/Apps/Homebrew/brew-sync.installed >> /tmp/brew-sync.installed | |
| # make the lists unique and sync into Dropbox | |
| echo "Syncing to Dropbox ..." | |
| mkdir -p ~/Dropbox/Apps/Homebrew | |
| cat /tmp/brew-sync.taps | sort | uniq > ~/Dropbox/Apps/Homebrew/brew-sync.taps | |
| cat /tmp/brew-sync.installed | sort | uniq > ~/Dropbox/Apps/Homebrew/brew-sync.installed | |
| # Set taps | |
| echo "Enabling taps ..." | |
| for TAP in `cat ~/Dropbox/Apps/Homebrew/brew-sync.taps`; do | |
| $BREW tap ${TAP} >/dev/null | |
| done | |
| # Install missing Homebrew packages | |
| echo "Install missing packages ..." | |
| for PACKAGE in `cat ~/Dropbox/Apps/Homebrew/brew-sync.installed`; do | |
| $BREW list ${PACKAGE} >/dev/null | |
| [ "$?" != "0" ] && $BREW install ${PACKAGE} | |
| done |
Sorry for the ignorance, but will this sync both ways? Should I do something in preparation? I understand ghis is a one-time sync, right?
I'm looking at a way to keep my 2 macs as "identical as possible"... this involves shared document folders, as well as trying to get all sorts of apps synced... not a trivial chore it seems...
Very helpful. I forked @witt3rd's gist and added brew update so that the cask file is not filled with update/migration messages, along with changing the directory where the items are stored.
Enabling taps ...
Updating Homebrew...
Error: Invalid tap name '==>'
Updating Homebrew...
Error: Invalid tap name 'Auto-updated'
Updating Homebrew...
Error: Invalid tap name 'Homebrew!'
Error: Invalid tap name '==>'
Error: Invalid tap name 'Deleted'
Error: Invalid tap name 'Formulae'
Error: Invalid tap name '==>'
Error: Invalid tap name 'Updated'
Error: Invalid tap name 'Formulae'
Error: Invalid tap name 'Updated'
Error: Invalid tap name '1'
Error: Invalid tap name 'tap'
What matter with those?
Look in to using brew bundle instead, not only does it combine taps/brews/casks into one Brewfile but it also saves the arguments the brews were installed with, for example brew install gnu-sed --with-default-names gets represented as brew "gnu-sed", args: ["with-default-names"] in the Brewfile.
This is a great little script. I added cask syncing to my fork.