Method: Autoproj::PackageManagers::ShellScriptManager.execute

Defined in:
lib/autoproj/package_managers/shell_script_manager.rb

.execute(command_line, with_locking, with_root, env: Autoproj.workspace.env, inherit: Set.new) ⇒ Object



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
36
37
38
# File 'lib/autoproj/package_managers/shell_script_manager.rb', line 6

def self.execute(command_line, with_locking, with_root,
    env: Autoproj.workspace.env, inherit: Set.new)
    if with_locking
        File.open("/tmp/autoproj_osdeps_lock", "w") do |lock_io|
            until lock_io.flock(File::LOCK_EX | File::LOCK_NB)
                Autoproj.message "  waiting for other autoproj "\
                                 "instances to finish their osdeps "\
                                 "installation"
                sleep 5
            end
            return execute(command_line, false, with_root,
                           env: env, inherit: inherit)
        ensure
            lock_io.flock(File::LOCK_UN)
        end
    end

    process_env = env
    if with_root
        process_env = Autobuild::Environment.new
        process_env.isolate
        process_env.add_path("PATH", "/usr/local/sbin",
                             "/usr/sbin", "/sbin")

        inherit.each { |var| process_env.set(var, env[var]) }
        sudo = Autobuild.tool_in_path("sudo", env: process_env)
        command_line = [sudo, "--preserve-env", *command_line]
    end

    Autobuild::Subprocess.run "autoproj", "osdeps", *command_line,
                              env: process_env.resolved_env,
                              env_inherit: false
end