Skip to content

Commit 8205e61

Browse files
committed
More environment filtering tweaks
- only document HOMEBREW_* variables in the manpage (although still read from all the original environment variables). - resort manpage environment variables in alphabetical order - check the original path for trailing slashes
1 parent 459fef3 commit 8205e61

File tree

9 files changed

+54
-83
lines changed

9 files changed

+54
-83
lines changed

Library/Homebrew/diagnostic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def check_for_installed_developer_tools
100100

101101
# See https://github.com/Homebrew/legacy-homebrew/pull/9986
102102
def check_path_for_trailing_slashes
103-
bad_paths = PATH.new(ENV["PATH"]).select { |p| p.end_with?("/") }
103+
bad_paths = PATH.new(ENV["HOMEBREW_PATH"]).select { |p| p.end_with?("/") }
104104
return if bad_paths.empty?
105105

106106
inject_file_list bad_paths, <<-EOS.undent

Library/Homebrew/download_strategy.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ def _fetch
520520
bucket = $1
521521
key = $2
522522

523+
ENV["AWS_ACCESS_KEY_ID"] = ENV["HOMEBREW_AWS_ACCESS_KEY_ID"]
524+
ENV["AWS_SECRET_ACCESS_KEY"] = ENV["HOMEBREW_AWS_SECRET_ACCESS_KEY"]
525+
523526
obj = AWS::S3.new.buckets[bucket].objects[key]
524527
begin
525528
s3url = obj.url_for(:get)

Library/Homebrew/manpages/brew.1.md.erb

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,25 @@ can take several different forms:
9898
The formula file will be cached for later use.
9999

100100
## ENVIRONMENT
101+
* `HOMEBREW_ARTIFACT_DOMAIN`:
102+
If set, instructs Homebrew to use the given URL as a download mirror for bottles and binaries.
103+
104+
* `HOMEBREW_AUTO_UPDATE_SECS`:
105+
If set, Homebrew will only check for autoupdates once per this seconds interval.
106+
107+
*Default:* `60`.
101108

102-
* `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`:
109+
* `HOMEBREW_AWS_ACCESS_KEY_ID`, `HOMEBREW_AWS_SECRET_ACCESS_KEY`:
103110
When using the `S3` download strategy, Homebrew will look in
104111
these variables for access credentials (see
105112
<https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment>
106113
to retrieve these access credentials from AWS). If they are not set,
107114
the `S3` download strategy will download with a public
108115
(unsigned) URL.
109116

110-
* `BROWSER`:
111-
If set, and `HOMEBREW_BROWSER` is not, use `BROWSER` as the web browser
112-
when opening project homepages.
113-
114-
* `EDITOR`:
115-
If set, and `HOMEBREW_EDITOR` and `VISUAL` are not, use `EDITOR` as the text editor.
116-
117-
* `GIT`:
118-
When using Git, Homebrew will use `GIT` if set,
119-
a Homebrew-built Git if installed, or the system-provided binary.
120-
121-
Set this to force Homebrew to use a particular git binary.
122-
123117
* `HOMEBREW_BOTTLE_DOMAIN`:
124118
If set, instructs Homebrew to use the given URL as a download mirror for bottles.
125119

126-
* `HOMEBREW_ARTIFACT_DOMAIN`:
127-
If set, instructs Homebrew to use the given URL as a download mirror for bottles and binaries.
128-
129-
* `HOMEBREW_AUTO_UPDATE_SECS`:
130-
If set, Homebrew will only check for autoupdates once per this seconds interval.
131-
132-
*Default:* `60`.
133-
134120
* `HOMEBREW_BROWSER`:
135121
If set, uses this setting as the browser when opening project homepages,
136122
instead of the OS default browser.
@@ -178,6 +164,12 @@ can take several different forms:
178164
If set, Homebrew will always use its vendored, relocatable Ruby 2.0 version
179165
even if the system version of Ruby is >=2.0.
180166

167+
* `HOMEBREW_GIT`:
168+
When using Git, Homebrew will use `GIT` if set,
169+
a Homebrew-built Git if installed, or the system-provided binary.
170+
171+
Set this to force Homebrew to use a particular git binary.
172+
181173
* `HOMEBREW_GITHUB_API_TOKEN`:
182174
A personal access token for the GitHub API, which you can create at
183175
<https://github.com/settings/tokens>. If set, GitHub will allow you a
@@ -243,9 +235,6 @@ can take several different forms:
243235
* `HOMEBREW_VERBOSE`:
244236
If set, Homebrew always assumes `--verbose` when running commands.
245237

246-
* `VISUAL`:
247-
If set, and `HOMEBREW_EDITOR` is not, use `VISUAL` as the text editor.
248-
249238
## USING HOMEBREW BEHIND A PROXY
250239

251240
Homebrew uses several commands for downloading files (e.g. `curl`, `git`, `svn`).

Library/Homebrew/shims/scm/git

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ fi
8686
case "$(lowercase "$SCM_FILE")" in
8787
git)
8888
[[ -n "$HOMEBREW_GIT" ]] && safe_exec "$(which "$HOMEBREW_GIT")" "$@"
89-
[[ -n "$GIT" ]] && safe_exec "$(which "$GIT")" "$@"
9089
;;
9190
svn)
9291
[[ -n "$HOMEBREW_SVN" ]] && safe_exec "$(which "$HOMEBREW_SVN")" "$@"

