From e00fe40725d49e035dd8abe91b19908d60420db3 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 9 Jan 2024 02:20:13 +0000 Subject: [PATCH] feat: add macos commandlinetools (for pyenv, brew, etc) --- commandlinetools/README.md | 55 ++++++++++++++++++++++++++++++++ commandlinetools/install.sh | 62 +++++++++++++++++++++++++++++++++++++ xcode-cli | 1 + 3 files changed, 118 insertions(+) create mode 100644 commandlinetools/README.md create mode 100644 commandlinetools/install.sh create mode 120000 xcode-cli diff --git a/commandlinetools/README.md b/commandlinetools/README.md new file mode 100644 index 0000000..f1f969f --- /dev/null +++ b/commandlinetools/README.md @@ -0,0 +1,55 @@ +--- +title: XCode Command Line Tools +homepage: https://webinstall.dev/commandlinetools +tagline: | + The XCode Command Line Tools include git, swift, make, clang, and other developer tools +--- + +## Cheat Sheet + +> The developer tools provided by Apple for macOS. + +- git +- swift +- make +- clang +- etc + +This is also part of [webi-essentials](../webi-essentials/). + +## Table of Contents + +- Files +- Manual Install + - macOS + - Linux + - Alpine + - Windows + +### Files + +These are the files / directories that are created and/or modified with this +install: + +```sh +/Library/Developer/CommandLineTools/ +``` + +### How to Install Manually + +It's very easy to start the installer: + +```sh +xcode-select --install +``` + +The trick is to also have a mechanism to know when it has finished: + +```sh +while ! test -x /Library/Developer/CommandLineTools/usr/bin/git || + ! test -x /Library/Developer/CommandLineTools/usr/bin/make; do + sleep 0.25 +done + +echo "Command Line Tools Installed" +``` diff --git a/commandlinetools/install.sh b/commandlinetools/install.sh new file mode 100644 index 0000000..3153746 --- /dev/null +++ b/commandlinetools/install.sh @@ -0,0 +1,62 @@ +#!/bin/sh +set -e +set -u + +fn_install_xcode_commandlinetools() { ( + b_os="$(uname -s)" + if test "${b_os}" != 'Darwin'; then + echo >&2 'XCode Command Line Tools are for macOS only' + return 1 + fi + + # streamline the output to be pretty + fn_check_pkg '/Library/Developer/CommandLineTools/usr/bin/clang' 'clang' + fn_check_pkg '/Library/Developer/CommandLineTools/usr/bin/git' 'git' + fn_check_pkg '/Library/Developer/CommandLineTools/usr/bin/make' 'make' + echo >&2 "" + + # git + if xcode-select -p > /dev/null 2> /dev/null; then + echo "" + return 0 + fi + + cmd_xcode_cli_tools_install="xcode-select --install" + echo " Running $(t_cmd "${cmd_xcode_cli_tools_install}")" + $cmd_xcode_cli_tools_install 2> /dev/null + echo "" + echo ">>> $(t_attn 'ACTION REQUIRED') <<<" + echo "" + echo " $(t_attn "Click") '$(t_bold 'Install')' $(t_attn "in the pop-up")" + echo " (it may appear $(t_em 'under') this window)" + echo "" + echo "^^^ $(t_attn 'ACTION REQUIRED') ^^^" + echo "" + printf " waiting %s to finish installing Command Line Developer Tools ..." "$(t_em 'for you')" + while ! test -x /Library/Developer/CommandLineTools/usr/bin/git || + ! test -x /Library/Developer/CommandLineTools/usr/bin/make; do + sleep 0.25 + done + echo " $(t_info 'OK')" + echo " Installed to $(t_path '/Library/Developer/CommandLineTools/')" + sleep 1 +); } + +fn_check_pkg() { ( + a_pkg="${1}" + a_pkgname="${2:-$a_pkg}" + + printf >&2 ' %s %s %s' \ + "$(t_dim "Checking for")" \ + "$(t_pkg "${a_pkgname}")" \ + "$(t_dim "...")" + + if command -v "${a_pkg}" > /dev/null; then + echo >&2 " $(t_dim 'OK')" + return 0 + fi + + echo >&2 ' missing' +); } + +fn_install_xcode_commandlinetools diff --git a/xcode-cli b/xcode-cli new file mode 120000 index 0000000..f69a588 --- /dev/null +++ b/xcode-cli @@ -0,0 +1 @@ +commandlinetools \ No newline at end of file