def run
require 'chef/util/windows/net_use'
if @name_args.first == nil
Chef::Log.error("Must pass a node name/ip to windows bootstrap")
exit 1
end
config[:server_name] = @name_args.first
if Chef::Config[:http_proxy]
uri = URI.parse(Chef::Config[:http_proxy])
config[:proxy] = "#{uri.host}:#{uri.port}"
end
@unc_path = "\\\\#{config[:server_name]}"
@admin_share = "#{@unc_path}\\c$"
path = "#{@admin_share}\\chef"
etc = "#{path}\\etc"
tmp = "#{path}\\tmp"
$stdout.sync = true
command = render_template(load_template(config[:bootstrap_template]))
Chef::Log.info("Bootstrapping Chef on #{config[:server_name]}")
@add_mount = config[:user] != nil && !is_mounted
mount_admin_share
begin
[etc, tmp, "#{path}\\log"].each do |dir|
unless File.exists?(dir)
Chef::Log.debug("mkdir_p #{dir}")
FileUtils.mkdir_p(dir)
end
end
File.open("#{tmp}\\bootstrap.bat", 'w') {|f| f.write(command) }
FileUtils.cp(File.join(File.dirname(__FILE__), 'bootstrap', 'client-install.vbs'), tmp)
FileUtils.cp(Chef::Config[:validation_key], etc)
psexec("cmd.exe /c bootstrap.bat")
ensure
unmount_admin_share
end
end