Class: VagrantPlugins::DigitalOcean::Actions::SetupSudo

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-digitalocean/actions/setup_sudo.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SetupSudo

Returns a new instance of SetupSudo.



5
6
7
8
9
# File 'lib/vagrant-digitalocean/actions/setup_sudo.rb', line 5

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @logger = Log4r::Logger.new('vagrant::digitalocean::setup_sudo')
end

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/vagrant-digitalocean/actions/setup_sudo.rb', line 11

def call(env)
  # check if setup is enabled
  return @app.call(env) unless @machine.provider_config.setup?

  # override ssh username to root
  user = @machine.config.ssh.username
  @machine.config.ssh.username = 'root'

  # check for guest name available in Vagrant 1.2 first
  guest_name = @machine.guest.name if @machine.guest.respond_to?(:name)
  guest_name ||= @machine.guest.to_s.downcase

  case guest_name
  when /redhat/
    env[:ui].info I18n.t('vagrant_digital_ocean.info.modifying_sudo')

    # disable tty requirement for sudo
    @machine.communicate.execute(<<-'BASH')
      sed -i'.bk' -e 's/\(Defaults\s\+requiretty\)/# \1/' /etc/sudoers
    BASH
  end

  # reset ssh username
  @machine.config.ssh.username = user

  @app.call(env)
end