rtrouton / rtrouton_scripts

Scripts to share
MIT License
1.3k stars 489 forks source link

Add check to see if Xcode commandlinetools already installed #95

Open jelockwood opened 2 years ago

jelockwood commented 2 years ago

As far as I can see the existing script to install Xcode commandlinttools does not do a check to see if these tools are already installed. Apart from the potential fact that this would unnecessarily reinstall the tools if they are already installed there is also the possibility that the touch command used will at least temporarily overwrite part of the tools.

Apple have unfortunately made it harder than it need be to via a script determine if the tools are already installed, sadly a trend that seems to be more and more common these days with Apple.

However the following script does I believe provide a reliable method of checking.

Basically it boils down to using the well known xcode-select -p command but makes it clearer that this command returns 0 if they are NOT installed and 1 if they ARE installed. These numbers are normally only output to stderr and hence not normally visible.

I am suggesting that similar code be added to the script written by @rtrouton

#!/bin/sh

if ! command xcode-select -p &> /dev/null
then
    echo $?
    echo "\t xcode was not found! You need to manually install it :/ "
else
    echo $?
    echo "xcode is installed, checking other IOS build tools"
fi
exit