Created
January 12, 2016 00:24
-
-
Save avayanis/268c88495b41197ccd60 to your computer and use it in GitHub Desktop.
Bootstrap a new Mac
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 | |
# Define script directories | |
TMP="/tmp/osx_setup" | |
# Package Versions | |
NODEVERSION="0.12.5" | |
# Introduction to setup | |
echo "Preparing to setup:" | |
echo "* Adium" | |
echo "* Alfred 2" | |
echo "* Atom Text Editor" | |
echo "* Divvy" | |
echo "* Firefox" | |
echo "* Google Chrome" | |
echo "* HipChat" | |
echo "* Homebrew" | |
echo "* Homebrew taps: dupes, versions, php" | |
echo "* IntelliJ IDEA 14" | |
echo "* iTerm2" | |
echo "* KeePassX" | |
echo "* MySQL" | |
echo "* Node.js (v$NODEVERSION)" | |
echo "* Nvm (Node Version Manager)" | |
echo "* Oh My ZSH" | |
echo "* PHP 5.4, 5.5, 5.6" | |
echo "* Sequel Pro" | |
echo "* SSH Keys" | |
echo "* Sublime Text" | |
echo "* Skype" | |
echo "* VirtualBox" | |
echo "* WebStorm" | |
read -p "Press ENTER to continue or Ctrl-C to quit" | |
# Setup temp directory | |
echo "Cleaning temp directory." | |
rm -rf $TMP | |
mkdir -p $TMP | |
# Define installation functions | |
# Installs application from DMG archive. | |
# Parameters: | |
# - Application Name (As expected to be in Applications directory" | |
# - Download URL | |
# - true|false whether or not to run .pkg installer as root. | |
function install_dmg { | |
APP_NAME="$1.app" | |
APP_PKG="$1.pkg" | |
APP_URL=$2 | |
APP_TARGET="/Applications/$APP_NAME" | |
INSTALL_TARGET="$TMP/$APP_NAME.dmg" | |
INSTALL_VOLUME="/Volumes/$APP_NAME" | |
RUN_AS_ROOT=$3 | |
echo "Checking if $APP_NAME is installed." | |
if [ ! -d "$APP_TARGET" ]; then | |
echo "Downloading $APP_NAME." | |
curl -L -o "$INSTALL_TARGET" "$APP_URL" | |
echo "Mounting $APP_NAME." | |
hdiutil mount -mountpoint "$INSTALL_VOLUME" "$INSTALL_TARGET" | |
if [ ! -e "$INSTALL_VOLUME/$APP_PKG" ]; then | |
echo "Installing $APP_NAME." | |
cp -R "$INSTALL_VOLUME/$APP_NAME" "$APP_TARGET" | |
elif [ $RUN_AS_ROOT == "true" ]; then | |
sudo installer -pkg "$INSTALL_VOLUME/$APP_PKG" -target / | |
else | |
installer -pkg "$INSTALL_VOLUME/$APP_PKG" -target / | |
fi | |
echo "Unmounting $APP_NAME." | |
hdiutil unmount "$INSTALL_VOLUME" | |
fi | |
} | |
function install_zip { | |
APP_NAME="$1.app" | |
APP_URL=$2 | |
APP_TARGET="/Applications/$APP_NAME" | |
INSTALL_TARGET="$TMP/$APP_NAME.zip" | |
echo "Checking if $APP_NAME is installed." | |
if [ ! -d "$APP_TARGET" ]; then | |
echo "Downloading $APP_NAME." | |
curl -L -o "$INSTALL_TARGET" "$APP_URL" | |
echo "Installing $APP_NAME." | |
unzip "$INSTALL_TARGET" -d /Applications | |
fi | |
} | |
# Setup SSH Keys | |
echo "Checking for existing SSH keys." | |
if [ ! -e ~/.ssh/id_rsa.pub ] && [ ! -e ~/.ssh/id_dsa.pub ]; then | |
echo "Generating random passphrase." | |
SSH_PASSPHRASE=`openssl rand -base64 16` | |
read -r -p "Enter your email address (username@example.com): " email | |
echo "Generating SSH Key with the following Passphrase: $SSH_PASSPHRASE" | |
ssh-keygen -t rsa -b 4096 -C $email -P $SSH_PASSPHRASE | |
echo "Adding SSH key to ssh-agent." | |
ssh-add ~/.ssh/id_rsa | |
fi | |
# Install Homebrew | |
echo "Checking if Homebrew is installed." | |
if ! type "brew" > /dev/null; then | |
echo "Downloading and installing Homebrew." | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
fi | |
if [ ! -d /usr/local/Library/Taps/homebrew/homebrew-dupes ]; then | |
echo "Adding Homebrew tap: dupes." | |
brew tap homebrew/dupes | |
fi | |
if [ ! -d /usr/local/Library/Taps/homebrew/homebrew-versions ]; then | |
echo "Adding Homebrew tap: versions." | |
brew tap homebrew/versions | |
fi | |
if [ ! -d /usr/local/Library/Taps/homebrew/homebrew-php ]; then | |
echo "Adding Homebrew tap: php." | |
brew tap homebrew/homebrew-php | |
fi | |
# Install Oh-My-ZSH | |
echo "Check if brew zsh has been added to available shells." | |
if ! cat /etc/shells | grep "/usr/local/bin/zsh" > /dev/null; then | |
echo "Adding brew zsh to available shells." | |
echo "/usr/local/bin/zsh" | sudo tee -a /etc/shells | |
fi | |
echo "Checking if Zsh has been installed by Homebrew." | |
if [ ! -e /usr/local/bin/zsh ]; then | |
echo "Installing brew zsh." | |
brew install zsh | |
fi | |
echo "Checking if oh my zsh is installed." | |
if [ ! -e ~/.oh-my-zsh/oh-my-zsh.sh ]; then | |
echo "Downloading and installing oh my zsh." | |
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
fi | |
# Install NVM | |
echo "Checking if NVM is installed." | |
if [ ! -e ~/.nvm/nvm.sh ]; then | |
echo "Downloading and installing nvm." | |
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash | |
fi | |
echo "Checking if Node.js is installed." | |
if ! type "node" > /dev/null; then | |
echo "Loading NVM." | |
. ~/.nvm/nvm.sh | |
echo "Installing Node.js v$NODEVERSION." | |
nvm install $NODEVERSION | |
nvm use $NODEVERSION | |
echo "Setting up NVM default alias." | |
nvm alias default $NODEVERSION | |
fi | |
echo "Checking if PHP 5.4 is installed." | |
if [ ! -d /usr/local/Cellar/php54 ]; then | |
echo "Installing PHP 5.4." | |
brew install php54 | |
fi | |
echo "Checking if PHP 5.5 is installed." | |
if [ ! -d /usr/local/Cellar/php55 ]; then | |
echo "Installing PHP 5.5." | |
brew install php55 | |
fi | |
echo "Checking if PHP 5.6 is installed." | |
if [ ! -d /usr/local/Cellar/php56 ]; then | |
echo "Installing PHP 5.6." | |
brew install php56 | |
fi | |
echo "Checking if MySQL is installed." | |
if [ ! -d /usr/local/Cellar/mysql ]; then | |
echo "Installing MySQL." | |
brew install mysql | |
fi | |
install_zip "iTerm" https://iterm2.com/downloads/stable/iTerm2-2_1_1.zip | |
install_zip "Alfred 2" https://cachefly.alfredapp.com/Alfred_2.7.1_387.zip | |
install_zip "Divvy" http://mizage.com/downloads/Divvy.zip | |
install_zip "Atom" https://atom.io/download/mac | |
install_zip "HipChat" https://www.hipchat.com/downloads/latest/mac | |
install_dmg "KeePassX" https://www.keepassx.org/releases/KeePassX-0.4.3.dmg | |
install_dmg "Google Chrome" https://dl.google.com/chrome/mac/stable/GGRO/googlechrome.dmg | |
install_dmg "Sequel Pro" https://sequel-pro.googlecode.com/files/sequel-pro-1.0.2.dmg | |
install_dmg "Sublime Text" http://c758482.r82.cf2.rackcdn.com/Sublime%20Text%20Build%203083.dmg | |
install_dmg "Skype" http://download.skype.com/macosx/6798c0ef1c8de6ddf0ba00fdba572b40/Skype_7.9.746.dmg | |
install_dmg "Firefox" https://download-installer.cdn.mozilla.net/pub/firefox/releases/38.0.5/mac/en-US/Firefox%2038.0.5.dmg | |
install_dmg "IntelliJ IDEA 14" https://download.jetbrains.com/idea/ideaIU-14.1.4.dmg | |
install_dmg "WebStorm" http://download.jetbrains.com/webstorm/WebStorm-10.0.4.dmg | |
install_dmg "Adium" http://downloads.sourceforge.net/project/adium/Adium_1.5.10.dmg?r=&ts=1436214452&use_mirror=iweb | |
install_dmg "VirtualBox" http://download.virtualbox.org/virtualbox/4.3.28/VirtualBox-4.3.28-100309-OSX.dmg true | |
# Add command link for sublime | |
if [ ! -e /usr/local/bin/subl ]; then | |
echo "Adding link to Sublime Text command line binary." | |
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment