Skip to content

Instantly share code, notes, and snippets.

@umireon
Last active December 5, 2016 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umireon/68d7edbe7fa22055f6da3b5d64d8705c to your computer and use it in GitHub Desktop.
Save umireon/68d7edbe7fa22055f6da3b5d64d8705c to your computer and use it in GitHub Desktop.
Xcode Command Line Tools (CLT) remove script for macOS Sierra
#!/bin/bash
## # Usage
## 1. Boot with Recovery OS and open Terminal.app
## 2. cd "/Volumes/Macintosh HD"
## 3. Execute this script
## When the network connection is available, this script can be executed by:
## curl -fsSL https://gist.github.com/umireon/68d7edbe7fa22055f6da3b5d64d8705c/raw/remove-xcode-clt8.sh | bash
# sanity check
if [[ ! -d Users ]] && [[ $1 != -f ]]; then
echo "$(pwd)/Users not found"
volumes=(/Volumes/*/Users)
echo "cd to system root like: cd ${volumes[0]%/*}"
exit 1
fi
xargs="usr/bin/xargs"
pkgutil="pkgutil --volume ."
xcode_select="chroot . /usr/bin/xcode-select"
clt_pkgs() {
$pkgutil --pkgs='com\.apple\.pkg\.(CLTools_Executables|DevSDK.*)'
}
clt_files() {
clt_pkgs | $xargs -n1 $pkgutil --only-files --files | sort -ur
}
clt_dirs() {
clt_pkgs | $xargs -n1 $pkgutil --only-dirs --files | sort -ur
}
clt_files | $xargs -n1000 rm
clt_dirs | $xargs -n1000 rmdir
clt_pkgs | $xargs -I{} rm System/Library/Receipts/{}.{bom,plist}
echo reset the active developer directory
$xcode_select -r
echo check the active developer directory
$xcode_select -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment