From 78fdc9652f5309cbb8e970630c5df8430aef24d2 Mon Sep 17 00:00:00 2001 From: Newton Date: Mon, 10 Mar 2014 13:16:17 -0700 Subject: [PATCH] Update dotfiles script to automate xCode CLI tools - Create a script to check if xCode is installed; if so inform the user, if not run automated install script of xCode CLI tools - Create a recursive script to automate xCode CLI tools; checks version of kernel to ensure user is on 13 or up (Mavericks) as thats when `xcode-select --install` was introduced. Issue: #33 --- bin/dotfiles | 7 +------ lib/utils | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/bin/dotfiles b/bin/dotfiles index dd9c15908..83cbdaf47 100755 --- a/bin/dotfiles +++ b/bin/dotfiles @@ -47,12 +47,7 @@ do done # Before relying on Homebrew, check that packages can be compiled -if ! type_exists 'gcc'; then - e_error "The XCode Command Line Tools must be installed first." - printf " Download them from: https://developer.apple.com/downloads\n" - printf " Then run: bash ~/.dotfiles/bin/dotfiles\n" - exit 1 -fi +check_xcode # Check for Homebrew if ! type_exists 'brew'; then diff --git a/lib/utils b/lib/utils index 716b4fb35..ee852504d 100644 --- a/lib/utils +++ b/lib/utils @@ -61,3 +61,36 @@ formula_exists() { e_warning "Missing formula: $1" return 1 } + +# Check if xCode is present +check_xcode() { + if type_exists 'gcc'; then + e_success "xCode is installed" + else + e_warning "The XCode Command Line Tools must be installed first." + install_xcode + fi +} + +# Install xCode Command Line Tools +install_xcode() { + # figure out what version of OS X is running + darwin_version=$(uname -r) + + # are you on Mavericks, Darwin kernal 13.0.0 or above + if (( ${darwin_version%%.*} > 12 )); then + e_header "Installing xCode Command Line Tools. Follow the prompt" + xcode-select --install + seek_confirmation "Is xCode done installing" + + if is_confirmed; then + check_xcode + else + check_xcode + fi + else + printf " Download them from: https://developer.apple.com/downloads\n" + printf " Then run: bash ~/.dotfiles/bin/dotfiles\n" + exit 1 + fi +}