diff --git a/images/macos/provision/core/homebrew.sh b/images/macos/provision/core/homebrew.sh index 01b0fb0f3..201fc586a 100755 --- a/images/macos/provision/core/homebrew.sh +++ b/images/macos/provision/core/homebrew.sh @@ -1,23 +1,19 @@ -#!/bin/sh +#!/bin/bash -e -o pipefail + echo "Installing Homebrew..." - -source ~/utils/utils.sh - -echo Installing Homebrew... HOMEBREW_INSTALL_URL="https://raw.githubusercontent.com/Homebrew/install/master/install.sh" - /bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})" -echo Disabling Homebrew analytics... +echo "Disabling Homebrew analytics..." brew analytics off -echo Installing the last version of curl +echo "Installing the latest curl..." brew install curl -echo Installing wget... +echo "Installing wget..." brew install wget -echo Installing jq +echo "Installing jq..." brew install jq # init brew bundle feature diff --git a/images/macos/provision/core/xcode-clt.sh b/images/macos/provision/core/xcode-clt.sh new file mode 100644 index 000000000..49693d33b --- /dev/null +++ b/images/macos/provision/core/xcode-clt.sh @@ -0,0 +1,43 @@ +#!/bin/bash -e -o pipefail + +is_clt_installed() { + clt_path=`xcode-select -p 2>&1` + [[ -d "$clt_path" ]] +} + +install_clt() { + echo "Searching online for the Command Line Tools" + # This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools + clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" + sudo touch $clt_placeholder + clt_label_command="/usr/sbin/softwareupdate -l | + grep -B 1 -E 'Command Line Tools' | + awk -F'*' '/^ *\\*/ {print \$2}' | + sed -e 's/^ *Label: //' -e 's/^ *//' | + sort -V | + tail -n1" + clt_label=$(eval $clt_label_command) || true + if [[ -n "$clt_label" ]]; then + echo "Installing $clt_label" + sudo "/usr/sbin/softwareupdate" "-i" "$clt_label" + fi + sudo "/bin/rm" "-f" "$clt_placeholder" +} + +echo "Installing Command Line Tools..." +install_clt + +# Retry the installation if tools are not installed from the first attempt +retries=30 +sleepInterval=60 +while ! is_clt_installed; do + if [[ $retries -eq 0 ]]; then + echo "Unable to find the Command Line Tools, all the attempts exhausted" + exit 1 + fi + echo "Command Line Tools not found, trying to install them via softwareupdates, $retries attempts left" + install_clt + ((retries--)) + echo "Wait $sleepInterval seconds before the next check for installed Command Line Tools" + sleep $sleepInterval +done \ No newline at end of file diff --git a/images/macos/provision/core/xcode-ctl.sh b/images/macos/provision/core/xcode-ctl.sh deleted file mode 100644 index cea7aa633..000000000 --- a/images/macos/provision/core/xcode-ctl.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Homebrew doesn't support installation of command line tools on MacOS 11.0 -# https://github.com/Homebrew/install/blob/master/install.sh#L191 -# Copy-paste script from brew installation process -# https://github.com/Homebrew/install/blob/master/install.sh#L530 -# This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools - -clt_placeholder="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" -touch $clt_placeholder -clt_label=`/usr/sbin/softwareupdate -l | - grep -B 1 -E 'Command Line Tools beta 5' | - awk -F'*' '/^ *\\*/ {print \$2}' | - sed -e 's/^ *Label: //' -e 's/^ *//' | - sort -V | - tail -n1` -/usr/sbin/softwareupdate -i "$clt_label" -rm -f $clt_placeholder -sudo xcode-select --switch "/Library/Developer/CommandLineTools/" \ No newline at end of file diff --git a/images/macos/templates/macOS-10.13.json b/images/macos/templates/macOS-10.13.json index 2190a6b4a..35c7ef3c7 100644 --- a/images/macos/templates/macOS-10.13.json +++ b/images/macos/templates/macOS-10.13.json @@ -128,6 +128,7 @@ "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "pause_before": "30s", "scripts": [ + "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/templates/macOS-10.14.json b/images/macos/templates/macOS-10.14.json index 269ffa71f..2687302e0 100644 --- a/images/macos/templates/macOS-10.14.json +++ b/images/macos/templates/macOS-10.14.json @@ -128,6 +128,7 @@ "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "pause_before": "30s", "scripts": [ + "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/templates/macOS-10.15.json b/images/macos/templates/macOS-10.15.json index 3dcc3d33e..a65bd72ac 100644 --- a/images/macos/templates/macOS-10.15.json +++ b/images/macos/templates/macOS-10.15.json @@ -129,6 +129,7 @@ "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "pause_before": "30s", "scripts": [ + "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/templates/macOS-11.0.json b/images/macos/templates/macOS-11.0.json index 6da9df38d..27f39bfb0 100644 --- a/images/macos/templates/macOS-11.0.json +++ b/images/macos/templates/macOS-11.0.json @@ -129,7 +129,7 @@ "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "pause_before": "30s", "scripts": [ - "./provision/core/xcode-ctl.sh", + "./provision/core/xcode-clt.sh", "./provision/core/homebrew.sh", "./provision/core/dotnet.sh", "./provision/core/python.sh", diff --git a/images/macos/toolsets/toolset-11.0.json b/images/macos/toolsets/toolset-11.0.json index 5ff2280a2..18d72c23f 100644 --- a/images/macos/toolsets/toolset-11.0.json +++ b/images/macos/toolsets/toolset-11.0.json @@ -2,7 +2,7 @@ "xcode": { "default": "11.7", "versions": [ - "12.2_beta", "11.7" + "12.2_beta", "12.1_GM_seed", "11.7" ] }, "xamarin": {