-
Notifications
You must be signed in to change notification settings - Fork 1
/
brew-sync.sh
executable file
·68 lines (57 loc) · 2.17 KB
/
brew-sync.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Built from https://gist.github.com/jpawlowski/5248465
# Sync Homebrew installations between Macs via Dropbox
BREW="/usr/local/bin/brew"
CASK="$BREW cask"
# 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
echo "Get casks too..."
$CASK list > /tmp/brew-cask-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
[ -e ~/Dropbox/Apps/Homebrew/brew-cask-sync.installed ] && cat ~/Dropbox/Apps/Homebrew/brew-cask-sync.installed >> /tmp/brew-cask-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
cat /tmp/brew-cask-sync.installed | sort | uniq > ~/Dropbox/Apps/Homebrew/brew-cask-sync.installed
# Update brew
echo "Update brew, brew-cask"
brew update && brew upgrade brew-cask && brew cleanup
# 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
BREW_LIST=`brew list`
echo "Install missing brew packages..."
for PACKAGE in `cat ~/Dropbox/Apps/Homebrew/brew-sync.installed`; do
echo "Checking ${PACKAGE}..."
grep -q ${PACKAGE} <<< $BREW_LIST >/dev/null #Here string, who knew
if [ "$?" != "0" ]; then
echo " INSTALLING"
$BREW install ${PACKAGE}
else
echo " NOPE"
fi
done
# Install missing Homebrew Casks
CASK_LIST=`brew cask list`
echo "Install missing brew casks..."
for PACKAGE in `cat ~/Dropbox/Apps/Homebrew/brew-cask-sync.installed`; do
echo "Checking ${PACKAGE}..."
grep -q ${PACKAGE} <<< $CASK_LIST >/dev/null
if [ "$?" != "0" ]; then
echo " INSTALLING"
$CASK install ${PACKAGE}
else
echo " NOPE"
fi
done