Last active
December 5, 2016 13:29
-
-
Save umireon/68d7edbe7fa22055f6da3b5d64d8705c to your computer and use it in GitHub Desktop.
Xcode Command Line Tools (CLT) remove script for macOS Sierra
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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