Skip to content

Instantly share code, notes, and snippets.

@mudont
Forked from jamiew/brew-sync.sh
Last active January 30, 2022 03:21
Show Gist options
  • Save mudont/c17139c7fe4852a82b46985fa9b2643d to your computer and use it in GitHub Desktop.
Save mudont/c17139c7fe4852a82b46985fa9b2643d to your computer and use it in GitHub Desktop.
Sync Homebrew installations between Macs via Dropbox (including casks)
#!/bin/bash
# Sync Homebrew installations between Macs via Dropbox
#
BREW="/usr/local/bin/brew"
CLOUD_SYNC_DIR=~/iCloud/Apps/Homebrew
# 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 $CLOUD_SYNC_DIR/brew-sync.taps ] && cat $CLOUD_SYNC_DIR/brew-sync.taps >> /tmp/brew-sync.taps
[ -e $CLOUD_SYNC_DIR/brew-sync.installed ] && cat $CLOUD_SYNC_DIR/brew-sync.installed >> /tmp/brew-sync.installed
[ -e $CLOUD_SYNC_DIR/brew-sync.casks ] && cat $CLOUD_SYNC_DIR/brew-sync.casks >> /tmp/brew-sync.casks
# make the lists unique and sync into Dropbox
echo "Syncing to Dropbox ..."
mkdir -p $CLOUD_SYNC_DIR
cat /tmp/brew-sync.taps | sort | uniq > $CLOUD_SYNC_DIR/brew-sync.taps
cat /tmp/brew-sync.installed | sort | uniq > $CLOUD_SYNC_DIR/brew-sync.installed
cat /tmp/brew-sync.casks | sort | uniq > $CLOUD_SYNC_DIR/brew-sync.casks
# Set taps
echo "Enabling taps ..."
for TAP in `cat $CLOUD_SYNC_DIR/brew-sync.taps`; do
$BREW tap ${TAP} >/dev/null
done
# Install missing Homebrew packages
echo "Install missing packages ..."
for PACKAGE in `cat $CLOUD_SYNC_DIR/brew-sync.installed`; do
$BREW list ${PACKAGE} >/dev/null
[ "$?" != "0" ] && $BREW install ${PACKAGE}
done
echo "Install missing casks ..."
for CASK in `cat $CLOUD_SYNC_DIR/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