Class: Vagrant::LXC::Command::Sudoers

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-lxc/command/sudoers.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv, env) ⇒ Sudoers

Returns a new instance of Sudoers.



11
12
13
14
15
# File 'lib/vagrant-lxc/command/sudoers.rb', line 11

def initialize(argv, env)
  super
  @argv
  @env = env
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-lxc/command/sudoers.rb', line 17

def execute
  options = { user: ENV['USER'] }

  opts = OptionParser.new do |opts|
    opts.banner = "Usage: vagrant lxc sudoers"
    opts.separator ""
    opts.on('-u user', '--user user', String, "The user for which to create the policy (defaults to '#{options[:user]}')") do |u|
      options[:user] = u
    end
  end

  argv = parse_options(opts)
  return unless argv

  wrapper_path = SudoWrapper.dest_path
  wrapper = create_wrapper!
  sudoers = create_sudoers!(options[:user], wrapper_path)

  su_copy([
    {source: wrapper, target: wrapper_path, mode: "0555"},
    {source: sudoers, target: sudoers_path, mode: "0440"}
  ])
end

#sudoers_pathObject



41
42
43
# File 'lib/vagrant-lxc/command/sudoers.rb', line 41

def sudoers_path
  "/etc/sudoers.d/vagrant-lxc"
end