Skip to content

Commit a989b96

Browse files
committed
Fix Xcode-CLT install
- software update technique wasn't finding developer tools/Xcode-CLT - use `return 0` to bail out of first function when this happens... this is normal behavior - make messages clearer while xcode-clt install is attempted - fix spelling errors
1 parent 20fdf56 commit a989b96

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

prerequisites/install-functions/install-xcode-clt.sh

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ need_xcodeCLT() {
44
echo "false"
55
else
66
local xcode_dir
7-
xcode_dir="$(/usr/bin/xcode-select -print-path 2>/dev/null)"
7+
xcode_dir="$(/usr/bin/xcode-select -print-path 2>/dev/null)" || true
88
if [[ ! -d "${xcode_dir}" || ! -x "${xcode_dir}/usr/bin/make" ]]; then
99
echo "true"
1010
else
@@ -14,57 +14,62 @@ need_xcodeCLT() {
1414
}
1515

1616
xcode_clt_install () {
17-
info "It appears that you are on Mac OS and do not have the Xcode command line tools (CLT) installed."
18-
app_store_label="$(softwareupdate -l | grep -B 1 -E "Command Line (Developer|Tools)" | awk -F"*" '/^ +\\*/ {print $2}' | sed 's/^ *//' | tail -n1)"
17+
app_store_label="$(softwareupdate -l | grep -B 1 -E "Command Line (Developer|Tools)" | awk -F"*" '/^ +\\*/ {print $2}' | sed 's/^ *//' | tail -n1)" || return 0
1918
if [[ "${arg_y}" == "${__flag_present}" ]]; then
2019
info "-y or --yes-to-all flag present. Proceeding with non-interactive download and install."
2120
else
21+
info "If you proceed with the Xcode-CLT installation you may be prompted for your password."
2222
printf "Ready to install %s? (Y/n)" "${app_store_label}"
2323
read -r install_xcodeclt
2424
printf '%s\n' "${install_xcodeclt}"
2525
if [[ "${install_xcodeclt}" == [nN]* ]]; then
26-
emergency "${this_script}: Aborting: cannot procede without XCode CLT."
26+
emergency "${this_script}: Aborting: cannot proceed without XCode CLT."
2727
fi
2828
fi
29-
info "We will attempt to download and install XCode CLT for you now. Note: sudo priveledges required"
29+
info "install.sh will attempt to download and install XCode CLT for you now."
30+
info "Note: sudo privileges required. Please enter your password if prompted."
3031
place_holder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
3132
sudo /usr/bin/touch "${place_holder}" || true
32-
sudo /usr/sbin/softwareupdate -i app_store_label || true
33+
sudo /usr/sbin/softwareupdate -i app_store_label || return 0
3334
sudo /bin/rm -f "${place_holder}" || true
34-
sudo /usr/bin/xcode-select --switch "/Library/Developer/CommandLineTools" || true
35+
sudo /usr/bin/xcode-select --switch "/Library/Developer/CommandLineTools" || return 1
3536
}
3637

3738
headless_xcode_clt_install () {
38-
# Fallback her if headless install failed
39+
# Fallback here if headless install/upgrade failed. This is the usual path through this code.
3940
if [[ "${arg_y}" == "${__flag_present}" ]]; then
4041
info "-y or --yes-to-all flag present. Proceeding with non-interactive download and install."
4142
else
43+
info "If you proceed with the Xcode-CLT installation you may be prompted for your password."
4244
printf "Ready to install Xcode-CLT using xcode-select? (Y/n)"
4345
read -r install_xcodeclt
4446
printf '%s\n' "${install_xcodeclt}"
4547
if [[ "${install_xcodeclt}" == [nN]* ]]; then
46-
emergency "${this_script}: Aborting: cannot procede without XCode CLT."
48+
emergency "${this_script}: Aborting: cannot proceed without XCode CLT."
4749
fi
4850
fi
49-
info "Installing Xcode Command Line Tools (CLE), please follow instructions on popup window."
51+
info "Installing Xcode Command Line Tools (CLT), using \`xcode-select --install\`."
52+
info "Note: sudo privileges required. Please enter your password if prompted."
5053
sudo /usr/bin/xcode-select --install || emergency "${this_script}: unable to run \`sudo xcode-select --install\`"
51-
printf "Press <enter> once installation has completed"
54+
printf "Please press <enter> once installation of Xcode command line tools has completed."
5255
read -r
5356
sudo /usr/bin/xcode-select --switch "/Library/Developer/CommandLineTools" || \
5457
emergency "${this_script}: Xcode-CLT installation and activation failed, unable to continue"
5558
}
5659

5760
maybe_install_xcodeCLT () {
5861
if [[ "$(need_xcodeCLT)" == "true" ]]; then
59-
xcode_clt_install
62+
info "It appears that you are on Mac OS and do not have the Xcode command line tools (CLT) installed, or they need to be upgraded."
63+
info "install.sh will now attempt to install/upgrade the Xcode-CLT using \`softwareupdate\`"
64+
xcode_clt_install || true # This usually fails since `softwareupdate -i` doesn't return CLTs needing update
6065
fi
6166
if [[ "$(need_xcodeCLT)" == "true" ]]; then
62-
info "First Xcode-CLT installation failed, trying another method"
63-
headless_xcode_clt_install
67+
info "\`softwareupdate\` installation/upgrade failed. This is normal. Now trying with \`xcode-select --install\`"
68+
headless_xcode_clt_install || emergency "${this_script}: Could not install Xcode command line tools, unable to proceed. Please install them via the app store before retrying this installation."
6469
fi
6570

6671
clang_output="$(/usr/bin/xzrun clang 2>&1)" || true
6772
if [[ "${clang_output}" =~ license ]]; then
68-
emergency "${this_script}: It appears you have not agreed to the Xcode license. Please do so before attempting to run this script again. This may be acheived by opening Xcode.app or running \`sudo xcodebuild -license\`"
73+
emergency "${this_script}: It appears you have not agreed to the Xcode license. Please do so before attempting to run this script again. This may be achieved by opening Xcode.app or running \`sudo xcodebuild -license\`"
6974
fi
7075
}

0 commit comments

Comments
 (0)