Last active
October 4, 2016 05:31
-
-
Save revans/5673581 to your computer and use it in GitHub Desktop.
OSX Installer of Homebrew, Rbenv, various homebrew libraries, rbenv plugins, gems, and ruby 1.9.3
This file contains hidden or 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
#!/usr/bin/env bash | |
# | |
# Homebrew & Ruby setup for OSX | |
# | |
set -e | |
# Setup some array's | |
declare -a brew_libs=(apple-gcc42 openssl readline zlib libxml2 libyaml librsvg libiconv git curl solr wget redis sqlite memcached ack phantomjs mysql node) | |
declare -a rbenv_plugins=(ruby-build rbenv-vars rbenv-default-gems rbenv-gem-rehash) | |
install_homebrew() { | |
echo "==> Installing Homebrew..." | |
if ! which brew > /dev/null; then | |
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)" | |
fi | |
} | |
install_homebrew_libraries() { | |
echo "==> Installing Homebrew Libraries..." | |
for lib in "${brew_libs[@]}" | |
do | |
echo "===> Installing ${lib}..." | |
brew install $lib | |
done | |
echo "===> Installing Imagemagick..." | |
brew install imagemagick --use-rsvg | |
} | |
postgresql_setup() { | |
echo "==> Installing & lauching/relaunching PostgreSQL..." | |
if ! which psql > /dev/null; then | |
brew install postgres --no-python | |
initdb /usr/local/var/postgres -E utf8 # only if it's a new install | |
fi | |
launchctl unload $HOME/Library/LaunchAgents/homebrew.mxcl.postgresql.plist | |
launchctl load $HOME/Library/LaunchAgents/homebrew.mxcl.postgresql.plist | |
} | |
install_rbenv() { | |
echo "==> Installing rbenv to $HOME/.rbenv..." | |
git clone git://github.com/sstephenson/rbenv.git $HOME/.rbenv | |
echo "===> Adding Rbenv specific configuration to the end of your Shell's profile..." | |
# Using bash? | |
# write rbenv configuration to the .bash_profile | |
if [ -f $HOME/.bash_profile ]; then | |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.bash_profile | |
echo 'eval "$(rbenv init -)"' >> $HOME/.bash_profile | |
fi | |
# Using ZSH? | |
# write rbenv configuration to the .zshrc | |
if [ -f $HOME/.zshrc ]; then | |
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $HOME/.zshrc | |
echo 'eval "$(rbenv init -)"' >> $HOME/.zshrc | |
fi | |
# restart the shell | |
exec $SHELL -l | |
} | |
install_rbenv_plugins() { | |
url=git://github.com/sstephenson | |
rbenv_plugin_home=$HOME/.rbenv/plugins | |
echo "==> Installing Rbenv plugins..." | |
for plugin in "${rbenv_plugins[@]}" | |
do | |
if [ -d $rbenv_plugin_home/$plugin ]; then | |
echo "===> Updating ${rbenv_plugin_home}/${plugin}" | |
cd $rbenv_plugin_home/$plugin & git pull & cd - | |
else | |
echo "===> Installing ${plugin} to ${rbenv_plugin_home}/${plugin}" | |
git clone $url/$plugin.git $rbenv_plugin_home/$plugin | |
fi | |
done | |
} | |
install_ruby_versions() { | |
version=1.9.3-p429 | |
if [[ ! -d $HOME/.rbenv/versions/$version ]]; then | |
echo "==> Installing Ruby version ${version}..." | |
rbenv install $version | |
rbenv rehash | |
rbenv global $version | |
fi | |
# update rubygems regardless | |
echo "==> Updating RubyGems..." | |
gem update --system | |
} | |
# write some default gems to the rbenv default list so they can be installed | |
# with every new ruby the user installs | |
setup_default_gems() { | |
default_gem_home=$HOME/.rbenv/default-gems | |
declare -a gems=('bundler --pre' 'minitest' 'foreman' 'powder' 'pry' 'rails' 'sinatra' 'vagrant'); | |
touch $default_gem_home | |
for g in "${gems[@]}" | |
do | |
grep -w "${g}" $default_gem_home >/dev/null | |
if [ $? -eq 1 ]; then | |
echo "==> Adding ${g} to ${default_gem_home}" | |
echo "${g}" >> $default_gem_home | |
fi | |
done | |
} | |
# install/upgrade pow | |
install_server() { | |
curl get.pow.cx | sh | |
} | |
################################################# | |
# Get this started | |
# Ask some starting questions | |
echo I am going to download and install the following libraries: | |
echo "* Homebrew" | |
echo "* Rbenv" | |
echo "* Mysql" | |
echo "* PostgreSQL" | |
echo "* SQLite" | |
echo "* Redis" | |
echo "* Solr" | |
echo "* Git" | |
echo "* Memcached" | |
echo "* PhantomJS" | |
echo "* Node.js" | |
read -p "---> Are you OK with this? (y/n) " answer | |
if [ "x${answer}" = xY ] || [ "x${answer}" = xy ]; then | |
if ! which brew > /dev/null; then | |
echo | |
echo You do not have Homebrew, a package manager for OSX, on your system | |
echo I am going to install it at /usr/local directory | |
echo | |
echo You can read more about Homebrew here: http://mxcl.github.com/homebrew/ | |
install_homebrew | |
install_homebrew_libraries | |
else | |
echo "==> I am going to see if your version of | |
Homebrew needs an upgrade..." | |
brew update | |
echo | |
echo "==> Going to see if any of your homebrew | |
packages need an upgrade..." | |
brew upgrade | |
fi | |
# RBENV | |
if ! which rbenv > /dev/null; then | |
echo I am going to install Rbenv, a Ruby manager, onto your system | |
echo It will be installed at ~/.rbenv, in your local home directory. | |
echo | |
echo You can read more about rbenv here: https://github.com/sstephenson/rbenv/ | |
install_rbenv | |
else | |
echo "==> I am going to see if your rbenv version needs an upgrade..." | |
cd $HOME/.rbenv && git pull && cd plugins/ruby-build && git pull && cd - | |
fi | |
install_rbenv_plugins | |
install_ruby_versions | |
setup_default_gems | |
postgresql_setup | |
install_server | |
else | |
echo | |
echo Without Homebrew, I cannot proceed. | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment