Sha256: bb10ff90f62f3755ffea08838f14dc7174d5783982c0d57ca0f1a1a3d74abce7

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module VagrantPlugins
  module GuestOpenBSD
    module Cap
      class ChangeHostName
        def self.change_host_name(machine, name)
          comm = machine.communicate

          if !comm.test("hostname -f | grep '^#{name}$'", sudo: false, shell: "sh")
            basename = name.split(".", 2)[0]
            command = <<-EOH.gsub(/^ {14}/, '')
              # Set the hostname
              hostname '#{name}'
              sed -i'' 's/^hostname=.*$/hostname=\"#{name}\"/' /etc/rc.conf
              echo '#{name}' > /etc/myname

              # Remove comments and blank lines from /etc/hosts
              sed -i'' -e 's/#.*$//' /etc/hosts
              sed -i'' -e '/^$/d' /etc/hosts

              # Prepend ourselves to /etc/hosts
              grep -w '#{name}' /etc/hosts || {
                echo -e '127.0.0.1\\t#{name}\\t#{basename}' | cat - /etc/hosts > /tmp/tmp-hosts
                mv /tmp/tmp-hosts /etc/hosts
              }
            EOH
            comm.sudo(command, shell: "sh")
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vagrant-unbundled-1.9.1.1 plugins/guests/openbsd/cap/change_host_name.rb
vagrant-unbundled-1.8.5.2 plugins/guests/openbsd/cap/change_host_name.rb
vagrant-unbundled-1.8.5.1 plugins/guests/openbsd/cap/change_host_name.rb