aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cmd/postinstall.rb
blob: 5e9e956c86e87f15eeeec161d1a196c6146361bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "sandbox"

module Homebrew
  def postinstall
    ARGV.formulae.each { |f| run_post_install(f) }
  end

  def run_post_install(formula)
    args = %W[
      nice #{RUBY_PATH}
      -W0
      -I #{HOMEBREW_LIBRARY_PATH}
      --
      #{HOMEBREW_LIBRARY_PATH}/postinstall.rb
      #{formula.path}
    ].concat(ARGV.options_only)

    Utils.safe_fork do
      if Sandbox.available? && ARGV.sandbox?
        sandbox = Sandbox.new
        logd = HOMEBREW_LOGS/formula.name
        logd.mkpath
        sandbox.record_log(logd/"sandbox.postinstall.log")
        sandbox.allow_write_temp_and_cache
        sandbox.allow_write_log(formula)
        sandbox.allow_write_cellar(formula)
        sandbox.allow_write_path HOMEBREW_PREFIX
        sandbox.deny_write_homebrew_library
        sandbox.exec(*args)
      else
        exec(*args)
      end
    end
  end
end