-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathmac
196 lines (153 loc) · 4.36 KB
/
mac
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
# Welcome to the monfresh laptop script!
# Be prepared to turn your laptop (or desktop)
# into an awesome development machine.
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
append_to_file() {
local file="$1"
local text="$2"
if [ "$file" = "$HOME/.zshrc" ]; then
if [ -w "$HOME/.zshrc.local" ]; then
file="$HOME/.zshrc.local"
else
file="$HOME/.zshrc"
fi
fi
if ! grep -Fqs "$text" "$file"; then
printf "\n%s\n" "$text" >> "$file"
fi
}
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
set -e
if [ ! -d "$HOME/.bin/" ]; then
mkdir "$HOME/.bin"
fi
if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi
# shellcheck disable=SC2016
append_to_file "$HOME/.zshrc" 'export PATH="$HOME/.bin:$PATH"'
case "$SHELL" in
*/zsh) : ;;
*)
fancy_echo "Changing your shell to zsh ..."
chsh -s "$(which zsh)"
;;
esac
brew_install_or_upgrade() {
if brew_is_installed "$1"; then
if brew_is_upgradable "$1"; then
fancy_echo "Upgrading %s ..." "$1"
brew upgrade "$@"
else
fancy_echo "Already using the latest version of %s. Skipping ..." "$1"
fi
else
fancy_echo "Installing %s ..." "$1"
brew install "$@"
fi
}
brew_is_installed() {
brew list -1 | grep -Fqx "$1"
}
brew_is_upgradable() {
! brew outdated --quiet "$1" >/dev/null
}
brew_tap_is_installed() {
brew tap | grep -Fqx "$1"
}
brew_tap() {
if ! brew_tap_is_installed "$1"; then
fancy_echo "Tapping $1..."
brew tap "$1" 2> /dev/null
fi
}
gem_install_or_update() {
if gem list "$1" --installed > /dev/null; then
fancy_echo "Updating %s ..." "$1"
gem update "$@"
else
fancy_echo "Installing %s ..." "$1"
gem install "$@"
fi
}
brew_cask_expand_alias() {
brew cask info "$1" 2>/dev/null | head -1 | awk '{gsub(/:/, ""); print $1}'
}
brew_cask_is_installed() {
local NAME=$(brew_cask_expand_alias "$1")
brew cask list -1 | grep -Fqx "$NAME"
}
app_is_installed() {
local app_name=$(echo "$1" | cut -d'-' -f1)
find /Applications -iname "$app_name*" -maxdepth 1 | egrep '.*' > /dev/null
}
brew_cask_install() {
if app_is_installed "$1" || brew_cask_is_installed "$1"; then
fancy_echo "$1 is already installed. Skipping..."
else
fancy_echo "Installing $1..."
brew cask install "$@"
fi
}
if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew ..."
curl -fsS \
'https://raw.githubusercontent.com/Homebrew/install/master/install' | ruby
# shellcheck disable=SC2016
append_to_file "$HOME/.zshrc" 'export PATH="/usr/local/bin:$PATH"'
else
fancy_echo "Homebrew already installed. Skipping ..."
fi
fancy_echo "Updating Homebrew formulas ..."
brew update
brew_install_or_upgrade 'git'
brew_tap 'gapple/services'
brew_install_or_upgrade 'postgresql'
fancy_echo 'Restarting postgres...'
brew services restart postgresql
brew_install_or_upgrade 'qt'
brew_install_or_upgrade 'hub'
# shellcheck disable=SC2016
append_to_file "$HOME/.zshrc" 'eval "$(hub alias -s)"'
append_to_file "$HOME/.gemrc" 'gem: --no-document'
if ! command -v rbenv >/dev/null; then
if ! command -v rvm >/dev/null; then
fancy_echo 'Installing RVM and the latest Ruby...'
curl -L https://get.rvm.io | bash -s stable --ruby --auto-dotfiles --autolibs=enable
. ~/.rvm/scripts/rvm
else
local_version="$(rvm -v 2> /dev/null | awk '$2 != ""{print $2}')"
latest_version="$(curl -s https://raw.githubusercontent.com/wayneeseguin/rvm/stable/VERSION)"
if [ "$local_version" != "$latest_version" ]; then
fancy_echo 'Upgrading RVM...'
rvm get stable --auto-dotfiles --autolibs=enable
else
fancy_echo "Already using the latest version of RVM. Skipping..."
fi
fi
fi
fancy_echo 'Updating Rubygems...'
gem update --system
gem_install_or_update 'bundler'
fancy_echo "Configuring Bundler ..."
number_of_cores=$(sysctl -n hw.ncpu)
bundle config --global jobs $((number_of_cores - 1))
brew_install_or_upgrade 'heroku-toolbelt'
brew_tap 'caskroom/cask'
brew_install_or_upgrade 'brew-cask'
brew_tap 'caskroom/versions'
brew_cask_install 'flux'
brew_cask_install 'github'
brew_cask_install 'sublime-text3'
if [ -f "$HOME/.laptop.local" ]; then
. "$HOME/.laptop.local"
fi
append_to_file "$HOME/.rvmrc" 'rvm_auto_reload_flag=2'
if [ ! -f "$HOME/.ssh/github_rsa.pub" ]; then
open ~/Applications/GitHub.app
fi