From 1bf3aa69ed954f817f539a282c0549f5a4bbfd7a Mon Sep 17 00:00:00 2001 From: Dave Simons Date: Wed, 27 Jul 2011 23:24:27 +0200 Subject: [PATCH] set hostname on archlinux [closes GH-439] Signed-off-by: Dave Simons --- lib/vagrant/systems.rb | 1 + lib/vagrant/systems/arch.rb | 16 ++++++++++++++++ lib/vagrant/systems/linux.rb | 1 + lib/vagrant/vm.rb | 3 ++- 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 lib/vagrant/systems/arch.rb diff --git a/lib/vagrant/systems.rb b/lib/vagrant/systems.rb index 7c815ffcf..feca7a12e 100644 --- a/lib/vagrant/systems.rb +++ b/lib/vagrant/systems.rb @@ -10,3 +10,4 @@ require 'vagrant/systems/gentoo' require 'vagrant/systems/redhat' require 'vagrant/systems/suse' require 'vagrant/systems/ubuntu' +require 'vagrant/systems/arch' diff --git a/lib/vagrant/systems/arch.rb b/lib/vagrant/systems/arch.rb new file mode 100644 index 000000000..48c0caf62 --- /dev/null +++ b/lib/vagrant/systems/arch.rb @@ -0,0 +1,16 @@ +module Vagrant + module Systems + class Arch < Linux + def change_host_name(name) + vm.ssh.execute do |ssh| + # Only do this if the hostname is not already set + if !ssh.test?("sudo hostname | grep '#{name}'") + ssh.exec!("sudo sed -i 's/\\(HOSTNAME=\\).*/\\1#{name}/' /etc/rc.conf") + ssh.exec!("sudo hostname #{name}") + ssh.exec!("sudo sed -i 's@^\\(127[.]0[.]0[.]1[[:space:]]\\+\\)@\\1#{name} @' /etc/hosts") + end + end + end + end + end +end diff --git a/lib/vagrant/systems/linux.rb b/lib/vagrant/systems/linux.rb index 777565957..2830a47d7 100644 --- a/lib/vagrant/systems/linux.rb +++ b/lib/vagrant/systems/linux.rb @@ -14,6 +14,7 @@ module Vagrant return :gentoo if ssh.test?("cat /etc/gentoo-release") return :redhat if ssh.test?("cat /etc/redhat-release") return :suse if ssh.test?("cat /etc/SuSE-release") + return :arch if ssh.test?("cat /etc/arch-release") end # Can't detect the distro, assume vanilla linux diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index 879ccf953..21da2c898 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -66,7 +66,8 @@ module Vagrant :redhat => Systems::Redhat, :suse => Systems::Suse, :linux => Systems::Linux, - :solaris => Systems::Solaris + :solaris => Systems::Solaris, + :arch => Systems::Arch } raise Errors::VMSystemError, :_key => :unknown_type, :system => system.to_s if !mapping.has_key?(system)