Skip to content

Instantly share code, notes, and snippets.

@amadden80
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save amadden80/2acf28ef193261602650 to your computer and use it in GitHub Desktop.

Select an option

Save amadden80/2acf28ef193261602650 to your computer and use it in GitHub Desktop.
Dev-Environment
#!/usr/bin/env bash
while getopts "vf" FLAG; do
case $FLAG in
f ) FORCE=true;;
v ) VERBOSE=true;;
? ) exit 2;;
esac
done
BELOVED_RUBY_VERSION="2.2.2"
#philco's function to stop the script from executing until enter is pressed
function pause_awhile () {
echo ""
read -p "${BG_YELLOW}>>>> $*. Press <Enter> to continue.${RESET}"
}
echo "checking os x version and installing updates, repairing permissions (this may take some time...)"
os_version=$(sw_vers -productVersion)
# Check for recommended software updates
sudo softwareupdate -i -r --ignore iTunes
# Ensure user has full control over their folder
sudo chown -R ${USER} ~
# Repair disk permission
diskutil repairPermissions /
#####ensure commandlinetools are installed
echo "checking for commmand line tools"
# Check that command line tools are installed
case $os_version in
*10.10*) cmdline_version="CLTools_Executables" ;; # Yosemite
*10.9*) cmdline_version="CLTools_Executables" ;; # Mavericks
*10.8*) cmdline_version="DeveloperToolsCLI" ;; # Mountain Lion
*10.7*) cmdline_version="DeveloperToolsCLI" ;; # Lion
*10.6*) cmdline_version="DeveloperToolsCLILeo"
warn "Outdated OS. Considering upgrading before continuing.";; # Snow Leopard
# Force the user to upgrade if they're below 10.6
*) warn "Sorry! You'll have to upgrade your OS to $MINIMUM_OS or above."; exit 1;;
esac
# Check for Command Line Tools based on OS versions
if [ ! -z $(pkgutil --pkgs=com.apple.pkg.$cmdline_version) ]; then
inform "Command Line Tools are installed!";
elif [[ $os_version == *10.6** ]]; then
warn "Command Line Tools are not installed"
warn "Downloading and installing the GCC compiler."
warn "When you're done rerun this script"
curl -OLk https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.6.pkg
open GCC-10.6.pkg
exit 1
elif [[ $os_version == *10.7* ]] || [[ $os_version == *10.8* ]]; then
warn "Command Line Tools are not installed"
warn "Register for a Developer Account"
warn "Download the Command Lion Tools from"
warn "https://developer.apple.com/downloads/index.action"
warn "Then rerun this script"
exit 1 # TODO (phlco) maybe just type 'done' instead of rerunning?
else
warn "Command Line Tools are not installed!"
# echo "run '$ sudo xcodebuild -license' then"
# echo "'$ xcode-select --install'"
# echo "Then rerun this script."
warn "Running 'xcode-select --install' Please click continue!"
warn "After installing please rerun the installfest script."
xcode-select --install
exit 1 # TODO (phlco) maybe just type 'done' instead of rerunning?
fi
###blow up rvm
echo "uninstalling RVM ruby version manager, if it exists"
# uninstall rvm, so that we can use rbenv
# http://stackoverflow.com/questions/3950260/howto-uninstall-rvm
if hash rvm 2>/dev/null || [ -d ~/.rvm ]; then
yes | rvm implode
rm -rf ~/.rvm
fi
##GRAB ssh keys, but echo user input to user so they confirm the info entered is correct
echo ""
echo "If you haven't already, please sign up for a github account"
#read to capture user input, saved as a variable as the third argument here
read -p "First Name: " fname
read -p "Last Name: " lname
read -p "Github Username (CASE SENSITIVE AND DON'T CHANGE THIS LATER): " github_name
read -p "Github Email: " github_email
read -s -p "Github Password: " github_password
echo "please confirm that your github username and email are correct. you entered the email: $github_email and the username: $github_name. Is this right? enter 'y' or 'n' "
read -p "y/n" answer
if [ $answer == "y" ] ; then
echo "great!"
pause_awhile "Generate an SSH key. When you see the prompt 'Enter a file in which to save the key', just press Enter! Your passphrase can be anything that's memorable."
#from GH docs, pass GH email captured earlier.
ssh-keygen -t rsa -C $github_email
#start ssh-agent if it's not running (TODO maybe take this out)
eval "$(ssh-agent -s)"
#add the key
ssh-add ~/.ssh/id_rsa
#set another variable called public key
public_key=$(cat ~/.ssh/id_rsa.pub)
# Upload to github
# -H flag for headers, -d for data, like form data (body of a post request), -u to specify user and password for server auth
curl https://api.github.com/user/keys \
-H "User-Agent: WDI Installfest" \
-H "Accept: application/vnd.github.v3+json" \
-u "$github_name:$github_password" \
-d '{"title":"WDI", "key":"'"$public_key"'"}'
git config --global user.name "$fname $lname"
git config --global user.email "$github_email"
git config --global user.username "$github_name"
echo ""
echo "All set! Thanks!"
else
echo "got it. re-run the script, lol!"
fi
#check to see if homebrew is installed, install it if not
$(which -s brew)
if [[ $? != 0 ]]; then
echo 'Installing Homebrew...'
# piping echo to simulate hitting return in the brew install script
echo | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
fi
echo "upgrading and installing package management and any related packages"
#update homebrew
brew update
# Version Control
brew install git
# additional git commands
brew install hub
# Upgrade any already-installed formulae
brew upgrade
# These formulae duplicate software provided by OS X
# though may provide more recent or bugfix versions.
brew tap homebrew/dupes
# Tap a new formula repository from GitHub, or list existing taps.
brew tap homebrew/versions
# Ensures all tapped formula are symlinked into Library/Formula
# and prunes dead formula from Library/Formula.
brew tap --repair
# Remove outdated versions from the cellar
brew cleanup
git_completion_url=https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o ~/.git-completion.bash $git_completion_url
# Add user's github info to gitconfig
# https://www.kernel.org/pub/software/scm/git/docs/git-config.html
echo "configuring git to look presentable"
git config --global user.name "$fname $lname"
git config --global user.github $github_name
git config --global user.email $github_email
# set colors
git config --global color.ui always
git config --global color.branch.current "green reverse"
git config --global color.branch.local green
git config --global color.branch.remote yellow
git config --global color.status.added green
git config --global color.status.changed yellow
git config --global color.status.untracked red
# set editor
# change to `subl -w` if you want to open merge messages in Sublime.
#should open now in sublime
git config --global core.editor "subl -w"
echo "installing rbenv for Ruby version management"
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
# Add to bash_profile
echo '# added by installfest script' >> ~/.bash_profile
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
# enable shims and autocompletion
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
# brew install rbenv-gem-rehash
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
# Automatically install gems every time you install a new version of Ruby
# brew install rbenv-default-gems
git clone https://github.com/sstephenson/rbenv-default-gems.git ~/.rbenv/plugins/rbenv-default-gems
# # Provides an `rbenv install` command
# # ruby-build is a dependency of rbenv-default-gems, so it gets installed
# brew install ruby-build
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install $BELOVED_RUBY_VERSION
#set global version of ruby to the beloved version (2.2.2 on 6/11/15)
# Our gems to install
# skip documentation
echo "gem: --no-ri --no-rdoc" > ~/.gemrc
touch ~/.rbenv/default-gems
gemlist=(
bundler # Maintains a consistent environment for ruby applications.
rails # full stack, Web application framework
sinatra # Lite web application framework
github_api # Ruby interface to github API v3
)
for gem in ${gemlist[@]}; do
echo "${gem}" >> ~/.rbenv/default-gems
done
rbenv global 2.2.2
rbenv rehash
source ~/.bash_profile
####Install Node
brew install node
####Install Homebrew Cask
brew tap phinze/homebrew-cask
brew install phinze/brew-cask
brew cask install spectacle
###Install Sublime-Text & Atom
brew cask install sublime-text
brew cask install atom
###Install Google Chrome
brew cask install google-chrome
echo "yay we're done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment