From eca3f117badb9ee91d74d7978aa5f4d49a1e9bfd Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Mon, 9 Jan 2017 12:31:28 +0000 Subject: [PATCH 01/11] Update with comments in the code --- Library/Homebrew/utils/shell_env.sh | 15 ++++++ bin/brew | 80 ++++++++++++++++++++++++++++- 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100755 Library/Homebrew/utils/shell_env.sh diff --git a/Library/Homebrew/utils/shell_env.sh b/Library/Homebrew/utils/shell_env.sh new file mode 100755 index 0000000000..fc7e1c9726 --- /dev/null +++ b/Library/Homebrew/utils/shell_env.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set +o posix + +IFS="=" + +while read -r key value +do + export "$key=$value" +done < /tmp/homebrew-env + +# Need to reset IFS to default value for later shell functions like 'printf -v HOMEBREW_MACOS_VERSION_NUMERIC ...' to work +unset IFS + +# HOMEBREW_LIBRARY will have been readded above having been added originally in 'bin/brew' +source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" diff --git a/bin/brew b/bin/brew index 593043f9f2..846758c30a 100755 --- a/bin/brew +++ b/bin/brew @@ -44,4 +44,82 @@ fi HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library" -source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" +# Refactor of code from '/Library/Homebrew/brew.sh' +export HOMEBREW_BREW_FILE +export HOMEBREW_PREFIX +export HOMEBREW_REPOSITORY +export HOMEBREW_LIBRARY + +# Set to system default value to avoid any possible later mis-direction based on the user's shell env +export PATH=/usr/bin:/bin:/usr/sbin:/sbin + +# ------------------------------------------------------------------------------------------------------------------------- +# Setting 'HOMEBREW_OLD_ENV' would be removed with 'env -i' so would need to be passed as another arg to the 'env -i' cmd. + +# The resulting '/tmp/homebrew-env' for an update prior to install was +# (which may run into bash arg limits, so I suggest keeping the tmp file): + +#HOMEBREW_PROCESSOR=Intel +#HOMEBREW_DEV_CMD_RUN=1 +#HOMEBREW_USER_AGENT=Homebrew/1.X.Y (Macintosh; Intel macOS 10.6.8) +#HOMEBREW_UPDATE_BEFORE=f7bccee2145547d21b2629cab8b5fddff3299bda +#HOMEBREW_LIBRARY=/usr/local/Homebrew/Library +#HOMEBREW_COMMAND_DEPTH=2 +#TERM=xterm-color +#HOMEBREW_OS_VERSION=macOS 10.6.8 +#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_BUNDLE=a32e4559ef653c648426a4d52abdb570db09fccf +#HOMEBREW_REPOSITORY=/usr/local/Homebrew +#HOMEBREW_ENABLE_AUTO_UPDATE_MIGRATION=1 +#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE=350aa1a6b9f5d31dabb9d2cfeeffb960a64509e6 +#HOMEBREW_GIT_CONFIG_FILE=/usr/local/Homebrew/.git/config +#HOMEBREW_RUBY_PATH=/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/current/bin/ruby +#HOMEBREW_NO_AUTO_UPDATE=1 +#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE=9bc16f465e1d7697426dd6dad685d161f1f4ee1d +#HOMEBREW_ANALYTICS_USER_UUID=B2E8D13A-443F-4686-B946-DE6C797064D7 +#HOMEBREW_CACHE=/Users/doug/Library/Caches/Homebrew +#HOMEBREW_USER_AGENT_CURL=Homebrew/1.X.Y (Macintosh; Intel macOS 10.6.8) curl/7.52.1 +#PATH=/usr/bin:/bin:/usr/sbin:/sbin +#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_VERSIONS=c94a1b18d5c2c198b4be302b604dd0c845a4344b +#HOMEBREW_UPDATE_BEFORE_CASKROOM_HOMEBREW_CASK=258fd55c9c3d4fc3699753f363927c51a6fe9c18 +#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_BUNDLE=a32e4559ef653c648426a4d52abdb570db09fccf +#HOMEBREW_BREW_FILE=/usr/local/bin/brew +#HOMEBREW_MACOS_VERSION=10.6.8 +#HOMEBREW_ANALYTICS_ID=UA-76679469-1 +#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_VERSIONS=c94a1b18d5c2c198b4be302b604dd0c845a4344b +#HOMEBREW_UPDATE_AFTER_CASKROOM_HOMEBREW_CASK=258fd55c9c3d4fc3699753f363927c51a6fe9c18 +#HOMEBREW_PRODUCT=Homebrew +#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_DUPES=25fa9b53f943de00fc83c5a85fa0d29180eb1030 +#HOME=/Users/doug +#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_DUPES=25fa9b53f943de00fc83c5a85fa0d29180eb1030 +#HOMEBREW_PREFIX=/usr/local +#HOMEBREW_VERSION=>1.1.0 (no git repository) +#HOMEBREW_CELLAR=/usr/local/Cellar +#HOMEBREW_CURL=/usr/local/opt/curl/bin/curl +#HOMEBREW_UPDATE_PREINSTALL=1 +#HOMEBREW_NO_UPDATE_CLEANUP=1 +#HOMEBREW_UPDATE_AFTER=f7bccee2145547d21b2629cab8b5fddff3299bda +#HOMEBREW_SYSTEM=Macintosh + +# from an original of: + +#HOMEBREW_LIBRARY=/usr/local/Homebrew/Library +#TERM=xterm-color +#HOMEBREW_REPOSITORY=/usr/local/Homebrew +#PATH=/usr/bin:/bin:/usr/sbin:/sbin +#HOMEBREW_BREW_FILE=/usr/local/bin/brew +#HOME=/Users/doug +#HOMEBREW_PREFIX=/usr/local +# ------------------------------------------------------------------------------------------------------------------------- + +if [[ -n "$HOMEBREW_ENV_FILTERING" ]] +then + echo "----- HOMEBREW_ENV_FILTERING set -----" + + # Needed TERM to prevent "tput: No value for $TERM and no -T specified" + env | grep -E '^(HOMEBREW.*|HOME|PATH|TERM)=.*$' > /tmp/homebrew-env + env -i "$HOMEBREW_LIBRARY/Homebrew/utils/shell_env.sh" "$@" +else + echo "----- HOMEBREW_ENV_FILTERING NOT set! -----" + + source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" +fi From 90b3f9b19a066b14cfa1d67923ca5932db27e414 Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Fri, 30 Dec 2016 19:46:29 +0000 Subject: [PATCH 02/11] fixup --- Library/Homebrew/brew.sh | 19 +++++++++++++++++-- bin/brew | 4 ---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 92953001d3..14de020659 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -76,7 +76,11 @@ export GEM_OLD_PATH="$GEM_PATH" # Users may have these set, pointing the system Ruby # at non-system gem paths unset GEM_HOME -unset GEM_PATH + +if [[ -z "$HOMEBREW_WHICH_RUBY" ]] +then + unset GEM_PATH +fi # Users may have this set, injecting arbitrary environment changes into # bash processes inside builds @@ -267,6 +271,12 @@ access to all bottles." EOS fi +if [[ -z "$HOMEBREW_ENV_PRUNED" ]] +then + source "$HOMEBREW_LIBRARY/Homebrew/utils/shell_env.sh" + prune-shell-env +fi + # Hide shellcheck complaint: # shellcheck source=/dev/null source "$HOMEBREW_LIBRARY/Homebrew/utils/analytics.sh" @@ -336,7 +346,12 @@ else # shellcheck source=/dev/null source "$HOMEBREW_LIBRARY/Homebrew/utils/ruby.sh" setup-ruby-path - + + if [[ -n "$HOMEBREW_WHICH_RUBY" ]] + then + export HOMEBREW_RUBY_PATH="$(which ruby)" + fi + # Unshift command back into argument list (unless argument list was empty). [[ "$HOMEBREW_ARG_COUNT" -gt 0 ]] && set -- "$HOMEBREW_COMMAND" "$@" { update-preinstall; exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/Homebrew/brew.rb" "$@"; } diff --git a/bin/brew b/bin/brew index 846758c30a..5fe7f892c6 100755 --- a/bin/brew +++ b/bin/brew @@ -113,13 +113,9 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin if [[ -n "$HOMEBREW_ENV_FILTERING" ]] then - echo "----- HOMEBREW_ENV_FILTERING set -----" - # Needed TERM to prevent "tput: No value for $TERM and no -T specified" env | grep -E '^(HOMEBREW.*|HOME|PATH|TERM)=.*$' > /tmp/homebrew-env env -i "$HOMEBREW_LIBRARY/Homebrew/utils/shell_env.sh" "$@" else - echo "----- HOMEBREW_ENV_FILTERING NOT set! -----" - source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" fi From e78b31905df68309af65347a4ed2338f87942854 Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Tue, 3 Jan 2017 22:23:10 +0000 Subject: [PATCH 03/11] fixup --- Library/Homebrew/brew.sh | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 14de020659..e93d3de75f 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -73,19 +73,6 @@ fi export GEM_OLD_HOME="$GEM_HOME" export GEM_OLD_PATH="$GEM_PATH" -# Users may have these set, pointing the system Ruby -# at non-system gem paths -unset GEM_HOME - -if [[ -z "$HOMEBREW_WHICH_RUBY" ]] -then - unset GEM_PATH -fi - -# Users may have this set, injecting arbitrary environment changes into -# bash processes inside builds -unset BASH_ENV - HOMEBREW_SYSTEM="$(uname -s)" case "$HOMEBREW_SYSTEM" in Darwin) HOMEBREW_MACOS="1" ;; @@ -271,12 +258,6 @@ access to all bottles." EOS fi -if [[ -z "$HOMEBREW_ENV_PRUNED" ]] -then - source "$HOMEBREW_LIBRARY/Homebrew/utils/shell_env.sh" - prune-shell-env -fi - # Hide shellcheck complaint: # shellcheck source=/dev/null source "$HOMEBREW_LIBRARY/Homebrew/utils/analytics.sh" @@ -347,11 +328,6 @@ else source "$HOMEBREW_LIBRARY/Homebrew/utils/ruby.sh" setup-ruby-path - if [[ -n "$HOMEBREW_WHICH_RUBY" ]] - then - export HOMEBREW_RUBY_PATH="$(which ruby)" - fi - # Unshift command back into argument list (unless argument list was empty). [[ "$HOMEBREW_ARG_COUNT" -gt 0 ]] && set -- "$HOMEBREW_COMMAND" "$@" { update-preinstall; exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/Homebrew/brew.rb" "$@"; } From 0bb0228962cebcce05ab966618945621ba144fcb Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Sun, 12 Feb 2017 14:31:37 +0000 Subject: [PATCH 04/11] Presumably the "env -I" was a typo for "env -i" Just sourcing brew.sh causes the "Example usage" msg due to lacking command args but changing the last line of your suggestion to: /bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@" worked. If all of the 'HOMEBREW.*' vars, that other parts of the system require, are only added in brew.sh then your suggestion is cleaner. --- Library/Homebrew/utils/shell_env.sh | 15 ------ bin/brew | 79 ++++------------------------- 2 files changed, 9 insertions(+), 85 deletions(-) delete mode 100755 Library/Homebrew/utils/shell_env.sh diff --git a/Library/Homebrew/utils/shell_env.sh b/Library/Homebrew/utils/shell_env.sh deleted file mode 100755 index fc7e1c9726..0000000000 --- a/Library/Homebrew/utils/shell_env.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set +o posix - -IFS="=" - -while read -r key value -do - export "$key=$value" -done < /tmp/homebrew-env - -# Need to reset IFS to default value for later shell functions like 'printf -v HOMEBREW_MACOS_VERSION_NUMERIC ...' to work -unset IFS - -# HOMEBREW_LIBRARY will have been readded above having been added originally in 'bin/brew' -source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" diff --git a/bin/brew b/bin/brew index 5fe7f892c6..b5fb9af047 100755 --- a/bin/brew +++ b/bin/brew @@ -44,78 +44,17 @@ fi HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library" -# Refactor of code from '/Library/Homebrew/brew.sh' -export HOMEBREW_BREW_FILE -export HOMEBREW_PREFIX -export HOMEBREW_REPOSITORY -export HOMEBREW_LIBRARY - -# Set to system default value to avoid any possible later mis-direction based on the user's shell env -export PATH=/usr/bin:/bin:/usr/sbin:/sbin - -# ------------------------------------------------------------------------------------------------------------------------- -# Setting 'HOMEBREW_OLD_ENV' would be removed with 'env -i' so would need to be passed as another arg to the 'env -i' cmd. - -# The resulting '/tmp/homebrew-env' for an update prior to install was -# (which may run into bash arg limits, so I suggest keeping the tmp file): - -#HOMEBREW_PROCESSOR=Intel -#HOMEBREW_DEV_CMD_RUN=1 -#HOMEBREW_USER_AGENT=Homebrew/1.X.Y (Macintosh; Intel macOS 10.6.8) -#HOMEBREW_UPDATE_BEFORE=f7bccee2145547d21b2629cab8b5fddff3299bda -#HOMEBREW_LIBRARY=/usr/local/Homebrew/Library -#HOMEBREW_COMMAND_DEPTH=2 -#TERM=xterm-color -#HOMEBREW_OS_VERSION=macOS 10.6.8 -#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_BUNDLE=a32e4559ef653c648426a4d52abdb570db09fccf -#HOMEBREW_REPOSITORY=/usr/local/Homebrew -#HOMEBREW_ENABLE_AUTO_UPDATE_MIGRATION=1 -#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE=350aa1a6b9f5d31dabb9d2cfeeffb960a64509e6 -#HOMEBREW_GIT_CONFIG_FILE=/usr/local/Homebrew/.git/config -#HOMEBREW_RUBY_PATH=/usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/current/bin/ruby -#HOMEBREW_NO_AUTO_UPDATE=1 -#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE=9bc16f465e1d7697426dd6dad685d161f1f4ee1d -#HOMEBREW_ANALYTICS_USER_UUID=B2E8D13A-443F-4686-B946-DE6C797064D7 -#HOMEBREW_CACHE=/Users/doug/Library/Caches/Homebrew -#HOMEBREW_USER_AGENT_CURL=Homebrew/1.X.Y (Macintosh; Intel macOS 10.6.8) curl/7.52.1 -#PATH=/usr/bin:/bin:/usr/sbin:/sbin -#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_VERSIONS=c94a1b18d5c2c198b4be302b604dd0c845a4344b -#HOMEBREW_UPDATE_BEFORE_CASKROOM_HOMEBREW_CASK=258fd55c9c3d4fc3699753f363927c51a6fe9c18 -#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_BUNDLE=a32e4559ef653c648426a4d52abdb570db09fccf -#HOMEBREW_BREW_FILE=/usr/local/bin/brew -#HOMEBREW_MACOS_VERSION=10.6.8 -#HOMEBREW_ANALYTICS_ID=UA-76679469-1 -#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_VERSIONS=c94a1b18d5c2c198b4be302b604dd0c845a4344b -#HOMEBREW_UPDATE_AFTER_CASKROOM_HOMEBREW_CASK=258fd55c9c3d4fc3699753f363927c51a6fe9c18 -#HOMEBREW_PRODUCT=Homebrew -#HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_DUPES=25fa9b53f943de00fc83c5a85fa0d29180eb1030 -#HOME=/Users/doug -#HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_DUPES=25fa9b53f943de00fc83c5a85fa0d29180eb1030 -#HOMEBREW_PREFIX=/usr/local -#HOMEBREW_VERSION=>1.1.0 (no git repository) -#HOMEBREW_CELLAR=/usr/local/Cellar -#HOMEBREW_CURL=/usr/local/opt/curl/bin/curl -#HOMEBREW_UPDATE_PREINSTALL=1 -#HOMEBREW_NO_UPDATE_CLEANUP=1 -#HOMEBREW_UPDATE_AFTER=f7bccee2145547d21b2629cab8b5fddff3299bda -#HOMEBREW_SYSTEM=Macintosh - -# from an original of: - -#HOMEBREW_LIBRARY=/usr/local/Homebrew/Library -#TERM=xterm-color -#HOMEBREW_REPOSITORY=/usr/local/Homebrew -#PATH=/usr/bin:/bin:/usr/sbin:/sbin -#HOMEBREW_BREW_FILE=/usr/local/bin/brew -#HOME=/Users/doug -#HOMEBREW_PREFIX=/usr/local -# ------------------------------------------------------------------------------------------------------------------------- - if [[ -n "$HOMEBREW_ENV_FILTERING" ]] then - # Needed TERM to prevent "tput: No value for $TERM and no -T specified" - env | grep -E '^(HOMEBREW.*|HOME|PATH|TERM)=.*$' > /tmp/homebrew-env - env -i "$HOMEBREW_LIBRARY/Homebrew/utils/shell_env.sh" "$@" + env -i \ + HOME="$HOME" \ + PATH=/usr/bin:/bin:/usr/sbin:/sbin \ + TERM="$TERM" \ + HOMEBREW_BREW_FILE="$HOMEBREW_BREW_FILE" \ + HOMEBREW_PREFIX="$HOMEBREW_PREFIX" \ + HOMEBREW_REPOSITORY="$HOMEBREW_REPOSITORY" \ + HOMEBREW_LIBRARY="$HOMEBREW_LIBRARY" \ + /bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@" else source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" fi From adc43466a6c3d807344e0350e8d1776c4bd78a31 Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Sun, 12 Feb 2017 15:26:59 +0000 Subject: [PATCH 05/11] Reverting 'brew.sh' to origin/master to resolve conflict --- Library/Homebrew/brew.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index e93d3de75f..81a52f4744 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -73,6 +73,18 @@ fi export GEM_OLD_HOME="$GEM_HOME" export GEM_OLD_PATH="$GEM_PATH" +# Users may have these set, pointing the system Ruby +# at non-system gem paths +unset GEM_HOME +unset GEM_PATH + +# Users may have this set, injecting arbitrary environment changes into +# bash processes inside builds +unset BASH_ENV + +# Users may have this set, breaking grep's output. +unset GREP_OPTIONS + HOMEBREW_SYSTEM="$(uname -s)" case "$HOMEBREW_SYSTEM" in Darwin) HOMEBREW_MACOS="1" ;; @@ -327,7 +339,7 @@ else # shellcheck source=/dev/null source "$HOMEBREW_LIBRARY/Homebrew/utils/ruby.sh" setup-ruby-path - + # Unshift command back into argument list (unless argument list was empty). [[ "$HOMEBREW_ARG_COUNT" -gt 0 ]] && set -- "$HOMEBREW_COMMAND" "$@" { update-preinstall; exec "$HOMEBREW_RUBY_PATH" -W0 "$HOMEBREW_LIBRARY/Homebrew/brew.rb" "$@"; } From 5d1576784a5603662ca9910eb97c948e833f35c9 Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Sun, 19 Feb 2017 02:12:46 +0000 Subject: [PATCH 06/11] Mechanism to dynamically add HOMEBREW.* vars to 'env -i' command string in 'bin/brew' --- Library/Homebrew/utils/homebrew_vars.rb | 11 +++++++++++ bin/brew | 23 +++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100755 Library/Homebrew/utils/homebrew_vars.rb diff --git a/Library/Homebrew/utils/homebrew_vars.rb b/Library/Homebrew/utils/homebrew_vars.rb new file mode 100755 index 0000000000..057633b776 --- /dev/null +++ b/Library/Homebrew/utils/homebrew_vars.rb @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby + +ENV.keys.each do |key| + if key =~ /^HOMEBREW.*/ + # Remove any HOMEBREW.* vars containing white-space which causes a problem for "env -i" command via string. + # + # (Any user supplied HOMEBREW.* vars with valid white-space need to be hard-coded in 'bin/brew') + # + puts "#{key}=#{ENV[key]}" unless ENV[key].split(' ').length > 1 + end +end diff --git a/bin/brew b/bin/brew index b5fb9af047..710ef7e5c3 100755 --- a/bin/brew +++ b/bin/brew @@ -46,15 +46,22 @@ HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library" if [[ -n "$HOMEBREW_ENV_FILTERING" ]] then - env -i \ - HOME="$HOME" \ + + homebrew_vars=$("$HOMEBREW_LIBRARY/Homebrew/utils/homebrew_vars.rb") + + cmd_str="/usr/bin/env -i \ + HOME=$HOME \ PATH=/usr/bin:/bin:/usr/sbin:/sbin \ - TERM="$TERM" \ - HOMEBREW_BREW_FILE="$HOMEBREW_BREW_FILE" \ - HOMEBREW_PREFIX="$HOMEBREW_PREFIX" \ - HOMEBREW_REPOSITORY="$HOMEBREW_REPOSITORY" \ - HOMEBREW_LIBRARY="$HOMEBREW_LIBRARY" \ - /bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@" + TERM=$TERM \ + HOMEBREW_BREW_FILE=$HOMEBREW_BREW_FILE \ + HOMEBREW_PREFIX=$HOMEBREW_PREFIX \ + HOMEBREW_REPOSITORY=$HOMEBREW_REPOSITORY \ + HOMEBREW_LIBRARY=$HOMEBREW_LIBRARY \ + $homebrew_vars \ + /bin/bash $HOMEBREW_LIBRARY/Homebrew/brew.sh $@" + + command $cmd_str + else source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" fi From ac4c9d13240f466915301556fd1aa57e003ee34a Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Thu, 23 Feb 2017 15:21:46 +0000 Subject: [PATCH 07/11] Update from comments --- bin/brew | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/bin/brew b/bin/brew index 710ef7e5c3..8d7730d6b6 100755 --- a/bin/brew +++ b/bin/brew @@ -46,22 +46,25 @@ HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library" if [[ -n "$HOMEBREW_ENV_FILTERING" ]] then + PATH="/usr/bin:/bin:/usr/sbin:/sbin" - homebrew_vars=$("$HOMEBREW_LIBRARY/Homebrew/utils/homebrew_vars.rb") + export HOMEBREW_BREW_FILE + export HOMEBREW_PREFIX + export HOMEBREW_REPOSITORY + export HOMEBREW_LIBRARY - cmd_str="/usr/bin/env -i \ - HOME=$HOME \ - PATH=/usr/bin:/bin:/usr/sbin:/sbin \ - TERM=$TERM \ - HOMEBREW_BREW_FILE=$HOMEBREW_BREW_FILE \ - HOMEBREW_PREFIX=$HOMEBREW_PREFIX \ - HOMEBREW_REPOSITORY=$HOMEBREW_REPOSITORY \ - HOMEBREW_LIBRARY=$HOMEBREW_LIBRARY \ - $homebrew_vars \ - /bin/bash $HOMEBREW_LIBRARY/Homebrew/brew.sh $@" - - command $cmd_str - + execution_env=() + for key in HOME SHELL PATH TERM LOGNAME USER "${!HOMEBREW_@}" + do + # ugly, unfortunate consequence of lack of `export -p NAME` in bash's export + + # The following failed to find non exported vars on Bash 3.2.48 + [[ "$(declare -p "$key" 2>/dev/null)" =~ ^declare\ -[^\ ]*x[^\ ]*\ ]] || continue + + execution_env+=( "${key}=${!key}" ) + done + + /usr/bin/env -i "${execution_env[@]}" /bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@" else source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" fi From 9395ec4d309c1a06b90168058eacf5b55f026f37 Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Thu, 23 Feb 2017 15:32:44 +0000 Subject: [PATCH 08/11] Update based on comments (without a mutex...) --- bin/brew | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/bin/brew b/bin/brew index 8d7730d6b6..3feb0af20b 100755 --- a/bin/brew +++ b/bin/brew @@ -48,19 +48,14 @@ if [[ -n "$HOMEBREW_ENV_FILTERING" ]] then PATH="/usr/bin:/bin:/usr/sbin:/sbin" - export HOMEBREW_BREW_FILE - export HOMEBREW_PREFIX - export HOMEBREW_REPOSITORY - export HOMEBREW_LIBRARY +# export HOMEBREW_BREW_FILE +# export HOMEBREW_PREFIX +# export HOMEBREW_REPOSITORY +# export HOMEBREW_LIBRARY execution_env=() for key in HOME SHELL PATH TERM LOGNAME USER "${!HOMEBREW_@}" do - # ugly, unfortunate consequence of lack of `export -p NAME` in bash's export - - # The following failed to find non exported vars on Bash 3.2.48 - [[ "$(declare -p "$key" 2>/dev/null)" =~ ^declare\ -[^\ ]*x[^\ ]*\ ]] || continue - execution_env+=( "${key}=${!key}" ) done From 6f5913ccdd281556decc57adf85067fc29bc1950 Mon Sep 17 00:00:00 2001 From: Doug Hazell Date: Thu, 23 Feb 2017 15:36:26 +0000 Subject: [PATCH 09/11] Tidy up the latest draft --- bin/brew | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bin/brew b/bin/brew index 3feb0af20b..1ecc6f3e29 100755 --- a/bin/brew +++ b/bin/brew @@ -48,11 +48,6 @@ if [[ -n "$HOMEBREW_ENV_FILTERING" ]] then PATH="/usr/bin:/bin:/usr/sbin:/sbin" -# export HOMEBREW_BREW_FILE -# export HOMEBREW_PREFIX -# export HOMEBREW_REPOSITORY -# export HOMEBREW_LIBRARY - execution_env=() for key in HOME SHELL PATH TERM LOGNAME USER "${!HOMEBREW_@}" do From 9ce757b339d0fbda95c6dcc07d07dc33b08dad8a Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 26 Feb 2017 20:35:50 +0000 Subject: [PATCH 10/11] Remove unused utils/homebrew_vars. --- Library/Homebrew/utils/homebrew_vars.rb | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100755 Library/Homebrew/utils/homebrew_vars.rb diff --git a/Library/Homebrew/utils/homebrew_vars.rb b/Library/Homebrew/utils/homebrew_vars.rb deleted file mode 100755 index 057633b776..0000000000 --- a/Library/Homebrew/utils/homebrew_vars.rb +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env ruby - -ENV.keys.each do |key| - if key =~ /^HOMEBREW.*/ - # Remove any HOMEBREW.* vars containing white-space which causes a problem for "env -i" command via string. - # - # (Any user supplied HOMEBREW.* vars with valid white-space need to be hard-coded in 'bin/brew') - # - puts "#{key}=#{ENV[key]}" unless ENV[key].split(' ').length > 1 - end -end From d3ae1cc264dc9eb9b602dd6aa21c4282dc049c79 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 26 Feb 2017 20:42:24 +0000 Subject: [PATCH 11/11] bin/brew: tweak variable names. --- bin/brew | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/brew b/bin/brew index 1ecc6f3e29..43a807c7b2 100755 --- a/bin/brew +++ b/bin/brew @@ -48,13 +48,13 @@ if [[ -n "$HOMEBREW_ENV_FILTERING" ]] then PATH="/usr/bin:/bin:/usr/sbin:/sbin" - execution_env=() - for key in HOME SHELL PATH TERM LOGNAME USER "${!HOMEBREW_@}" + FILTERED_ENV=() + for VAR in HOME SHELL PATH TERM LOGNAME USER "${!HOMEBREW_@}" do - execution_env+=( "${key}=${!key}" ) + FILTERED_ENV+=( "${VAR}=${!VAR}" ) done - /usr/bin/env -i "${execution_env[@]}" /bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@" + /usr/bin/env -i "${FILTERED_ENV[@]}" /bin/bash "$HOMEBREW_LIBRARY/Homebrew/brew.sh" "$@" else source "$HOMEBREW_LIBRARY/Homebrew/brew.sh" fi