Skip to content

Instantly share code, notes, and snippets.

@justinkiner
Forked from jpawlowski/brew-sync.sh
Last active March 12, 2024 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinkiner/08f570655ce9148d8c2ce6747a0d8073 to your computer and use it in GitHub Desktop.
Save justinkiner/08f570655ce9148d8c2ce6747a0d8073 to your computer and use it in GitHub Desktop.
Sync Homebrew installations between Macs via Dropbox
#!/bin/bash
# Sync Homebrew installations between Macs via Dropbox
#
BREW="/usr/local/bin/brew"
SYNCDIR="$HOME/Dropbox/Tools/Homebrew"
# First, update homebrew
$BREW update
# Create sync dir
mkdir -p /$SYNCDIR
# 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
$BREW cask list -1 > /tmp/brew-sync.casks
# then combine it with list in Dropbox
echo "Reading settings from Dropbox ..."
[ -e $SYNCDIR/brew-sync.taps ] && cat $SYNCDIR/brew-sync.taps >> /tmp/brew-sync.taps
[ -e $SYNCDIR/brew-sync.installed ] && cat $SYNCDIR/brew-sync.installed >> /tmp/brew-sync.installed
[ -e $SYNCDIR/brew-sync.casks ] && cat $SYNCDIR/brew-sync.casks >> /tmp/brew-sync.casks
# make the lists unique and sync into Dropbox
echo "Syncing to Dropbox ..."
cat /tmp/brew-sync.taps | sort | uniq > $SYNCDIR/brew-sync.taps
cat /tmp/brew-sync.installed | sort | uniq > $SYNCDIR/brew-sync.installed
cat /tmp/brew-sync.casks | sort | uniq > $SYNCDIR/brew-sync.casks
# Set taps
echo "Enabling taps ..."
for TAP in `cat $SYNCDIR/brew-sync.taps`; do
$BREW tap ${TAP} >/dev/null
done
# Install missing Homebrew packages
echo "Install missing packages ..."
for PACKAGE in `cat $SYNCDIR/brew-sync.installed`; do
$BREW list ${PACKAGE} >/dev/null
[ "$?" != "0" ] && $BREW install ${PACKAGE}
done
echo "Install missing casks ..."
for CASK in `cat $SYNCDIR/brew-sync.casks`; do
$BREW cask list -1 ${CASK} >/dev/null
[ "$?" != "0" ] && $BREW cask install ${CASK}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment