forked from necolas/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbrew
62 lines (52 loc) · 1.74 KB
/
brew
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
#!/bin/bash
run_brew() {
# Check for Homebrew
if type_exists 'brew'; then
e_header "Updating Homebrew..."
# Use the latest version of Homebrew
brew update
[[ $? ]] && e_success "Done"
e_header "Updating any existing Homebrew formulae..."
# Upgrade any already-installed formulae
brew upgrade
[[ $? ]] && e_success "Done"
e_header "Checking status of desired Homebrew formulae..."
local list_formulae
local -a missing_formulae
local -a desired_formulae=(
'coreutils' # GNU core utilities (those that come with OS X are outdated)
'git'
'ack'
'bash-completion'
'jpeg'
'node'
'optipng'
'phantomjs'
'tree'
'wget'
'hub'
)
for index in ${!desired_formulae[*]}
do
if ! formula_exists ${desired_formulae[$index]}; then
# Store the name (and options) of every missing formula
missing_formulae=("${missing_formulae[@]}" "${desired_formulae[$index]}")
fi
done
if [[ "$missing_formulae" ]]; then
# Convert the array of missing formula into a list of space-separate strings
list_formulae=$( printf "%s " "${missing_formulae[@]}" )
e_header "Installing missing Homebrew formulae..."
# Install all missing formulae
brew install $list_formulae
[[ $? ]] && e_success "Done"
fi
# Remove outdated versions from the Cellar
brew cleanup
else
printf "\n"
e_error "Error: Homebrew not found."
printf "Aborting...\n"
exit
fi
}