brew: remove sudo call only in docker context

Follow up from #6018
This commit is contained in:
Michka Popoff 2019-04-18 07:48:05 +02:00
parent 1aaffda62f
commit 49aad7ddb3

View File

@ -17,16 +17,6 @@ end
# Also define here so we can rescue regardless of location.
class MissingEnvironmentVariables < RuntimeError; end
def create_tap(cmd, tap_name)
tap_commands = []
if cmd == "services"
brew_uid = HOMEBREW_BREW_FILE.stat.uid
tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero?
end
tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{tap_name}]
safe_system(*tap_commands)
end
begin
require_relative "global"
rescue MissingEnvironmentVariables => e
@ -123,7 +113,14 @@ begin
# Unset HOMEBREW_HELP to avoid confusing the tap
ENV.delete("HOMEBREW_HELP") if help_flag
create_tap(cmd, possible_tap.name)
tap_commands = []
cgroup = Utils.popen_read("cat", "/proc/1/cgroup")
unless cgroup.include?("azpl_job") || cgroup.include?("docker")
brew_uid = HOMEBREW_BREW_FILE.stat.uid
tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero?
end
tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap.name}]
safe_system(*tap_commands)
ENV["HOMEBREW_HELP"] = "1" if help_flag
exec HOMEBREW_BREW_FILE, cmd, *ARGV
end