Skip to content

Commit 864a96c

Browse files
committed
move function back into main script
1 parent 46bd626 commit 864a96c

File tree

2 files changed

+45
-62
lines changed

2 files changed

+45
-62
lines changed

XcodeCLTools-install.zsh

Lines changed: 0 additions & 54 deletions
This file was deleted.

autopkg-setup.sh

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,51 @@ installCommandLineTools() {
4444
# This section written by Rich Trouton.
4545
echo "### Installing the command line tools..."
4646
echo
47-
zsh "$working_dir/XcodeCLTools-install.zsh"
47+
cmd_line_tools_temp_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress"
48+
49+
# convert a macOS major version to a darwin version
50+
os_version=$(sw_vers -productVersion)
51+
if [[ "${os_version:0:2}" == "10" ]]; then
52+
darwin_version=${os_version:3:2}
53+
darwin_version=$((darwin_version+4))
54+
else
55+
darwin_version=${os_version:0:2}
56+
darwin_version=$((darwin_version+9))
57+
fi
58+
59+
# installing the latest Xcode command line tools
60+
61+
if [[ "$darwin_version" -lt 15 ]] ; then
62+
echo "macOS version $os_version is too old for this script"
63+
exit 1
64+
fi
65+
66+
echo "macOS version $os_version - proceeding"
67+
68+
# create the placeholder file which is checked by the softwareupdate tool
69+
# before allowing the installation of the Xcode command line tools.
70+
71+
touch "$cmd_line_tools_temp_file"
72+
73+
# identify the correct update in the Software Update feed with "Command Line Tools" in the name
74+
if [[ "$darwin_version" -ge 19 ]] ; then
75+
cmd_line_tools=$(softwareupdate -l | awk '/\*\ Label: Command Line Tools/ { $1=$1;print }' | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 9- | head -n 1)
76+
else
77+
cmd_line_tools=$(softwareupdate -l | awk '/\*\ Command Line Tools/ { $1=$1;print }' | grep "${os_version:3:2}" | sed 's/^[[ \t]]*//;s/[[ \t]]*$//;s/*//' | cut -c 2-)
78+
fi
79+
80+
# Iistall the command line tools
81+
if [[ ${cmd_line_tools} ]]; then
82+
echo "Download found - installing"
83+
softwareupdate -i "$cmd_line_tools" --verbose
84+
else
85+
echo "Download not found"
86+
fi
87+
88+
# remove the temp file
89+
if [[ -f "$cmd_line_tools_temp_file" ]]; then
90+
rm "$cmd_line_tools_temp_file"
91+
fi
4892
}
4993

5094
installAutoPkg() {
@@ -186,13 +230,6 @@ configureSlack() {
186230

187231
## Main section
188232

189-
# working_dir=$(dirname "$0")
190-
working_dir=$(mdfind -literal "kMDItemDisplayName == 'autopkg-setup.sh'" 2>/dev/null)
191-
if [[ ! -d "$working_dir" ]]; then
192-
echo "ERROR: multitenant-jamf-tools not found"
193-
exit 1
194-
fi
195-
196233
# Commands
197234
GIT="/usr/bin/git"
198235
DEFAULTS="/usr/bin/defaults"

0 commit comments

Comments
 (0)