This comment has been minimized.

This is awesome. The only thing I could recommend is change installer -allowUntrusted -pkg... to sudo installer -allowUntrusted -pkg... and it works great. And if you want to detect if Xcode CL Tools is installed then just run pkgutil --pkgs | grep com.apple | grep CL | grep Tools (I have tested this on 10.7.x, 10.8.x, 10.9.x, 10.10.x, and 10.11.x).