lib/vagrant-solaris10.rb in vagrant-solaris10-0.0.0 vs lib/vagrant-solaris10.rb in vagrant-solaris10-0.0.1

- old
+ new

@@ -1,168 +1,63 @@ -module VagrantPlugins +require "vagrant-solaris10/version" +require "vagrant" -module GuestSolaris10 - class Guest < Vagrant.plugin("2", :guest) - - def detect?(machine) - machine.communicate.test("grep 'Solaris' /etc/release") +module Vagrant + module Solaris10 + class A + def self.mount_parallels_shared_folder(machine, name, guestpath, options) + p "mount parallels" end - def configure_networks(networks) - networks.each do |network| - device = "#{vm.config.solaris.device}#{network[:interface]}" - su_cmd = vm.config.solaris.suexec_cmd - ifconfig_cmd = "#{su_cmd} /sbin/ifconfig #{device}" - - vm.communicate.execute("#{ifconfig_cmd} plumb") - - if network[:type].to_sym == :static - vm.communicate.execute("#{ifconfig_cmd} inet #{network[:ip]} netmask #{network[:netmask]}") - vm.communicate.execute("#{ifconfig_cmd} up") - vm.communicate.execute("#{su_cmd} sh -c \"echo '#{network[:ip]}' > /etc/hostname.#{device}\"") - elsif network[:type].to_sym == :dhcp - vm.communicate.execute("#{ifconfig_cmd} dhcp start") - end - end + def self.mount_vmware_shared_folder(machine, name, guestpath, options) + p "mount vmware" end - def change_host_name(name) - su_cmd = vm.config.solaris.suexec_cmd + # Copyright (c) 2014 Mitchell Hashimoto + def self.insert_public_key(machine, contents) + contents = contents.chomp + contents = Vagrant::Util::ShellQuote.escape(contents, "'") - # Only do this if the hostname is not already set - if !vm.communicate.test("#{su_cmd} hostname | grep '#{name}'") - vm.communicate.execute("#{su_cmd} sh -c \"echo '#{name}' > /etc/nodename\"") - vm.communicate.execute("#{su_cmd} uname -S #{name}") + machine.communicate.tap do |comm| + comm.execute("mkdir -p ~/.ssh") + comm.execute("chmod 0700 ~/.ssh") + comm.execute("printf '#{contents}\\n' >> ~/.ssh/authorized_keys") + comm.execute("chmod 0600 ~/.ssh/authorized_keys") end end - # There should be an exception raised if the line - # - # vagrant::::profiles=Primary Administrator - # - # does not exist in /etc/user_attr. TODO - def halt - # Wait until the VM's state is actually powered off. If this doesn't - # occur within a reasonable amount of time (15 seconds by default), - # then simply return and allow Vagrant to kill the vm. - count = 0 - last_error = nil - while vm.state != :poweroff - begin - vm.communicate.execute("#{vm.config.solaris.suexec_cmd} /usr/sbin/poweroff") - rescue IOError => e - # Save the last error; if it's not shutdown in a reasonable amount - # of attempts we will re-raise the error so it's not hidden for - # all time - last_error = e - end + # Copyright (c) 2014 Mitchell Hashimoto + def self.remove_public_key(machine, contents) + contents = contents.chomp + contents = Vagrant::Util::ShellQuote.escape(contents, "'") - count += 1 - if count >= vm.config.solaris.halt_timeout - # Check for last error and re-raise it - if last_error != nil - raise last_error - else - # Otherwise, just return - return - end + machine.communicate.tap do |comm| + if comm.test("test -f ~/.ssh/authorized_keys") + comm.execute( + "gsed -i '/^.*#{contents}.*$/d' ~/.ssh/authorized_keys") end - - # Still opportunities remaining; sleep and loop - sleep vm.config.solaris.halt_check_interval - end # while - end - - def mount_shared_folder(name, guestpath, options) - # These are just far easier to use than the full options syntax - owner = options[:owner] - group = options[:group] - - # Create the shared folder - vm.communicate.execute("#{vm.config.solaris.suexec_cmd} mkdir -p #{guestpath}") - - # We have to use this `id` command instead of `/usr/bin/id` since this - # one accepts the "-u" and "-g" flags. - id_cmd = "/usr/xpg4/bin/id" - - # Mount the folder with the proper owner/group - mount_options = "-o uid=`#{id_cmd} -u #{owner}`,gid=`#{id_cmd} -g #{group}`" - mount_options += ",#{options[:extra]}" if options[:extra] - vm.communicate.execute("#{vm.config.solaris.suexec_cmd} /sbin/mount -F vboxfs #{mount_options} #{name} #{guestpath}") - - # chown the folder to the proper owner/group - vm.communicate.execute("#{vm.config.solaris.suexec_cmd} chown `#{id_cmd} -u #{owner}`.`#{id_cmd} -g #{group}` #{guestpath}") - end - end - - - - class SolarisConfig < Vagrant.plugin("2", :config) - - def detect?(vm) - vm.communicate.test("grep 'Solaris' /etc/release") - end - - attr_accessor :halt_timeout - attr_accessor :halt_check_interval - # This sets the command to use to execute items as a superuser. pfexec is default - attr_accessor :suexec_cmd - attr_accessor :device - - def initialize - @halt_timeout = 30 - @halt_check_interval = 1 - @suexec_cmd = 'pfexec' - @device = "e1000g" end end + end - - # A general Vagrant system implementation for "solaris10". class Plugin < Vagrant.plugin("2") name "Solaris10 guest" description "Solaris10 guest support." - # A custom config class which will be made accessible via `config.solaris10` - # This is not necessary for all system implementers, of course. However, - # generally, Vagrant tries to make almost every aspect of its execution - # configurable, and this assists that goal. - - guest(:solaris10) do + guest_capability("solaris", "mount_vmware_shared_folder") do + A + end - p "doing the guest" - p Vagrant::Plugin::V2::Plugin + guest_capability("solaris", "mount_parallels_shared_folder") do + A + end - Guest - end + guest_capability("solaris", "insert_public_key") do + A + end - config(:solaris10) do - SolarisConfig - end - - #config("solaris10") do - # SolarisConfig - #end - - - # guest_capability("solaris10", "configure_networks") do - # Solaris10::Guest::configure_networks - # end -# - # guest_capability("solaris10", "configure_networks") do - # Solaris10::Guest::configure_networks - # end -# - # guest_capability("solaris10", "change_host_name") do - # Solaris10::Guest::change_host_name - # end -# - # guest_capability("solaris10", "mount_shared_folder") do - # Solaris10::Guest::mount_shared_folder - # end -# - # guest_capability("solaris10", "halt") do - # Guest::halt - # end -end -end + guest_capability("solaris", "remove_public_key") do + A + end + end + end end \ No newline at end of file