From 6af8b8d9cf5e653b545b9a4d79b8ccad705067c5 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Tue, 26 Mar 2024 08:51:33 -0600 Subject: [PATCH 01/18] Rewrite monorepo install script --- tools/install-monorepo.sh | 441 ++++++++++++++++++++++++++++---------- 1 file changed, 322 insertions(+), 119 deletions(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 4faaec56ac4b2..8826b83f63fd1 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -1,9 +1,11 @@ #!/usr/bin/env bash -set -eo pipefail +# Start in the monorepo root folder. +root_dir="$(dirname "${BASH_SOURCE[0]}")/.." +cd "$root_dir" -BASE=$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd) -source "$BASE/tools/includes/chalk-lite.sh" +# Source some helper functions. +. tools/includes/chalk-lite.sh # Print help and exit. function usage { @@ -15,143 +17,344 @@ function usage { exit 1 } -if [[ $1 ]]; then - usage -fi +# Wrapper to check for a command silently. +function has_command { + command -v "$1" &>/dev/null + return $? +} -# Check if we're on a Mac or Linux, bail if we're not. -OS="$(uname)" -if [[ "$OS" == "Linux" ]]; then - ON_LINUX=1 - if ! command -v apt &>/dev/null; then - die "Installer script requires 'apt' to ensure essentials are installed." +# Check if we're on Mac or Linux; bail if we're not. +function do_system { + OS="$(uname)" + if [[ "$OS" != "Linux" && "$OS" != "Darwin" ]]; then + die "Installer script is only supported on macOS and Linux." + elif [[ "$(uname -m)" == "aarch64" ]]; then + # Homebrew doesn't support Linux on ARM, so gate the installer as well. + die "Linux on ARM is unsupported." fi - sudo apt update - sudo apt install build-essential -elif [[ "$OS" != "Darwin" ]]; then - die "Installer script is only supported on macOS and Linux." -fi + echo "Valid OS: $OS" +} -# Check for curl and git -if ! command -v git &>/dev/null; then - die "Installer script requires 'git' to be installed." -fi +# Checks for build-essential (Linux), git, and curl. +function do_basics { + if [[ "$OS" == "Linux" ]]; then + if ! has_command apt; then + # Effectively only support Debian. + die "Installer script requires 'apt' to ensure build-essential package is installed." + fi -if ! command -v curl &>/dev/null; then - die "Installer script requires 'curl' to be installed" -fi + sudo apt update + if [[ $(dpkg-query -W --showformat='${db:Status-Status}' build-essential 2>/dev/null) != 'installed' ]]; then + echo "build-essential: not found" + echo "Installing build-essential..." + sudo apt install build-essential || die "Unable to install build-essential!" + echo "Installed build-essential." + fi + echo "build-essential: available" + fi -# Check of Homebrew and nvm are installed -info "Checking if Homebrew is installed..." -if ! command -v brew &>/dev/null; then - info "Installing Homebrew" - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - if [[ -n "$ON_LINUX" ]]; then # Add homebrew to PATH - echo 'eval "$("/home/linuxbrew/.linuxbrew/bin/brew" shellenv)"' >> "$HOME/.profile" - eval "$("/home/linuxbrew/.linuxbrew/bin/brew" shellenv)" - PATH="/home/linuxbrew/.linuxbrew/bin:$PATH" + # Check for curl and git + if ! has_command git; then + echo "git: not found" + if [[ "$OS" == "Linux" ]]; then + echo "Installing git..." + sudo apt install git || die "Unable to install git!" + echo "Installed git." + else + die "Installer script requires git to be installed." + fi fi -else - info "Updating brew" - brew update - # Brew can be finicky on MacOS - if [[ $? -ne 0 ]]; then - echo "Reinstalling Homebrew" - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + echo "git: available" + + if ! has_command curl; then + echo "curl: not found" + if [[ "$OS" == "Linux" ]]; then + echo "Installing curl..." + sudo apt install curl || die "Unable to install curl!" + echo "Installed curl." + else + die "Installer script requires curl to be installed." + fi fi -fi + echo "curl: available" +} -info "Checking if NVM is installed..." -if ! command -v nvm &>/dev/null; then - info "Installing nvm" - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash && export NVM_DIR=$HOME/.nvm && source $NVM_DIR/nvm.sh --no-use -else - info "Updating nvm" - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash -fi +# Checks for, installs, and updates Homebrew. +function do_homebrew { + if ! has_command brew; then + echo "brew: not found" + echo "Installing brew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || die "Unable to install brew!" + if [[ "$OS" == "Linux" ]]; then + HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew" + else + HOMEBREW_PREFIX="/opt/homebrew" + fi -# Install and use the correct version of Node.js -info "Installing Node.js" -nvm install && nvm use + # Add brew env to current script for use later. + eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)" -# Install our requirements -info "Checking Bash version..." -if [[ -z "${BASH_VERSINFO}" || -z "${BASH_VERSINFO[0]}" || ${BASH_VERSINFO[0]} -lt 4 ]]; then - brew install bash -fi + if ! has_command brew; then + die "Unable to install brew!" + fi + echo "Installed brew." -info "Checking if jq is installed..." -if ! command -v jq &>/dev/null; then - info "Installing jq" - brew install jq -fi + # Determine shell RC file. + # Adapted from Homebrew install script: + # https://github.com/Homebrew/install/blob/master/install.sh + case "${SHELL}" in + */bash*) + if [[ "$OS" == "Linux" ]]; then + shell_rcfile="${HOME}/.bashrc" + else + shell_rcfile="${HOME}/.bash_profile" + fi + ;; + */zsh*) + if [[ "$OS" == "Linux" ]]; then + shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zshrc" + else + shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zprofile" + fi + ;; + */fish*) + shell_rcfile="${HOME}/.config/fish/config.fish" + ;; + *) + shell_rcfile="${ENV:-"${HOME}/.profile"}" + ;; + esac + + # Add brew init to shell rc file. + if ! grep -qs "eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"" "${shell_rcfile}"; then + (echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_rcfile} + fi -info "Checking if pnpm is installed..." -if ! command -v pnpm &>/dev/null; then - info "Installing pnpm" - # Don't use https://get.pnpm.io/install.sh, that doesn't play nice with different shells. - # And corepack will likely lose pnpm every time nvm installs a new node version. - curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm -fi -if [[ -z "$( pnpm bin --global )" ]]; then - info "Setting up pnpm" - if ! pnpm setup; then - warn 'pnpm has no bin dir set, and `pnpm setup` failed. Linking the Jetpack CLI may fail.' else - # Try to read PNPM_HOME from the login shell after `pnpm setup`, as pnpm probably changed it. - P=$( "$SHELL" -i -c 'echo $PNPM_HOME' ) || true - if [[ -n "$P" ]]; then - export PNPM_HOME="$P" - if [[ ":$PATH:" != *":$PNPM_HOME:"* ]]; then - export PATH="$PNPM_HOME:$PATH" + # Run brew updates + if ! brew update &> /dev/null; then + die "Unable to update brew!" + fi + fi + export HOMEBREW_NO_AUTO_UPDATE=1 + export HOMEBREW_NO_ENV_HINTS=1 + echo "brew: available" +} + +# Checks for, installs, and updates nvm. +function do_nvm { + # Get latest nvm version. + # Based on this: https://stackoverflow.com/a/71896712 + good_nvm_version=$(basename $(curl -fs -o/dev/null -w %{redirect_url} https://github.com/nvm-sh/nvm/releases/latest)) + + if [[ -f "$HOME"/.nvm/nvm.sh ]] ; then + # Since nvm really several shell functions, and isn't in the environment + # initially, we need to source it. + if [[ -f "$(brew --prefix nvm)/nvm.sh" ]]; then + # Sometimes nvm is installed via brew, which is an unsupported install + # route, and uses a wrapper helper script. + . "$(brew --prefix nvm)/nvm.sh" + else + export NVM_DIR="$HOME/.nvm" && . "$NVM_DIR"/nvm.sh --no-use + fi + + if [[ v$(nvm --version) != "$good_nvm_version" ]]; then + echo "nvm: wrong version" + echo "Updating nvm..." + + # Download latest version + curl -s -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$good_nvm_version/install.sh" | bash - &>/dev/null && + + # Source again to get latest shell functions + . "$NVM_DIR/nvm.sh" --no-use + + # Something's wrong, so abort. + if [[ "v$(nvm --version)" != "$good_nvm_version" ]]; then + die "Unable to update nvm!" fi + echo "Updated nvm." + fi + else + echo "nvm: not found" + info "Installing nvm..." + curl -s -o- https://raw.githubusercontent.com/nvm-sh/nvm/$good_nvm_version/install.sh | bash - &>/dev/null && + + # Source to get latest shell functions + export NVM_DIR="$HOME"/.nvm && . "$NVM_DIR"/nvm.sh --no-use + + # Something's wrong, so abort. + if ! has_command nvm; then + die "Unable to install nvm!" fi + echo "Installed nvm." fi -fi -source .github/versions.sh -info "Installing and linking PHP $PHP_VERSION" -brew install php@$PHP_VERSION -brew link php@$PHP_VERSION + echo "nvm: available" +} + +# Checks for and installs node. +function do_node { + good_node_version=$(cat .nvmrc) + if ! has_command node; then + echo "node: not found" + echo "Installing node..." + nvm install + # Something's wrong, so abort. + if ! has_command node; then + die "Unable to install node!" + fi + echo "Node installed." + elif [[ $(node --version) != v"$good_node_version" ]]; then + # Install correct version if not yet installed + if ! nvm list node | grep -q "$good_node_version"; then + echo "node: needed version not installed" + echo "Installing correct node version..." + nvm install + # Something's wrong, so abort. + if ! nvm list node | grep -q "$good_node_version"; then + die "Unable to needed version of node!" + fi + echo "Correct version of node installed." + fi + fi + # Switch node version + nvm use &> /dev/null + echo "node: available" +} -info "Checking composer..." -if ! command -v composer &>/dev/null; then - info "Installing Composer" - EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" +function do_bash { + if [[ -z "${BASH_VERSINFO}" || -z "${BASH_VERSINFO[0]}" || ${BASH_VERSINFO[0]} -lt 4 ]]; then + echo "bash 4+: not found" + echo "Installing bash..." + brew install bash + if [[ -z "${BASH_VERSINFO}" || -z "${BASH_VERSINFO[0]}" || ${BASH_VERSINFO[0]} -lt 4 ]]; then + die "Unable to install newer version of 'bash'!" + fi + echo "Installed bash." + fi + echo "bash 4+: available" +} - if [[ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]]; then +function do_jq { + if ! has_command jq; then + echo "jq: not found" + echo "Installing jq..." + brew install jq &>/dev/null + if ! has_command jq; then + die "Unable to install newer version of jq!" + fi + echo "Installed jq." + fi + echo "jq: available" +} + +function do_pnpm { + if ! has_command pnpm; then + echo "pnpm: not found" + echo "Installing pnpm..." + curl -fsSL https://get.pnpm.io/install.sh | sh - &>/dev/null + + # Make sure pnpm is in one's path + export PNPM_HOME="$("$SHELL" -i -c 'echo "$PNPM_HOME"')" + export PATH="$("$SHELL" -i -c 'echo "$PATH"')" + if ! has_command pnpm; then + die "Unable to install 'pnpm'!" + fi + echo "Installed pnpm." + fi + echo "pnpm: available" +} + +function do_php { + if ! has_command php || [[ $(php -r "echo version_compare(PHP_VERSION,'$PHP_VERSION');") -eq -1 ]]; then + echo "PHP $PHP_VERSION: not found" + + # Note that we can't use grep -v, as it's prematurely terminated. + if ! $(brew list|grep php@$PHP_VERSION >/dev/null); then + echo "Installing PHP $PHP_VERSION..." + # Don't hide output, as this can take some time... + brew install php@"$PHP_VERSION" + else + echo "Linking already-installed PHP $PHP_VERSION..." + fi + brew link --overwrite php@"$PHP_VERSION" &>/dev/null + if ! has_command php || [[ $(php -r "echo version_compare(PHP_VERSION,'$PHP_VERSION');") -eq -1 ]]; then + die "Unable to install PHP $PHP_VERSION!" + fi + fi + echo "PHP $PHP_VERSION: available" +} + +function do_composer { + if ! has_command composer; then + echo "composer: not found" + echo "Installing composer..." + + # Note that installing from brew adds various unneeded dependencies (e.g. extra PHP). + # Largely grabbed from official install script: + # https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md + EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" + ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" + + if [[ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]]; then + rm composer-setup.php + die "Invalid composer installer checksum!" + fi + + php composer-setup.php --quiet --version="$COMPOSER_VERSION" + RESULT=$? rm composer-setup.php - die 'ERROR: Invalid composer installer checksum' + if [[ $RESULT -ne 0 ]]; then + die "Unable to install composer!" + if [[ -f composer.phar ]]; then + # Clean up. + rm composer.phar + fi + fi + sudo mkdir -p /usr/local/bin + sudo mv composer.phar /usr/local/bin/composer + if ! has_command composer; then + die "Unable to install composer!" + fi + echo "Installed composer." + fi + echo "composer: available" +} + +function do_monorepo_config { + echo "Setting up the Jetpack monorepo tooling..." + pnpm install + composer install + pnpm jetpack cli link &>/dev/null + if ! command -v jetpack &>/dev/null; then + warn 'Failed to link Jetpack CLI. The `jetpack` command will be unavailable.' + warn 'You can still use `pnpm jetpack` or set up an alias as desired.' fi +} - php composer-setup.php --version=$COMPOSER_VERSION --quiet - RESULT=$? - rm composer-setup.php - sudo mkdir -p /usr/local/bin - sudo mv composer.phar /usr/local/bin/composer +if [[ $1 ]]; then + usage fi -# Setup the Jetpack CLI -info "Setting up the Jetpack CLI" -pnpm install -pnpm jetpack cli link -if ! command -v jetpack &>/dev/null; then - warn 'Failed to link Jetpack CLI. The `jetpack` command will be unavailable.' - warn 'Likely this is because `pnpm setup` has not been run successfully. You may use `pnpm jetpack` from within the monorepo checkout instead.' -fi -pnpm jetpack install --root - -success "Installation complete. You may need to restart your terminal for changes to take effect. Then you can run tools/check-development-environment.sh to make sure everything installed correctly." - -# Reset the terminal so it picks up the changes. -if [[ "$SHELL" == "/bin/zsh" ]]; then - info "Refreshing terminal" - exec zsh -elif [[ "$SHELL" == "/bin/bash" ]]; then - info "Refreshing terminal" - exec bash -else - info "Note: You may have to restart your terminal for monorepo tools to work properly." -fi +do_system +do_basics +do_homebrew +do_nvm +do_node +do_bash +do_jq +do_pnpm + +# Get repo-preferred versions +. .github/versions.sh +do_php +do_composer + +echo +do_monorepo_config + +echo +echo "Installation complete. You will need to restart your terminal for changes" +echo "to take effect. You can then run ./tools/check-development-environment.sh" +echo "to make sure everything installed correctly." From 0fac46b1f80024cf3ae92b20444a0eea10ca40bc Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:36:36 -0600 Subject: [PATCH 02/18] Remove Linux support --- tools/install-monorepo.sh | 63 +++++++-------------------------------- 1 file changed, 10 insertions(+), 53 deletions(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 8826b83f63fd1..062e079d2b96c 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -23,58 +23,27 @@ function has_command { return $? } -# Check if we're on Mac or Linux; bail if we're not. +# Check if we're on macOS; bail if we're not. function do_system { - OS="$(uname)" - if [[ "$OS" != "Linux" && "$OS" != "Darwin" ]]; then - die "Installer script is only supported on macOS and Linux." - elif [[ "$(uname -m)" == "aarch64" ]]; then - # Homebrew doesn't support Linux on ARM, so gate the installer as well. - die "Linux on ARM is unsupported." + if [[ "$(uname)" != "Darwin" ]]; then + die "Installer script is only supported on macOS." fi - echo "Valid OS: $OS" + echo "Valid OS: macOS (Darwin)" } -# Checks for build-essential (Linux), git, and curl. +# Checks for git and curl. function do_basics { - if [[ "$OS" == "Linux" ]]; then - if ! has_command apt; then - # Effectively only support Debian. - die "Installer script requires 'apt' to ensure build-essential package is installed." - fi - - sudo apt update - if [[ $(dpkg-query -W --showformat='${db:Status-Status}' build-essential 2>/dev/null) != 'installed' ]]; then - echo "build-essential: not found" - echo "Installing build-essential..." - sudo apt install build-essential || die "Unable to install build-essential!" - echo "Installed build-essential." - fi - echo "build-essential: available" - fi # Check for curl and git if ! has_command git; then echo "git: not found" - if [[ "$OS" == "Linux" ]]; then - echo "Installing git..." - sudo apt install git || die "Unable to install git!" - echo "Installed git." - else - die "Installer script requires git to be installed." - fi + die "Installer script requires git to be installed." fi echo "git: available" if ! has_command curl; then echo "curl: not found" - if [[ "$OS" == "Linux" ]]; then - echo "Installing curl..." - sudo apt install curl || die "Unable to install curl!" - echo "Installed curl." - else - die "Installer script requires curl to be installed." - fi + die "Installer script requires curl to be installed." fi echo "curl: available" } @@ -85,11 +54,7 @@ function do_homebrew { echo "brew: not found" echo "Installing brew..." /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || die "Unable to install brew!" - if [[ "$OS" == "Linux" ]]; then - HOMEBREW_PREFIX="/home/linuxbrew/.linuxbrew" - else - HOMEBREW_PREFIX="/opt/homebrew" - fi + HOMEBREW_PREFIX="/opt/homebrew" # Add brew env to current script for use later. eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)" @@ -104,18 +69,10 @@ function do_homebrew { # https://github.com/Homebrew/install/blob/master/install.sh case "${SHELL}" in */bash*) - if [[ "$OS" == "Linux" ]]; then - shell_rcfile="${HOME}/.bashrc" - else - shell_rcfile="${HOME}/.bash_profile" - fi + shell_rcfile="${HOME}/.bash_profile" ;; */zsh*) - if [[ "$OS" == "Linux" ]]; then - shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zshrc" - else - shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zprofile" - fi + shell_rcfile="${ZDOTDIR:-"${HOME}"}/.zprofile" ;; */fish*) shell_rcfile="${HOME}/.config/fish/config.fish" From 6c6762624c75bdd3a33fcd6def2d312203641e51 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:38:24 -0600 Subject: [PATCH 03/18] set -eo pipefail --- tools/install-monorepo.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 062e079d2b96c..80b4c7cd83ff1 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -eo pipefail # Start in the monorepo root folder. root_dir="$(dirname "${BASH_SOURCE[0]}")/.." From e1023d2b67ff008d8f00d0ca472004afa73a2a68 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:39:29 -0600 Subject: [PATCH 04/18] =?UTF-8?q?.=20=E2=86=92=20source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/install-monorepo.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 80b4c7cd83ff1..b2a073155441d 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -6,7 +6,7 @@ root_dir="$(dirname "${BASH_SOURCE[0]}")/.." cd "$root_dir" # Source some helper functions. -. tools/includes/chalk-lite.sh +source tools/includes/chalk-lite.sh # Print help and exit. function usage { @@ -111,9 +111,9 @@ function do_nvm { if [[ -f "$(brew --prefix nvm)/nvm.sh" ]]; then # Sometimes nvm is installed via brew, which is an unsupported install # route, and uses a wrapper helper script. - . "$(brew --prefix nvm)/nvm.sh" + source "$(brew --prefix nvm)/nvm.sh" else - export NVM_DIR="$HOME/.nvm" && . "$NVM_DIR"/nvm.sh --no-use + export NVM_DIR="$HOME/.nvm" && source "$NVM_DIR"/nvm.sh --no-use fi if [[ v$(nvm --version) != "$good_nvm_version" ]]; then @@ -124,7 +124,7 @@ function do_nvm { curl -s -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$good_nvm_version/install.sh" | bash - &>/dev/null && # Source again to get latest shell functions - . "$NVM_DIR/nvm.sh" --no-use + source "$NVM_DIR/nvm.sh" --no-use # Something's wrong, so abort. if [[ "v$(nvm --version)" != "$good_nvm_version" ]]; then @@ -138,7 +138,7 @@ function do_nvm { curl -s -o- https://raw.githubusercontent.com/nvm-sh/nvm/$good_nvm_version/install.sh | bash - &>/dev/null && # Source to get latest shell functions - export NVM_DIR="$HOME"/.nvm && . "$NVM_DIR"/nvm.sh --no-use + export NVM_DIR="$HOME"/.nvm && source "$NVM_DIR"/nvm.sh --no-use # Something's wrong, so abort. if ! has_command nvm; then @@ -305,7 +305,7 @@ do_jq do_pnpm # Get repo-preferred versions -. .github/versions.sh +source .github/versions.sh do_php do_composer From adfe291c604ca682ee4465cee108c4b8347c7cb5 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:16:44 -0600 Subject: [PATCH 05/18] Document has_command params Co-authored-by: Brad Jorsch --- tools/install-monorepo.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index b2a073155441d..913dae7254ecf 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -19,6 +19,9 @@ function usage { } # Wrapper to check for a command silently. +# +# $1 - Command to check for +# Returns: 0 if the command exists, non-zero if not. function has_command { command -v "$1" &>/dev/null return $? From 51df6a65f661672fe293154e77d65fc069399527 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:28:53 -0600 Subject: [PATCH 06/18] Oops! Co-authored-by: Brad Jorsch --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 913dae7254ecf..19bbf0633923d 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -61,7 +61,7 @@ function do_homebrew { HOMEBREW_PREFIX="/opt/homebrew" # Add brew env to current script for use later. - eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)" + eval "$(${HOMEBREW_PREFIX}/bin/brew shellenv)" if ! has_command brew; then die "Unable to install brew!" From 3120a05eaf2c234c5d9ab0eab58d107f8ec646ff Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:34:41 -0600 Subject: [PATCH 07/18] Sigh... Co-authored-by: Brad Jorsch --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 19bbf0633923d..2e34fe501d70a 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -88,7 +88,7 @@ function do_homebrew { # Add brew init to shell rc file. if ! grep -qs "eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"" "${shell_rcfile}"; then - (echo; echo 'eval "\$(${HOMEBREW_PREFIX}/bin/brew shellenv)"') >> ${shell_rcfile} + (echo; echo "eval \"\$(${HOMEBREW_PREFIX}/bin/brew shellenv)\"") >> "${shell_rcfile}" fi else From 67e0656de354bf1dce403d1de26303f7086bee45 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:53:13 -0600 Subject: [PATCH 08/18] Missed quotes Co-authored-by: Brad Jorsch --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 2e34fe501d70a..f3183693ffc8f 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -138,7 +138,7 @@ function do_nvm { else echo "nvm: not found" info "Installing nvm..." - curl -s -o- https://raw.githubusercontent.com/nvm-sh/nvm/$good_nvm_version/install.sh | bash - &>/dev/null && + curl -s -o- "https://raw.githubusercontent.com/nvm-sh/nvm/$good_nvm_version/install.sh" | bash - &>/dev/null && # Source to get latest shell functions export NVM_DIR="$HOME"/.nvm && source "$NVM_DIR"/nvm.sh --no-use From c59562bbaf0dadc045d14912b21d95449a4d6393 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:53:40 -0600 Subject: [PATCH 09/18] Typo in comment Co-authored-by: Brad Jorsch --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index f3183693ffc8f..a9042bc38246a 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -109,7 +109,7 @@ function do_nvm { good_nvm_version=$(basename $(curl -fs -o/dev/null -w %{redirect_url} https://github.com/nvm-sh/nvm/releases/latest)) if [[ -f "$HOME"/.nvm/nvm.sh ]] ; then - # Since nvm really several shell functions, and isn't in the environment + # Since nvm is really several shell functions, and isn't in the environment # initially, we need to source it. if [[ -f "$(brew --prefix nvm)/nvm.sh" ]]; then # Sometimes nvm is installed via brew, which is an unsupported install From 5779a304930e6e9247aae602c8de850faabb9cc6 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:57:33 -0600 Subject: [PATCH 10/18] Typo --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index a9042bc38246a..475ed58728da0 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -173,7 +173,7 @@ function do_node { nvm install # Something's wrong, so abort. if ! nvm list node | grep -q "$good_node_version"; then - die "Unable to needed version of node!" + die "Unable to install needed version of node!" fi echo "Correct version of node installed." fi From 16e16c5bd248627d3c99d67827957e227fa8ff0b Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:58:35 -0600 Subject: [PATCH 11/18] Copy/paste typo --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 475ed58728da0..6de57b634b145 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -202,7 +202,7 @@ function do_jq { echo "Installing jq..." brew install jq &>/dev/null if ! has_command jq; then - die "Unable to install newer version of jq!" + die "Unable to install jq!" fi echo "Installed jq." fi From 9cd16979d8f0aea358d6b0b699b63abf16c42b7f Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:00:35 -0600 Subject: [PATCH 12/18] Adjust comparison logic Co-authored-by: Brad Jorsch --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 6de57b634b145..360127729238b 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -227,7 +227,7 @@ function do_pnpm { } function do_php { - if ! has_command php || [[ $(php -r "echo version_compare(PHP_VERSION,'$PHP_VERSION');") -eq -1 ]]; then + if ! has_command php || php -r "exit( version_compare( PHP_VERSION, '$PHP_VERSION', '>=' ) ? 0 : 1 );"; then echo "PHP $PHP_VERSION: not found" # Note that we can't use grep -v, as it's prematurely terminated. From cc42fbc3ff2a55714bbdbd395907a3a31981e445 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:04:23 -0600 Subject: [PATCH 13/18] Comment typo --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 360127729238b..0b4ac5f09d201 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -230,7 +230,7 @@ function do_php { if ! has_command php || php -r "exit( version_compare( PHP_VERSION, '$PHP_VERSION', '>=' ) ? 0 : 1 );"; then echo "PHP $PHP_VERSION: not found" - # Note that we can't use grep -v, as it's prematurely terminated. + # Note that we can't use grep -q, as it's prematurely terminated. if ! $(brew list|grep php@$PHP_VERSION >/dev/null); then echo "Installing PHP $PHP_VERSION..." # Don't hide output, as this can take some time... From 4298b1ca9273330c672ea25635dc43534bd61f01 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:29:13 -0600 Subject: [PATCH 14/18] Install preferred pnpm version if not already installed --- tools/install-monorepo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 0b4ac5f09d201..7a0bdc075007a 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -213,7 +213,7 @@ function do_pnpm { if ! has_command pnpm; then echo "pnpm: not found" echo "Installing pnpm..." - curl -fsSL https://get.pnpm.io/install.sh | sh - &>/dev/null + curl -fsSL https://get.pnpm.io/install.sh | env PNPM_VERSION="$PNPM_VERSION" sh - &>/dev/null # Make sure pnpm is in one's path export PNPM_HOME="$("$SHELL" -i -c 'echo "$PNPM_HOME"')" @@ -305,10 +305,10 @@ do_nvm do_node do_bash do_jq -do_pnpm # Get repo-preferred versions source .github/versions.sh +do_pnpm do_php do_composer From d1d6ca6bb675302186d81146d4a028db98809f3c Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:34:57 -0600 Subject: [PATCH 15/18] Fix PHP version check logic --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 7a0bdc075007a..7884dae511368 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -227,7 +227,7 @@ function do_pnpm { } function do_php { - if ! has_command php || php -r "exit( version_compare( PHP_VERSION, '$PHP_VERSION', '>=' ) ? 0 : 1 );"; then + if ! has_command php || php -r "exit( version_compare( PHP_VERSION, '$PHP_VERSION', '<' ) ? 0 : 1 );"; then echo "PHP $PHP_VERSION: not found" # Note that we can't use grep -q, as it's prematurely terminated. From 6a6a1b47675bfa45865844098484e352a3d77ec7 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:24:22 -0600 Subject: [PATCH 16/18] No need for var --- tools/install-monorepo.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 7884dae511368..5353dca6ad555 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -2,8 +2,7 @@ set -eo pipefail # Start in the monorepo root folder. -root_dir="$(dirname "${BASH_SOURCE[0]}")/.." -cd "$root_dir" +cd "$(dirname "${BASH_SOURCE[0]}")/.." # Source some helper functions. source tools/includes/chalk-lite.sh From c85c9a6d55dbda97d6263e5872d8d1e8c72a69c3 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:28:18 -0600 Subject: [PATCH 17/18] Make var local and improve readability Co-authored-by: Brad Jorsch --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 5353dca6ad555..279514b7a5c54 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -105,7 +105,7 @@ function do_homebrew { function do_nvm { # Get latest nvm version. # Based on this: https://stackoverflow.com/a/71896712 - good_nvm_version=$(basename $(curl -fs -o/dev/null -w %{redirect_url} https://github.com/nvm-sh/nvm/releases/latest)) + local good_nvm_version=$(basename "$(curl -fs -o/dev/null -w '%{redirect_url}' https://github.com/nvm-sh/nvm/releases/latest)") if [[ -f "$HOME"/.nvm/nvm.sh ]] ; then # Since nvm is really several shell functions, and isn't in the environment From fbe76a8da283ff9fd6555b48fd6b5c7a3941731b Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Thu, 28 Mar 2024 09:41:47 -0600 Subject: [PATCH 18/18] Update second PHP test --- tools/install-monorepo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install-monorepo.sh b/tools/install-monorepo.sh index 279514b7a5c54..17763456f68a6 100755 --- a/tools/install-monorepo.sh +++ b/tools/install-monorepo.sh @@ -238,7 +238,7 @@ function do_php { echo "Linking already-installed PHP $PHP_VERSION..." fi brew link --overwrite php@"$PHP_VERSION" &>/dev/null - if ! has_command php || [[ $(php -r "echo version_compare(PHP_VERSION,'$PHP_VERSION');") -eq -1 ]]; then + if ! has_command php || php -r "exit( version_compare( PHP_VERSION, '$PHP_VERSION', '<' ) ? 0 : 1 );"; then die "Unable to install PHP $PHP_VERSION!" fi fi