Last active
May 10, 2017 03:42
-
-
Save ppdeassis/601d9191c76337b94909 to your computer and use it in GitHub Desktop.
Installing a Ruby workstations from scratch on OS X (last used on El Capitan)
This file contains 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
#!/bin/bash | |
# | |
# \curl https://gist.githubusercontent.com/ppdeassis/601d9191c76337b94909/raw/92f4af629ee7d8d58022c4711b77e1fbd0f560e4/ruby_osx_setup.sh | bash | |
# | |
# If any command fails, we should immediately fail too | |
set -e | |
# | |
# | |
add_to_bash_profile() { | |
local line="$1" | |
if ! grep --quiet "$line" ~/.bash_profile; then | |
echo "$line" >> ~/.bash_profile | |
fi | |
} | |
brew_cask_install() { | |
local cask="$1" | |
if ! brew cask list | grep --quiet --line-regexp "$cask"; then | |
echo "Installing cask $cask" | |
brew cask install "$cask" | |
else | |
echo "Cask $cask already installed. Skipping..." | |
fi | |
} | |
brew_install() { | |
local formula="$1" | |
if ! brew list | grep --quiet --line-regexp "$formula"; then | |
echo "Installing formula $formula" | |
brew install "$formula" | |
else | |
echo "Formula $formula already installed. Skipping..." | |
fi | |
} | |
generate_ssh_keys() { | |
DIRECTORY=~/.ssh | |
KEY_PATH=~/.ssh/id_rsa | |
if [ ! -d "$DIRECTORY" ]; then | |
mkdir $DIRECTORY | |
chmod -R 0700 $DIRECTORY | |
fi | |
if [ -f "$KEY_PATH" ]; then | |
echo "SSH keys already exists, skipping..." | |
else | |
ssh-keygen -t rsa -f "$KEY_PATH" -N '' | |
fi | |
} | |
install_command_line_tools() { | |
if xcode-select -p > /dev/null; then | |
echo "Command Line Tools already installed. Skipping..." | |
else | |
# From https://github.com/rtrouton/rtrouton_scripts/blob/master/rtrouton_scripts/install_xcode_command_line_tools/install_xcode_command_line_tools.sh | |
local tmp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" | |
touch "$tmp_file" | |
# Find the last listed update in the Software Update feed with "Command Line Tools" in the name | |
local cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | tail -1 | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-) | |
echo $cmd_line_tools | |
#Install the command line tools | |
softwareupdate -i "$cmd_line_tools" -v | |
# Remove the temp file | |
if [[ -f "$tmp_file" ]]; then | |
rm "$tmp_file" | |
fi | |
# after installing, changing developer dir | |
sudo xcode-select --switch /Library/Developer/CommandLineTool | |
# agreeing to the license | |
sudo xcodebuild -license | |
fi # end installing commnad line tools | |
} | |
install_fonts() { | |
brew tap caskroom/fonts | |
brew_cask_install font-hack | |
brew_cask_install font-open-sans | |
} | |
install_homebrew() { | |
if ! command -v brew > /dev/null; then | |
echo "Installing Homebrew" | |
curl --silent \ | |
--fail \ | |
--show-error \ | |
--location \ | |
https://raw.githubusercontent.com/Homebrew/install/master/install | ruby | |
source ~/.bash_profile | |
brew doctor | |
else | |
echo "Homebrew already installed. Skipping..." | |
fi | |
} | |
install_postgres() { | |
if ! brew list | grep --quiet --line-regexp "postgresql"; then | |
brew_install postgresql | |
local pgdatadir=/usr/local/var/postgres | |
# removing brew initialized cluster | |
rm -rf $pgdatadir | |
# creating a new one, with custom encoding and locale | |
initdb --encoding=UTF-8 --locale=pt_BR.UTF-8 --lc-messages=en_US.UTF-8 --username=postgres $pgdatadir | |
# creating 'caiena' role | |
pg_ctl -D $pgdatadir start | |
# waiting for server to start | |
sleep 5 | |
psql --username=postgres --command="CREATE ROLE caiena SUPERUSER CREATEDB CREATEROLE LOGIN" | |
pg_ctl -D $pgdatadir stop | |
fi | |
} | |
install_rvm() { | |
if [ ! -d $HOME/.rvm ]; then | |
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 | |
curl -sSL https://get.rvm.io | bash -s stable --autolibs=homebrew | |
source ~/.rvm/scripts/rvm | |
rvm install ruby --latest | |
# skipping doc when installing gems | |
touch ~/.gemrc | |
local nodoc="gem: --no-ri --no-rdoc --no-document" | |
if ! grep --quiet "$nodoc" ~/.gemrc; then | |
echo "$nodoc" >> ~/.gemrc | |
fi | |
else | |
echo "rvm already installed. Skipping..." | |
fi | |
} | |
install_terminal_solarized() { | |
echo "Installing Solarized Dark color theme for Terminal.app" | |
echo " - It will open a new terminal window with the theme." | |
echo " - Feel free to close it." | |
curl -sSL https://raw.githubusercontent.com/altercation/solarized/master/osx-terminal.app-colors-solarized/Solarized%20Dark%20ansi.terminal > /tmp/"Solarized Dark.terminal" | |
open /tmp/"Solarized Dark.terminal" | |
} | |
# we expect a .bash_profile to exist | |
touch ~/.bash_profile | |
install_command_line_tools | |
install_homebrew | |
brew_install git | |
brew_install sqlite | |
brew_install imagemagick | |
brew_install bash-completion | |
# extra config needed for bash-completion to work properly | |
if ! grep --quiet "etc/bash_completion" ~/.bash_profile; then | |
cat <<-EOF >> ~/.bash_profile | |
# enabling bash-completion | |
if [ -f $(brew --prefix)/etc/bash_completion ]; then | |
source $(brew --prefix)/etc/bash_completion | |
fi | |
EOF | |
fi | |
brew_install gpg | |
install_postgres | |
brew_install phantomjs | |
brew_install caskroom/cask/brew-cask | |
brew tap caskroom/versions | |
brew_cask_install firefox | |
brew_cask_install google-chrome | |
brew_cask_install slack | |
brew_cask_install sublime-text3 | |
install_rvm | |
generate_ssh_keys | |
install_fonts | |
# adding solarized to terminal | |
install_terminal_solarized | |
# disable accentuation on key holding | |
defaults write -g ApplePressAndHoldEnabled -bool false | |
# Fast keyboard repeat rate | |
defaults write NSGlobalDomain KeyRepeat -int 2 | |
# Shorter delay until key repeat | |
# defaults write NSGlobalDomain InitialKeyRepeat -int 20 | |
# Enable inspect element in web views | |
# defaults write NSGlobalDomain WebKitDeveloperExtras -bool true | |
# Allow using tabs to cycle between prompts buttons | |
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3 | |
# Always show file extensions | |
defaults write NSGlobalDomain AppleShowAllExtensions -bool true | |
# Don't create DS_Store when connecting to network volumes | |
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true | |
# Don't always ask for using connected external drive with Timemachine | |
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true | |
# Turn off keyboard illumination when it is not touched for five minutes | |
# defaults write com.apple.BezelServices kDimTime -int 300 | |
# Disabling smart quotes substitution | |
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false | |
defaults write com.apple.TextEdit SmartQuotes -bool false | |
# Disabling smart dashes substitution | |
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false | |
defaults write com.apple.TextEdit SmartDashes -bool false | |
# Disabling autocorrect | |
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false | |
# Disabling Gatekeeper (will prompt for password) | |
sudo spctl --master-disable | |
echo "Setup complete. Enjoy! :)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment