Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 188 lines (145 sloc) 4.304 kb
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
1 #!/bin/sh
91048f3 @croaky Drop Linux support
croaky authored
2
3 # Welcome to the thoughtbot laptop script!
4 # Be prepared to turn your laptop (or desktop, no haters here)
5 # into an awesome development machine.
6
4e7f598 @kenyonj Re-order manifest build order
kenyonj authored
7 fancy_echo() {
350530a @croaky Be more specific in printed output
croaky authored
8 local fmt="$1"; shift
9
efd2160 @pbrisbin Setup travis build to run shellcheck
pbrisbin authored
10 # shellcheck disable=SC2059
350530a @croaky Be more specific in printed output
croaky authored
11 printf "\n$fmt\n" "$@"
4e7f598 @kenyonj Re-order manifest build order
kenyonj authored
12 }
13
14 append_to_zshrc() {
15 local text="$1" zshrc
c997c4f @pbrisbin Default $skip_new_line to 0
pbrisbin authored
16 local skip_new_line="${2:-0}"
4e7f598 @kenyonj Re-order manifest build order
kenyonj authored
17
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
18 if [ -w "$HOME/.zshrc.local" ]; then
4e7f598 @kenyonj Re-order manifest build order
kenyonj authored
19 zshrc="$HOME/.zshrc.local"
20 else
21 zshrc="$HOME/.zshrc"
22 fi
23
24 if ! grep -Fqs "$text" "$zshrc"; then
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
25 if [ "$skip_new_line" -eq 1 ]; then
3897ad8 @kenyonj Remove explicit new line addition
kenyonj authored
26 printf "%s\n" "$text" >> "$zshrc"
27 else
28 printf "\n%s\n" "$text" >> "$zshrc"
29 fi
4e7f598 @kenyonj Re-order manifest build order
kenyonj authored
30 fi
31 }
fc2143f @croaky mac is now a shell script. both mac & ubuntu now install ruby 1.9.2-p…
croaky authored
32
682323b @pbrisbin Regenerate compiled scripts
pbrisbin authored
33 trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
34
35 set -e
eb6a701 @croaky [#32] Run each command "successfully"
croaky authored
36
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
37 if [ ! -d "$HOME/.bin/" ]; then
c56f081 @thcipriani Ensure .bin directory exists in $HOME and in $PATH
thcipriani authored
38 mkdir "$HOME/.bin"
39 fi
40
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
41 if [ ! -f "$HOME/.zshrc" ]; then
8066ffa @AlJohri Add quotes around $HOME b/c path may have spaces
AlJohri authored
42 touch "$HOME/.zshrc"
f24f565 Improve idempotency in the linux laptop script
Dan Collis-Puro authored
43 fi
44
efd2160 @pbrisbin Setup travis build to run shellcheck
pbrisbin authored
45 # shellcheck disable=SC2016
3897ad8 @kenyonj Remove explicit new line addition
kenyonj authored
46 append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
c56f081 @thcipriani Ensure .bin directory exists in $HOME and in $PATH
thcipriani authored
47
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
48 case "$SHELL" in
49 */zsh) : ;;
50 *)
51 fancy_echo "Changing your shell to zsh ..."
52 chsh -s "$(which zsh)"
53 ;;
54 esac
5d749c0 @pbrisbin Remove linux-prereq script by switching to Bash
pbrisbin authored
55
3162c58 Extend and improve osx idempotency
Dan Collis-Puro authored
56 brew_install_or_upgrade() {
9807bd8 @gohanlon Test whether Homebrew formula is installed
gohanlon authored
57 if brew_is_installed "$1"; then
586b7e0 @gohanlon Don't upgrade a brew that is already up to date
gohanlon authored
58 if brew_is_upgradable "$1"; then
350530a @croaky Be more specific in printed output
croaky authored
59 fancy_echo "Upgrading %s ..." "$1"
586b7e0 @gohanlon Don't upgrade a brew that is already up to date
gohanlon authored
60 brew upgrade "$@"
350530a @croaky Be more specific in printed output
croaky authored
61 else
62 fancy_echo "Already using the latest version of %s. Skipping ..." "$1"
586b7e0 @gohanlon Don't upgrade a brew that is already up to date
gohanlon authored
63 fi
dc7a475 @chrispwood Making brew installs commands work in idempotently
chrispwood authored
64 else
350530a @croaky Be more specific in printed output
croaky authored
65 fancy_echo "Installing %s ..." "$1"
3162c58 Extend and improve osx idempotency
Dan Collis-Puro authored
66 brew install "$@"
dc7a475 @chrispwood Making brew installs commands work in idempotently
chrispwood authored
67 fi
68 }
586b7e0 @gohanlon Don't upgrade a brew that is already up to date
gohanlon authored
69
9807bd8 @gohanlon Test whether Homebrew formula is installed
gohanlon authored
70 brew_is_installed() {
af2df6d @croaky Make rbenv idempotent, install Ruby 2.1.4
croaky authored
71 local name="$(brew_expand_alias "$1")"
9807bd8 @gohanlon Test whether Homebrew formula is installed
gohanlon authored
72
af2df6d @croaky Make rbenv idempotent, install Ruby 2.1.4
croaky authored
73 brew list -1 | grep -Fqx "$name"
9807bd8 @gohanlon Test whether Homebrew formula is installed
gohanlon authored
74 }
75
586b7e0 @gohanlon Don't upgrade a brew that is already up to date
gohanlon authored
76 brew_is_upgradable() {
af2df6d @croaky Make rbenv idempotent, install Ruby 2.1.4
croaky authored
77 local name="$(brew_expand_alias "$1")"
9e566c8 @gohanlon Make brew_install_or_upgrade work with aliases
gohanlon authored
78
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
79 ! brew outdated --quiet "$name" >/dev/null
586b7e0 @gohanlon Don't upgrade a brew that is already up to date
gohanlon authored
80 }
9e566c8 @gohanlon Make brew_install_or_upgrade work with aliases
gohanlon authored
81
971bfae @AlJohri Add brew_tap function
AlJohri authored
82 brew_tap() {
83 brew tap "$1" 2> /dev/null
84 }
85
9e566c8 @gohanlon Make brew_install_or_upgrade work with aliases
gohanlon authored
86 brew_expand_alias() {
87 brew info "$1" 2>/dev/null | head -1 | awk '{gsub(/:/, ""); print $1}'
88 }
c9f1ab1 @gohanlon Add idempotent brew_launchctl_restart function
gohanlon authored
89
90 brew_launchctl_restart() {
af2df6d @croaky Make rbenv idempotent, install Ruby 2.1.4
croaky authored
91 local name="$(brew_expand_alias "$1")"
92 local domain="homebrew.mxcl.$name"
93 local plist="$domain.plist"
c9f1ab1 @gohanlon Add idempotent brew_launchctl_restart function
gohanlon authored
94
bfdd429 @croaky Restart Redis
croaky authored
95 fancy_echo "Restarting %s ..." "$1"
af2df6d @croaky Make rbenv idempotent, install Ruby 2.1.4
croaky authored
96 mkdir -p "$HOME/Library/LaunchAgents"
97 ln -sfv "/usr/local/opt/$name/$plist" "$HOME/Library/LaunchAgents"
c9f1ab1 @gohanlon Add idempotent brew_launchctl_restart function
gohanlon authored
98
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
99 if launchctl list | grep -Fq "$domain"; then
af2df6d @croaky Make rbenv idempotent, install Ruby 2.1.4
croaky authored
100 launchctl unload "$HOME/Library/LaunchAgents/$plist" >/dev/null
c9f1ab1 @gohanlon Add idempotent brew_launchctl_restart function
gohanlon authored
101 fi
af2df6d @croaky Make rbenv idempotent, install Ruby 2.1.4
croaky authored
102 launchctl load "$HOME/Library/LaunchAgents/$plist" >/dev/null
c9f1ab1 @gohanlon Add idempotent brew_launchctl_restart function
gohanlon authored
103 }
dc7a475 @chrispwood Making brew installs commands work in idempotently
chrispwood authored
104
bcf2993 @croaky Add gem_install_or_update function
croaky authored
105 gem_install_or_update() {
106 if gem list "$1" --installed > /dev/null; then
107 fancy_echo "Updating %s ..." "$1"
108 gem update "$@"
109 else
110 fancy_echo "Installing %s ..." "$1"
111 gem install "$@"
112 rbenv rehash
113 fi
114 }
115
01c0f05 @croaky Don't redirect stderr to /dev/null
croaky authored
116 if ! command -v brew >/dev/null; then
350530a @croaky Be more specific in printed output
croaky authored
117 fancy_echo "Installing Homebrew ..."
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
118 curl -fsS \
119 'https://raw.githubusercontent.com/Homebrew/install/master/install' | ruby
fbb2e9f @dayne Make Homebrew install idempotent
dayne authored
120
3897ad8 @kenyonj Remove explicit new line addition
kenyonj authored
121 append_to_zshrc '# recommended by brew doctor'
efd2160 @pbrisbin Setup travis build to run shellcheck
pbrisbin authored
122
123 # shellcheck disable=SC2016
3897ad8 @kenyonj Remove explicit new line addition
kenyonj authored
124 append_to_zshrc 'export PATH="/usr/local/bin:$PATH"' 1
efd2160 @pbrisbin Setup travis build to run shellcheck
pbrisbin authored
125
0f359ca @kenyonj Create append_to_zshrc()
kenyonj authored
126 export PATH="/usr/local/bin:$PATH"
fbb2e9f @dayne Make Homebrew install idempotent
dayne authored
127 else
128 fancy_echo "Homebrew already installed. Skipping ..."
55d9853 @croaky Fix idempotence
croaky authored
129 fi
c6a4aec @croaky Update Homebrew even if already installed
croaky authored
130
131 fancy_echo "Updating Homebrew formulas ..."
132 brew update
91d1f9a Componentize laptop
Dan Collis-Puro authored
133
ef0e998 @croaky Use Homebrew for Git
croaky authored
134 brew_install_or_upgrade 'git'
350530a @croaky Be more specific in printed output
croaky authored
135 brew_install_or_upgrade 'postgres'
bfdd429 @croaky Restart Redis
croaky authored
136 brew_launchctl_restart 'postgresql'
350530a @croaky Be more specific in printed output
croaky authored
137 brew_install_or_upgrade 'redis'
bfdd429 @croaky Restart Redis
croaky authored
138 brew_launchctl_restart 'redis'
350530a @croaky Be more specific in printed output
croaky authored
139 brew_install_or_upgrade 'the_silver_searcher'
140 brew_install_or_upgrade 'vim'
141 brew_install_or_upgrade 'ctags'
142 brew_install_or_upgrade 'tmux'
143 brew_install_or_upgrade 'reattach-to-user-namespace'
144 brew_install_or_upgrade 'imagemagick'
145 brew_install_or_upgrade 'qt'
9fe038c @seanpdoyle Revert `gh` to `hub`
seanpdoyle authored
146 brew_install_or_upgrade 'hub'
4d07ad0 @croaky Remove NVM, simplify to `brew install node`
croaky authored
147 brew_install_or_upgrade 'node'
91ca7d6 @croaky Start Postgres after it is installed
croaky authored
148
37f4575 @croaky Fix rbenv idempotence
croaky authored
149 brew_install_or_upgrade 'rbenv'
150 brew_install_or_upgrade 'ruby-build'
efd2160 @pbrisbin Setup travis build to run shellcheck
pbrisbin authored
151
37f4575 @croaky Fix rbenv idempotence
croaky authored
152 # shellcheck disable=SC2016
153 append_to_zshrc 'eval "$(rbenv init - zsh --no-rehash)"' 1
3aeb5b5 @croaky Use rbenv to change Ruby versions
croaky authored
154
350530a @croaky Be more specific in printed output
croaky authored
155 brew_install_or_upgrade 'openssl'
156 brew unlink openssl && brew link openssl --force
157 brew_install_or_upgrade 'libyaml'
91d1f9a Componentize laptop
Dan Collis-Puro authored
158
16d8692 @croaky Don't hardcode Ruby version
croaky authored
159 ruby_version="$(curl -sSL http://ruby.thoughtbot.com/latest)"
3aeb5b5 @croaky Use rbenv to change Ruby versions
croaky authored
160
cbacb37 @keith Add $HOME/.rbenv to $PATH even if it's installed
keith authored
161 eval "$(rbenv init - zsh)"
162
350530a @croaky Be more specific in printed output
croaky authored
163 if ! rbenv versions | grep -Fq "$ruby_version"; then
4ad53bc Remove ruby 2.1.1 conditional behavior for rbenv installation
Dan Collis-Puro authored
164 rbenv install -s "$ruby_version"
350530a @croaky Be more specific in printed output
croaky authored
165 fi
aae0a21 @croaky Upgrade Ruby to 2.1.0
croaky authored
166
350530a @croaky Be more specific in printed output
croaky authored
167 rbenv global "$ruby_version"
26fb8cf @croaky Use rbenv shell instead of rbenv local
croaky authored
168 rbenv shell "$ruby_version"
3aeb5b5 @croaky Use rbenv to change Ruby versions
croaky authored
169
350530a @croaky Be more specific in printed output
croaky authored
170 gem update --system
7d7b9d7 @croaky Fix install for Mountain Lion and RVM 1.16
croaky authored
171
bcf2993 @croaky Add gem_install_or_update function
croaky authored
172 gem_install_or_update 'bundler'
173
174 fancy_echo "Configuring Bundler ..."
175 number_of_cores=$(sysctl -n hw.ncpu)
176 bundle config --global jobs $((number_of_cores - 1))
8b21a94 @croaky Configure Bundler for parallel gem installs
croaky authored
177
350530a @croaky Be more specific in printed output
croaky authored
178 brew_install_or_upgrade 'heroku-toolbelt'
7d7b9d7 @croaky Fix install for Mountain Lion and RVM 1.16
croaky authored
179
01c0f05 @croaky Don't redirect stderr to /dev/null
croaky authored
180 if ! command -v rcup >/dev/null; then
971bfae @AlJohri Add brew_tap function
AlJohri authored
181 brew_tap 'thoughtbot/formulae'
350530a @croaky Be more specific in printed output
croaky authored
182 brew_install_or_upgrade 'rcm'
caeada5 @croaky Make mac script run idempotently
croaky authored
183 fi
8bae2b0 @mike-burns Add rcm
mike-burns authored
184
8034b8d @pbrisbin Remove bashisms, use /bin/sh shebang
pbrisbin authored
185 if [ -f "$HOME/.laptop.local" ]; then
186 . "$HOME/.laptop.local"
350530a @croaky Be more specific in printed output
croaky authored
187 fi
Something went wrong with that request. Please try again.