Skip to content

Instantly share code, notes, and snippets.

@pearofducks
Created March 7, 2017 05:52
Show Gist options
  • Save pearofducks/53dd9bae8ba4a6f0a82d507a926c8130 to your computer and use it in GitHub Desktop.
Save pearofducks/53dd9bae8ba4a6f0a82d507a926c8130 to your computer and use it in GitHub Desktop.
hands-off macOS command-line-tools install
if [[ $(/usr/bin/xcode-select -p &>/dev/null; /bin/echo $?) == 2 ]]; then
cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
touch "$cmd_line_tools_temp_file"
cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | tail -1 | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-)
softwareupdate -i "$cmd_line_tools" --verbose
if [[ $(/usr/bin/xcode-select -p &>/dev/null; /bin/echo $?) != 2 ]]; then
echo "CLT installed."
if [[ -f "$cmd_line_tools_temp_file" ]]; then
rm "$cmd_line_tools_temp_file"
fi
else
die "CLT install failed"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment