diff --git a/lib/vagrant/ssh/session.rb b/lib/vagrant/ssh/session.rb index 2cf5ffe3e..f4d97b67b 100644 --- a/lib/vagrant/ssh/session.rb +++ b/lib/vagrant/ssh/session.rb @@ -12,6 +12,16 @@ module Vagrant @session = session end + # Executes a given command and simply returns true/false if the + # command succeeded or not. + def test?(command) + exec!(command) do |ch, type, data| + return true if type == :exit_status && data == 0 + end + + false + end + # Executes a given command on the SSH session and blocks until # the command completes. This is an almost line for line copy of # the actual `exec!` implementation, except that this diff --git a/lib/vagrant/systems.rb b/lib/vagrant/systems.rb index 22f5ef686..bd759f737 100644 --- a/lib/vagrant/systems.rb +++ b/lib/vagrant/systems.rb @@ -3,4 +3,6 @@ require 'vagrant/systems/base' require 'vagrant/systems/linux' require 'vagrant/systems/solaris' + +require 'vagrant/systems/debian' require 'vagrant/systems/gentoo' diff --git a/lib/vagrant/systems/debian.rb b/lib/vagrant/systems/debian.rb new file mode 100644 index 000000000..660db7cdf --- /dev/null +++ b/lib/vagrant/systems/debian.rb @@ -0,0 +1,26 @@ +module Vagrant + module Systems + class Debian < Linux + def prepare_host_only_network + # Remove any previous host only network additions to the + # interface file. + vm.ssh.execute do |ssh| + # Clear out any previous entries + ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces") + ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'") + end + end + + def enable_host_only_network(net_options) + entry = TemplateRenderer.render('network_entry_debian', :net_options => net_options) + vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") + + vm.ssh.execute do |ssh| + ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null") + ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'") + ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}") + end + end + end + end +end diff --git a/lib/vagrant/systems/gentoo.rb b/lib/vagrant/systems/gentoo.rb index 609bc83f5..878bb90b3 100644 --- a/lib/vagrant/systems/gentoo.rb +++ b/lib/vagrant/systems/gentoo.rb @@ -5,9 +5,6 @@ module Vagrant # Remove any previous host only network additions to the # interface file. vm.ssh.execute do |ssh| - # Verify gentoo - # ssh.exec!("cat /etc/gentoo-release", :error_class => GentooError, :_key => :network_not_gentoo) - # Clear out any previous entries ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/conf.d/net > /tmp/vagrant-network-interfaces") ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/conf.d/net'") diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index bf090a52d..ade6abc8b 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -4,6 +4,16 @@ require 'vagrant/systems/linux/config' module Vagrant module Systems class Linux < Base + def distro_dispatch + vm.ssh.execute do |ssh| + return :debian if ssh.test?("cat /etc/debian_version") + return :gentoo if ssh.test?("cat /etc/gentoo-release") + end + + # Can't detect the distro, assume vanilla linux + nil + end + def halt vm.env.ui.info I18n.t("vagrant.systems.linux.attempting_halt") vm.ssh.execute do |ssh| @@ -39,30 +49,6 @@ module Vagrant end end - def prepare_host_only_network - # Remove any previous host only network additions to the - # interface file. - vm.ssh.execute do |ssh| - # Verify debian/ubuntu - ssh.exec!("cat /etc/debian_version", :error_class => LinuxError, :_key => :network_not_debian) - - # Clear out any previous entries - ssh.exec!("sudo sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' /etc/network/interfaces > /tmp/vagrant-network-interfaces") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-interfaces > /etc/network/interfaces'") - end - end - - def enable_host_only_network(net_options) - entry = TemplateRenderer.render('network_entry', :net_options => net_options) - vm.ssh.upload!(StringIO.new(entry), "/tmp/vagrant-network-entry") - - vm.ssh.execute do |ssh| - ssh.exec!("sudo /sbin/ifdown eth#{net_options[:adapter]} 2> /dev/null") - ssh.exec!("sudo su -c 'cat /tmp/vagrant-network-entry >> /etc/network/interfaces'") - ssh.exec!("sudo /sbin/ifup eth#{net_options[:adapter]}") - end - end - #------------------------------------------------------------------- # "Private" methods which assist above methods #------------------------------------------------------------------- diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 60c8bea47..b192c4ce6 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -58,9 +58,10 @@ module Vagrant elsif system.is_a?(Symbol) # Hard-coded internal systems mapping = { + :debian => Systems::Debian, + :gentoo => Systems::Gentoo, :linux => Systems::Linux, - :solaris => Systems::Solaris, - :gentoo => Systems::Gentoo + :solaris => Systems::Solaris } raise Errors::VMSystemError, :_key => :unknown_type, :system => system.to_s if !mapping.has_key?(system) diff --git a/templates/network_entry.erb b/templates/network_entry_debian.erb similarity index 100% rename from templates/network_entry.erb rename to templates/network_entry_debian.erb