Library/Homebrew/test/diagnostic_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
end
88

99
specify "#check_path_for_trailing_slashes" do
10-
ENV["PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
10+
ENV["HOMEBREW_PATH"] += File::PATH_SEPARATOR + "/foo/bar/"
1111
expect(subject.check_path_for_trailing_slashes)
1212
.to match("Some directories in your path end in a slash")
1313
end

Library/Homebrew/utils.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def which_all(cmd, path = ENV["PATH"])
320320
end
321321

322322
def which_editor
323-
editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL").compact.reject(&:empty?).first
323+
editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL").compact.reject(&:empty?).first
324324
if editor
325325
editor_name, _, editor_args = editor.partition " "
326326
editor_path = which(editor_name, ENV["HOMEBREW_PATH"])
@@ -356,7 +356,7 @@ def exec_editor(*args)
356356
end
357357

358358
def exec_browser(*args)
359-
browser = ENV["HOMEBREW_BROWSER"] || ENV["BROWSER"]
359+
browser = ENV["HOMEBREW_BROWSER"]
360360
browser ||= OS::PATH_OPEN if defined?(OS::PATH_OPEN)
361361
return unless browser
362362
safe_exec(browser, *args)

bin/brew

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ fi
4444

4545
HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"
4646

47-
for VAR in EDITOR PATH BINTRAY_USER BINTRAY_KEY
47+
# Whitelist and copy to HOMEBREW_* all variables previously mentioned in
48+
# manpage or used elsewhere by Homebrew.
49+
for VAR in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY BINTRAY_USER BINTRAY_KEY \
50+
BROWSER EDITOR GIT PATH VISUAL
4851
do
4952
VAR_NEW="HOMEBREW_${VAR}"
5053
[[ -n "${!VAR_NEW}" ]] && continue

docs/Manpage.md

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -910,39 +910,25 @@ can take several different forms:
910910
The formula file will be cached for later use.
911911

912912
## ENVIRONMENT
913+
* `HOMEBREW_ARTIFACT_DOMAIN`:
914+
If set, instructs Homebrew to use the given URL as a download mirror for bottles and binaries.
915+
916+
* `HOMEBREW_AUTO_UPDATE_SECS`:
917+
If set, Homebrew will only check for autoupdates once per this seconds interval.
918+
919+
*Default:* `60`.
913920

914-
* `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`:
921+
* `HOMEBREW_AWS_ACCESS_KEY_ID`, `HOMEBREW_AWS_SECRET_ACCESS_KEY`:
915922
When using the `S3` download strategy, Homebrew will look in
916923
these variables for access credentials (see
917924
<https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment>
918925
to retrieve these access credentials from AWS). If they are not set,
919926
the `S3` download strategy will download with a public
920927
(unsigned) URL.
921928

922-
* `BROWSER`:
923-
If set, and `HOMEBREW_BROWSER` is not, use `BROWSER` as the web browser
924-
when opening project homepages.
925-
926-
* `EDITOR`:
927-
If set, and `HOMEBREW_EDITOR` and `VISUAL` are not, use `EDITOR` as the text editor.
928-
929-
* `GIT`:
930-
When using Git, Homebrew will use `GIT` if set,
931-
a Homebrew-built Git if installed, or the system-provided binary.
932-
933-
Set this to force Homebrew to use a particular git binary.
934-
935929
* `HOMEBREW_BOTTLE_DOMAIN`:
936930
If set, instructs Homebrew to use the given URL as a download mirror for bottles.
937931

938-
* `HOMEBREW_ARTIFACT_DOMAIN`:
939-
If set, instructs Homebrew to use the given URL as a download mirror for bottles and binaries.
940-
941-
* `HOMEBREW_AUTO_UPDATE_SECS`:
942-
If set, Homebrew will only check for autoupdates once per this seconds interval.
943-
944-
*Default:* `60`.
945-
946932
* `HOMEBREW_BROWSER`:
947933
If set, uses this setting as the browser when opening project homepages,
948934
instead of the OS default browser.
@@ -990,6 +976,12 @@ can take several different forms:
990976
If set, Homebrew will always use its vendored, relocatable Ruby 2.0 version
991977
even if the system version of Ruby is >=2.0.
992978

979+
* `HOMEBREW_GIT`:
980+
When using Git, Homebrew will use `GIT` if set,
981+
a Homebrew-built Git if installed, or the system-provided binary.
982+
983+
Set this to force Homebrew to use a particular git binary.
984+
993985
* `HOMEBREW_GITHUB_API_TOKEN`:
994986
A personal access token for the GitHub API, which you can create at
995987
<https://github.com/settings/tokens>. If set, GitHub will allow you a
@@ -1055,9 +1047,6 @@ can take several different forms:
10551047
* `HOMEBREW_VERBOSE`:
10561048
If set, Homebrew always assumes `--verbose` when running commands.
10571049

1058-
* `VISUAL`:
1059-
If set, and `HOMEBREW_EDITOR` is not, use `VISUAL` as the text editor.
1060-
10611050
## USING HOMEBREW BEHIND A PROXY
10621051

10631052
Homebrew uses several commands for downloading files (e.g. `curl`, `git`, `svn`).

manpages/brew.1

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -941,29 +941,6 @@ Homebrew can install formulae via URL, e\.g\. \fBhttps://raw\.github\.com/Homebr
941941
.SH "ENVIRONMENT"
942942
.
943943
.TP
944-
\fBAWS_ACCESS_KEY_ID\fR, \fBAWS_SECRET_ACCESS_KEY\fR
945-
When using the \fBS3\fR download strategy, Homebrew will look in these variables for access credentials (see \fIhttps://docs\.aws\.amazon\.com/cli/latest/userguide/cli\-chap\-getting\-started\.html#cli\-environment\fR to retrieve these access credentials from AWS)\. If they are not set, the \fBS3\fR download strategy will download with a public (unsigned) URL\.
946-
.
947-
.TP
948-
\fBBROWSER\fR
949-
If set, and \fBHOMEBREW_BROWSER\fR is not, use \fBBROWSER\fR as the web browser when opening project homepages\.
950-
.
951-
.TP
952-
\fBEDITOR\fR
953-
If set, and \fBHOMEBREW_EDITOR\fR and \fBVISUAL\fR are not, use \fBEDITOR\fR as the text editor\.
954-
.
955-
.TP
956-
\fBGIT\fR
957-
When using Git, Homebrew will use \fBGIT\fR if set, a Homebrew\-built Git if installed, or the system\-provided binary\.
958-
.
959-
.IP
960-
Set this to force Homebrew to use a particular git binary\.
961-
.
962-
.TP
963-
\fBHOMEBREW_BOTTLE_DOMAIN\fR
964-
If set, instructs Homebrew to use the given URL as a download mirror for bottles\.
965-
.
966-
.TP
967944
\fBHOMEBREW_ARTIFACT_DOMAIN\fR
968945
If set, instructs Homebrew to use the given URL as a download mirror for bottles and binaries\.
969946
.
@@ -975,6 +952,14 @@ If set, Homebrew will only check for autoupdates once per this seconds interval\
975952
\fIDefault:\fR \fB60\fR\.
976953
.
977954
.TP
955+
\fBHOMEBREW_AWS_ACCESS_KEY_ID\fR, \fBHOMEBREW_AWS_SECRET_ACCESS_KEY\fR
956+
When using the \fBS3\fR download strategy, Homebrew will look in these variables for access credentials (see \fIhttps://docs\.aws\.amazon\.com/cli/latest/userguide/cli\-chap\-getting\-started\.html#cli\-environment\fR to retrieve these access credentials from AWS)\. If they are not set, the \fBS3\fR download strategy will download with a public (unsigned) URL\.
957+
.
958+
.TP
959+
\fBHOMEBREW_BOTTLE_DOMAIN\fR
960+
If set, instructs Homebrew to use the given URL as a download mirror for bottles\.
961+
.
962+
.TP
978963
\fBHOMEBREW_BROWSER\fR
979964
If set, uses this setting as the browser when opening project homepages, instead of the OS default browser\.
980965
.
@@ -1021,6 +1006,13 @@ If set, Homebrew will use this editor when editing a single formula, or several
10211006
If set, Homebrew will always use its vendored, relocatable Ruby 2\.0 version even if the system version of Ruby is >=2\.0\.
10221007
.
10231008
.TP
1009+
\fBHOMEBREW_GIT\fR
1010+
When using Git, Homebrew will use \fBGIT\fR if set, a Homebrew\-built Git if installed, or the system\-provided binary\.
1011+
.
1012+
.IP
1013+
Set this to force Homebrew to use a particular git binary\.
1014+
.
1015+
.TP
10241016
\fBHOMEBREW_GITHUB_API_TOKEN\fR
10251017
A personal access token for the GitHub API, which you can create at \fIhttps://github\.com/settings/tokens\fR\. If set, GitHub will allow you a greater number of API requests\. See \fIhttps://developer\.github\.com/v3/#rate\-limiting\fR for more information\. Homebrew uses the GitHub API for features such as \fBbrew search\fR\.
10261018
.
@@ -1086,10 +1078,6 @@ This issue typically occurs when using FileVault or custom SSD configurations\.
10861078
\fBHOMEBREW_VERBOSE\fR
10871079
If set, Homebrew always assumes \fB\-\-verbose\fR when running commands\.
10881080
.
1089-
.TP
1090-
\fBVISUAL\fR
1091-
If set, and \fBHOMEBREW_EDITOR\fR is not, use \fBVISUAL\fR as the text editor\.
1092-
.
10931081
.SH "USING HOMEBREW BEHIND A PROXY"
10941082
Homebrew uses several commands for downloading files (e\.g\. \fBcurl\fR, \fBgit\fR, \fBsvn\fR)\. Many of these tools can download via a proxy\. It\'s common for these tools to read proxy parameters from environment variables\.
10951083
.

0 commit comments

Comments
 (0)