-
-
Save GeriYatola/859545e04ed42a4058f17235ebddb612 to your computer and use it in GitHub Desktop.
Sync Homebrew installations between Macs via Dropbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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