Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dotfiles script to automate xCode CLI tools #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions bin/dotfiles
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions lib/utils
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, type_exists 'gcc' will be true on OS X 10.9, even if XCode is not installed.

For OS X 10.9, I personally use:

if [ $(xcode-select -p &> /dev/null; printf $?) -ne 0 ]; then
     xcode-select --install 
     # ...
fi

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I get that xcode-select -p prints out the location of the xCode developer directory if available, (and the redirect to the null device), but what does the printf $? do? Isn't that supposed to print out the previous command?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does the printf $? do?

@chrisopedia printf $? prints the exit code of the last executed command (in this case xcode-select -p &> /dev/null).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the assumption here then is that xcode select -p will print out an exit code that is not equal to 0? What happens or is it possible that they could change their exit code? What about if there is no status number with their exit as in just plain exit? Does that still pass?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens or is it possible that they could change their exit code? What about if there is no status number with their exit as in just plain exit? Does that still pass?

@chrisopedia in any UNIX based system every command returns an exit code (from 0-255). 0 means true/successful completion, while != 0 means false/something went wrong.

For more in-depth information, please read: http://tldp.org/LDP/abs/html/exit-status.html.

xcode select -p will print out an exit code that is not equal to 0?

@chrisopedia xcode-select -p &> /dev/null; printf $? will print out the exit code for xcode-select -p no matter what value it is. Then, -ne 0 will check if that exit code is different then 0, and if it is, then XCode will need to be installed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool @alrra I'll update my pull request with this new check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisopedia again, please note that this is only for OS X 10.9+. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K. Will do.

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
}