-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcltools_install.sh
executable file
·84 lines (73 loc) · 2.4 KB
/
cltools_install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Include configuration values from config.sh
source config
info="[info]"
warning="[warning]"
error="[error]"
check_root() {
if [[ $EUID -ne 0 ]]; then
echo "$error This script must be run as root" 1>&2
exit 1
fi
}
detect_osx_version() {
result=`sw_vers -productVersion`
if [[ $result =~ "10.7" ]]; then
osxversion="10.7"
osxvername="Lion"
cltools=xcode452cltools10_76938212a.dmg
mountpath="/Volumes/Command Line Tools (Lion)"
mpkg="Command Line Tools (Lion).mpkg"
elif [[ $result =~ "10.8" ]]; then
osxversion="10.8"
osxvername="Mountain Lion"
cltools=xcode452cltools10_86938211a.dmg
mountpath="/Volumes/Command Line Tools (Mountain Lion)"
mpkg="Command Line Tools (Mountain Lion).mpkg"
else
echo "$error This machine is running an unsupported version of OS X" 1>&2
exit 1
fi
echo -e "$info Detected OS X $osxversion $osxvername"
}
check_tools() {
RECEIPT_FILE=/var/db/receipts/com.apple.pkg.DeveloperToolsCLI.bom
[ -f "$RECEIPT_FILE" ] && echo "$info Command Line Tools are already installed. Exiting..." && exit 0
}
download_tools () {
# Use curl to download the appropriate installer to tmp
if [ ! -f /tmp/$cltools ]; then
echo -e "$info Downloading Command Line Tools for Mac OS X $osxversion"
cd /tmp && curl -O $webserver/$cltools
else
echo -e "$info $cltools already downloaded to /tmp/$cltools."
fi
}
install_tools() {
# Mount the Command Line Tools dmg
echo -e "$info Mounting Command Line Tools..."
hdiutil mount /tmp/$cltools
# Run the Command Line Tools Installer
echo -e "$info Installing Command Line Tools..."
installer -pkg "$mountpath/$mpkg" -target "/Volumes/Macintosh HD"
# Unmount the Command Line Tools dmg
echo -e "$info Unmounting Command Line Tools..."
hdiutil unmount "$mountpath"
}
cleanup () {
#rm /tmp/$cltools
echo "$info Cleanup complete."
exit 0
}
# Make sure only root can run our script
check_root
# Detect and set the version of OS X for the rest of the script
detect_osx_version
# Check for if tools are already installed by looking for a receipt file
check_tools
# Check for and if necessary download the required dmg
download_tools
# Start the appropriate installer for the correct version of OSX
install_tools
# Cleanup files used during script
cleanup