Skip to content

Instantly share code, notes, and snippets.

@GeriYatola
Forked from jpawlowski/brew-sync.sh
Last active December 20, 2021 08:57
Show Gist options
  • Save GeriYatola/859545e04ed42a4058f17235ebddb612 to your computer and use it in GitHub Desktop.
Save GeriYatola/859545e04ed42a4058f17235ebddb612 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"
DROPBOX_FOLDER=~/dropbox/.configs/Homebrew
BREWFILE="${DROPBOX_FOLDER}/Brewfile"
BREWFILE_TMP="/tmp/Brewfile"
# first dump local Homebrew bundle
echo "Bundling local Homebrew dependencies ..."
rm -f ${BREWFILE_TMP}
${BREW} bundle dump --file=${BREWFILE_TMP}
# then combine it with Brewfile in Dropbox
if [ -f "${BREWFILE}" ]
then
echo "Combining with Brewfile from Dropbox ..."
cat ${BREWFILE} >> ${BREWFILE_TMP}
else
echo
read -p "No Brewfile found in Dropbox ... Continue anyway? " -n 1 -r
echo
if [[ ! ${REPLY} =~ ^[Yy]$ ]]
then
[[ "$0" = "${BASH_SOURCE}" ]] && exit 1 || return 1
fi
fi
# make the Brewfile unique and sync into Dropbox
echo "Syncing to Dropbox ..."
mkdir -p "${DROPBOX_FOLDER}"
cat ${BREWFILE_TMP} | sort | uniq > ${BREWFILE}
echo "Checking dependencies ..."
if ${BREW} bundle check --quiet --file=${BREWFILE}
then
echo "Done!"
else
echo "Updating dependencies ... "
${BREW} bundle install --quiet --file=${BREWFILE}
echo "Done!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment