Last active
June 23, 2025 10:18
-
-
Save xphir/bf65c64955ee3adc4853097a2003c7f6 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| cli_path="/Library/Developer/CommandLineTools" | |
| flag_file="/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress" | |
| # Create install trigger file if CLI tools are not installed | |
| if [[ ! -d "$cli_path" ]]; then | |
| echo "🔍 Xcode Command Line Tools not found — preparing installation..." | |
| touch "$flag_file" | |
| fi | |
| # Find the latest Command Line Tools product label | |
| product=$( | |
| softwareupdate -l 2>/dev/null | | |
| grep "\*.*Command Line" | | |
| tail -n 1 | | |
| sed 's/^[^C]* //' | |
| ) | |
| # Install if a product was found | |
| if [[ -n "$product" ]]; then | |
| echo "⬇️ Installing: $product" | |
| softwareupdate -i "$product" --verbose | |
| # Remove trigger file if it was created | |
| if [[ -f "$flag_file" ]]; then | |
| rm -f "$flag_file" | |
| fi | |
| echo "✅ Xcode Command Line Tools installation complete." | |
| else | |
| echo "✅ Command Line Tools are already up to date." | |
| fi | |
| # bash <(curl -fsSL https://gist.githubusercontent.com/xphir/bf65c64955ee3adc4853097a2003c7f6/raw) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment