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 +}