-
Notifications
You must be signed in to change notification settings - Fork 1
/
cltools_uninstall.sh
executable file
·69 lines (56 loc) · 1.86 KB
/
cltools_uninstall.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
#!/bin/bash
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"
exit 1
fi
echo -e "$info Detected OS X $osxversion $osxvername"
}
uninstall_tools() {
RECEIPT_FILES=("/var/db/receipts/com.apple.pkg.DeveloperToolsCLI.bom")
RECEIPT_PLISTS=("/var/db/receipts/com.apple.pkg.DeveloperToolsCLI.plist")
[ ! -f "${RECEIPT_FILES[0]}" ] && echo -e "$info Nothing to remove. Exiting..." && exit 0
echo -e "$info Command Line Tools installed. Removing..."
# Need to be at root
cd /
# Remove files and dirs mentioned in the "Bill of Materials" (BOM)
for bom in "${RECEIPT_FILES[@]}"
do
lsbom -fls $bom | sudo xargs -I{} rm -r "{}"
sudo rm $bom
done
# remove the plists
for plist in "${RECEIPT_PLISTS[@]}"
do
sudo rm $plist
done
echo "$info Done! If XCode is running, restart it to have Command Line Tools appear as uninstalled."
}
# 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
# Uninstall the Command Line Tools
uninstall_tools