Skip to content

Commit

Permalink
Can now configure what shell to sudo with (default: bash)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Feb 9, 2011
1 parent c1373f4 commit 3c45df0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/vagrant/config/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class SSHConfig < Base
attr_writer :private_key_path
attr_accessor :forward_agent
attr_accessor :forward_x11
attr_accessor :sudo_shell

def initialize
@sudo_shell = "bash"
end

def private_key_path
File.expand_path(@private_key_path, env.root_path)
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def execute(opts={})
:user_known_hosts_file => [],
:paranoid => false,
:config => false)) do |ssh|
yield SSH::Session.new(ssh)
yield SSH::Session.new(ssh, env)
end
end
rescue Errno::ECONNREFUSED
Expand Down
6 changes: 4 additions & 2 deletions lib/vagrant/ssh/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class Session
include Util::Retryable

attr_reader :session
attr_reader :env

def initialize(session)
def initialize(session, env)
@session = session
@env = env
end

# Executes a given command and simply returns true/false if the
Expand All @@ -32,7 +34,7 @@ def test?(command)
# of `sudo`.
def sudo!(commands, options=nil, &block)
channel = session.open_channel do |ch|
ch.exec("sudo bash -l") do |ch2, success|
ch.exec("sudo #{env.config.ssh.sudo_shell} -l") do |ch2, success|
# Output each command as if they were entered on the command line
[commands].flatten.each do |command|
ch2.send_data "#{command}\n"
Expand Down
3 changes: 2 additions & 1 deletion test/vagrant/ssh/session_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
class SshSessionTest < Test::Unit::TestCase
setup do
@session = mock("session")
@env = vagrant_env

@klass = Vagrant::SSH::Session
@instance = @klass.new(@session)
@instance = @klass.new(@session, @env)
end

context "exec!" do
Expand Down

0 comments on commit 3c45df0

Please sign in to comment.