#!/bin/bash

cd "$(dirname "$BASH_SOURCE")" \
    && source '../../utils.sh' \
    && source './utils.sh'

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {

    if ! xcode-select -p &> /dev/null; then

        # Prompt user to install the XCode Command Line Tools
        xcode-select --install &> /dev/null

        # Wait until the XCode Command Line Tools are installed
        while ! xcode-select -p &> /dev/null; do
            sleep 5
        done

        print_result $? 'Install XCode Command Line Tools'

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Prompt user to agree to the terms of the Xcode license
        # https://github.com/alrra/dotfiles/issues/10

        sudo xcodebuild -license
        print_result $? 'Agree with the XCode Command Line Tools licence'

    fi

    print_result $? 'XCode Command Line Tools'

}

main

#!/bin/bash

cd "$(dirname "$BASH_SOURCE")" \
    && source '../../utils.sh' \
    && source './utils.sh'

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

main() {

    if ! xcode-select -p &> /dev/null; then

        # Prompt user to install the XCode Command Line Tools
        xcode-select --install &> /dev/null

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Wait until the XCode Command Line Tools are installed
        while ! xcode-select -p &> /dev/null; do
            sleep 5
        done

        print_result $? 'Install XCode Command Line Tools'

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Point the `xcode-select` developer directory to
        # the appropriate directory from within `Xcode.app`
        # https://github.com/alrra/dotfiles/issues/13

        sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
        print_result $? 'Make "xcode-select" developer directory point to Xcode'

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        # Prompt user to agree to the terms of the Xcode license
        # https://github.com/alrra/dotfiles/issues/10

        sudo xcodebuild -license
        print_result $? 'Agree with the XCode Command Line Tools licence'

    fi

    print_result $? 'XCode Command Line Tools'

}

main

Fix "'xcodebuild' requires Xcode" error
[osx] Fix "'xcodebuild' requires Xcode" error

By default, the `xcode-select` developer directory points to
`/Library/Developer/CommandLineTools`, but since it doesn't
get (immediately?) updated to point to the appropriate directory
from within `Xcode.app` once `Xcode` is installed, the following
error will be raised when trying to install anything that require
the `Xcode` CLTs:

 " xcode-select: error: tool 'xcodebuild' requires Xcode, but
   active developer directory '/Library/Developer/CommandLineTools'
   is a command line tools instance. "

This commit fixes the issue described above by making the
`xcode-select` developer directory point to the appropriate
directory from within `Xcode.app` once Xcode is installed.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Fix alrra/dotfiles#13
Ref alrra/dotfiles#13
