From c300528c11c8087c70e1f6e4c9a6ae4421a03b5e Mon Sep 17 00:00:00 2001 From: Hippie Hacker Date: Thu, 7 Mar 2013 16:41:00 -0800 Subject: [PATCH] first commit --- .../knife/source_ingredient_virtualbox.rb | 213 ++++++++++++++++++ README.md | 14 ++ el6_1_x86_64_4_2_8.json | 14 ++ extensionpack_4_2_8.json | 14 ++ guestadditions_4_2_8_iso.json | 14 ++ osx_4_2_8.json | 18 ++ ubuntu_precise_x86_64_4_2_8_iso.json | 14 ++ ubuntu_quantal_x86_64_4_2_8_iso.json | 14 ++ windows_4_2_8.json | 20 ++ 9 files changed, 335 insertions(+) create mode 100644 .chef/plugins/knife/source_ingredient_virtualbox.rb create mode 100644 README.md create mode 100644 el6_1_x86_64_4_2_8.json create mode 100644 extensionpack_4_2_8.json create mode 100644 guestadditions_4_2_8_iso.json create mode 100644 osx_4_2_8.json create mode 100644 ubuntu_precise_x86_64_4_2_8_iso.json create mode 100644 ubuntu_quantal_x86_64_4_2_8_iso.json create mode 100644 windows_4_2_8.json diff --git a/.chef/plugins/knife/source_ingredient_virtualbox.rb b/.chef/plugins/knife/source_ingredient_virtualbox.rb new file mode 100644 index 0000000..6463dfe --- /dev/null +++ b/.chef/plugins/knife/source_ingredient_virtualbox.rb @@ -0,0 +1,213 @@ +require 'chef/knife' + +module KnifePlugins + class SourceIngredientVirtualbox < Chef::Knife + include Chef::Mixin::Checksum + + deps do + require 'chef/version_constraint' + require 'chef/exceptions' + require 'chef/search/query' + require 'chef/shef/ext' + require 'chef/mixin/checksum' + require 'json' + require 'open-uri' + require 'net/https' + require 'uri' + require 'nokogiri' + require 'fileutils' + end + + banner "knife source ingredient virtualbox" + + def download_file(source,destination) + puts "Downloading #{source} to #{destination}" + uri = URI.parse source + Net::HTTP.start(uri.host, uri.port) do |http| + request = Net::HTTP::Get.new uri.request_uri + http.request request do |response| + if response.response['Location']!=nil + redirectURL=response.response['Location'] + puts "#{redirectURL}***" + # need to figure out how to handle redirects + raise Error + end + + open destination, 'wb' do |io| + response.read_body do |chunk| + io.write chunk + end + end + end + end + end + + def run + begin + FileUtils.touch(File.join(Chef::Config[:data_bag_path],'.writeable')) + FileUtils.touch(File.join(Chef::Config[:file_cache_path],'.writeable')) + rescue + puts "Set role_path and file_cache_path in knife.rb to somewhere writable" + exit 1 + end + data_bag_name = 'virtualbox' # maybe set this via cmdline later + artifacts = Hash.new + # http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/SHA256SUMS + base_url = 'http://dlc.sun.com.edgesuite.net/virtualbox/' + # this one directs us, and I can't handle 302s yet + # base_url = 'http://download.virtualbox.org/virtualbox/' + download_page=Nokogiri::HTML(open(base_url)) + download_page.search( + '//a/img[contains(@alt,"DIR")]/..').select{|l| + l['href'] =~ /\d+\.\d+\.\d+\/$/}.map{|v| v['href']}.each do |ver_url| + virtualbox_ver = ::File.basename(ver_url.sub('/','')) + semantic_ver = virtualbox_ver + # I only want 4.2.8 or higher + next if not Chef::VersionConstraint.new(">= 4.2.8").include? semantic_ver + + # we wants rhel 6, osx, windows, and recent ubuntus, the guest additions and extpack + wants = %w{ el6 OSX Win precise quantal VBoxGuestAdditions Pack } + # The formats we want... note lack of i386, i686, openSUSE, sles, fedora, SunOS + # generic Linux, src SDK + formats = %w{ amd64 x86_64 exe iso dmg} + formats << "#{virtualbox_ver}\\.vbox" + # get the urls for all links that have a class starting with file + package_urls = Nokogiri::HTML(open(base_url + ver_url)).search('//a' + ).select do |l| + l['href'] =~ /(#{wants.join('|')}).*(#{formats.join('|')})/ + end.map{ |l| l['href']} + # populate our artifacts hash with info about this artifact source + package_urls.each do |package_url| + dbi_safe_ver = virtualbox_ver.gsub('.','_') + package_filename = package_url + package_url = base_url + ver_url + package_filename + arch = case ::File.basename(package_filename) + when /(x86_64|amd64)/ + 'x86_64' + when /(i686|i586|i386)/ + 'i686' + else + ['i686','x86_64'] + end + case package_filename + when %r{ + (? \d+\.\d+\.\d+ ){0} + (? \d+ ){0} + VirtualBox-\g-\g-OSX\.dmg + }x + package_ver = $1 + build_num = $2 + os = { + 'mac_os_x' => [ + '10.7', + '10.8' + ] + } + dbi_name = "osx_#{dbi_safe_ver}" + when %r{ + (? \d+\.\d+\.\d+ ){0} + (? \d+ ){0} + VirtualBox-\g-\g-Win\.exe + }x + package_ver = $1 + build_num = $2 + os = { + 'windows' => [ + '2008r2', + '2012', + '7', + '8' + ] + } + dbi_name = "windows_#{dbi_safe_ver}" + when %r{ + (? \d+\.\d+\.\d+ ){0} + VBoxGuestAdditions_\g\.iso + }x + os = {} + dbi_name = "guestadditions_#{dbi_safe_ver}_iso" + when %r{ + (? \d+\.\d+\.\d+ ){0} + Oracle_VM_VirtualBox_Extension_Pack-\g\.vbox-extpack + }x + os = {} + dbi_name = "extensionpack_#{dbi_safe_ver}" + when %r{ + (? (x86_64|i386) ){0} + (? \d+\.\d+\.\d+ ){0} + (? \w+ ){0} + (? \d+ ){0} + (? \d+ ){0} + (? \d+ ){0} + VirtualBox-\d+\.\d+-\g_\g_\g\g-\g\.\g\.rpm + }x + distname = $3 + distrelease = $4 + osrev = $6 + os = {} + os = { + distname => + [ + distrelease + ] + } + dbi_name = "#{distname}#{distrelease}_#{osrev}_#{arch}_#{dbi_safe_ver}" + when %r{ + (? (amd64|i386) ){0} + (? \d+\.\d+\.\d+ ){0} + (? \w+ ){0} + (? \d+ ){0} + virtualbox-\d+\.\d+_\g-\g~Ubuntu~\g_\g\.deb + }x + pver = $1 + build_num = $2 + distname = $3 + os = { + 'ubuntu' => + [ + case distname + when /precise/ + '12.04' + when /quantal/ + '12.10' + end + ] + } + dbi_name = "ubuntu_#{distname}_#{arch}_#{dbi_safe_ver}_iso" + else + puts "XXX #{package_filename} not process" + end + + # Let's put the files in our cache... might be useful later 8) + cached_packagefile = ::File.join( + Chef::Config[:file_cache_path],package_filename) + if not ::File.exists? cached_packagefile + # we should probably try to compare to SHA256 or something + download_file(package_url) + end + + # New we have all the artifact details + artifacts[dbi_name] ||= Hash.new + artifacts[dbi_name][:source] ||= package_url + artifacts[dbi_name][:filename] ||= package_filename + artifacts[dbi_name][:arch] ||= arch + artifacts[dbi_name][:checksum] ||= checksum(cached_packagefile) + artifacts[dbi_name][:version] ||= virtualbox_ver + artifacts[dbi_name][:semantic_version] ||= semantic_ver + artifacts[dbi_name][:os] ||= os + end + end + + #puts JSON.pretty_generate(artifacts) + # Write out all data bag json + data_bag_item_dir = ::File.join(Chef::Config[:data_bag_path],data_bag_name) + Dir.mkdir data_bag_item_dir unless File.exists? data_bag_item_dir + artifacts.each do |dbi,data| + open(::File.join(data_bag_item_dir,dbi+'.json'),'w') do |f| + f.write JSON.pretty_generate({id: dbi}.merge(data)) + f.close + end + end + end + end +end diff --git a/README.md b/README.md new file mode 100644 index 0000000..eb700f2 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +Drop .chef/plugins/knife/source_ingredient_virtualbox.rb +into your .chef/plugins/knife directory and run: + +``` +knife source ingredient virtualbox +``` + +:file_cache_path and :data_bag_path must writable and might need to be set in your knife.rb + +The latest available versions of virtualbox will be downloaded into +your file_cache_path and your data bag path will get a virtualbox directory +created which will be populated with data bag items for each version +of vagrant that is available. + diff --git a/el6_1_x86_64_4_2_8.json b/el6_1_x86_64_4_2_8.json new file mode 100644 index 0000000..822d359 --- /dev/null +++ b/el6_1_x86_64_4_2_8.json @@ -0,0 +1,14 @@ +{ + "id": "el6_1_x86_64_4_2_8", + "source": "http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/VirtualBox-4.2-4.2.8_83876_el6-1.x86_64.rpm", + "filename": "VirtualBox-4.2-4.2.8_83876_el6-1.x86_64.rpm", + "arch": "x86_64", + "checksum": "7a9c783a9aa724156124c635255143a37d61d61544f1535b05cf33906e073cd7", + "version": "4.2.8", + "semantic_version": "4.2.8", + "os": { + "el": [ + "6" + ] + } +} \ No newline at end of file diff --git a/extensionpack_4_2_8.json b/extensionpack_4_2_8.json new file mode 100644 index 0000000..1751192 --- /dev/null +++ b/extensionpack_4_2_8.json @@ -0,0 +1,14 @@ +{ + "id": "extensionpack_4_2_8", + "source": "http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/Oracle_VM_VirtualBox_Extension_Pack-4.2.8.vbox-extpack", + "filename": "Oracle_VM_VirtualBox_Extension_Pack-4.2.8.vbox-extpack", + "arch": [ + "i686", + "x86_64" + ], + "checksum": "fa579416f382b58c4e93d3740d076ceba728e28d987e51aced5865a46cb9111c", + "version": "4.2.8", + "semantic_version": "4.2.8", + "os": { + } +} \ No newline at end of file diff --git a/guestadditions_4_2_8_iso.json b/guestadditions_4_2_8_iso.json new file mode 100644 index 0000000..6580b14 --- /dev/null +++ b/guestadditions_4_2_8_iso.json @@ -0,0 +1,14 @@ +{ + "id": "guestadditions_4_2_8_iso", + "source": "http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/VBoxGuestAdditions_4.2.8.iso", + "filename": "VBoxGuestAdditions_4.2.8.iso", + "arch": [ + "i686", + "x86_64" + ], + "checksum": "04a5402d8dcdefc83ffb2785351ddc57758781a3759137974469189392ae4ad5", + "version": "4.2.8", + "semantic_version": "4.2.8", + "os": { + } +} \ No newline at end of file diff --git a/osx_4_2_8.json b/osx_4_2_8.json new file mode 100644 index 0000000..a863164 --- /dev/null +++ b/osx_4_2_8.json @@ -0,0 +1,18 @@ +{ + "id": "osx_4_2_8", + "source": "http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/VirtualBox-4.2.8-83876-OSX.dmg", + "filename": "VirtualBox-4.2.8-83876-OSX.dmg", + "arch": [ + "i686", + "x86_64" + ], + "checksum": "e090da9766a1780a4f1fc6b3b85fe8b7ce71c8030d1fda9e7178716009d69a33", + "version": "4.2.8", + "semantic_version": "4.2.8", + "os": { + "mac_os_x": [ + "10.7", + "10.8" + ] + } +} \ No newline at end of file diff --git a/ubuntu_precise_x86_64_4_2_8_iso.json b/ubuntu_precise_x86_64_4_2_8_iso.json new file mode 100644 index 0000000..214ef19 --- /dev/null +++ b/ubuntu_precise_x86_64_4_2_8_iso.json @@ -0,0 +1,14 @@ +{ + "id": "ubuntu_precise_x86_64_4_2_8_iso", + "source": "http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/virtualbox-4.2_4.2.8-83876~Ubuntu~precise_amd64.deb", + "filename": "virtualbox-4.2_4.2.8-83876~Ubuntu~precise_amd64.deb", + "arch": "x86_64", + "checksum": "bf49e6b61dffd2130041550a79eb9347b79702874d1dccbe51bcacc8ecbfcfd0", + "version": "4.2.8", + "semantic_version": "4.2.8", + "os": { + "ubuntu": [ + "12.04" + ] + } +} \ No newline at end of file diff --git a/ubuntu_quantal_x86_64_4_2_8_iso.json b/ubuntu_quantal_x86_64_4_2_8_iso.json new file mode 100644 index 0000000..6d2418f --- /dev/null +++ b/ubuntu_quantal_x86_64_4_2_8_iso.json @@ -0,0 +1,14 @@ +{ + "id": "ubuntu_quantal_x86_64_4_2_8_iso", + "source": "http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/virtualbox-4.2_4.2.8-83876~Ubuntu~quantal_amd64.deb", + "filename": "virtualbox-4.2_4.2.8-83876~Ubuntu~quantal_amd64.deb", + "arch": "x86_64", + "checksum": "9e875b91f0ddaa9e5d08331e5b64d950ca6572b80caa8ff635d4cc0eed9476fc", + "version": "4.2.8", + "semantic_version": "4.2.8", + "os": { + "ubuntu": [ + "12.10" + ] + } +} \ No newline at end of file diff --git a/windows_4_2_8.json b/windows_4_2_8.json new file mode 100644 index 0000000..ada4db6 --- /dev/null +++ b/windows_4_2_8.json @@ -0,0 +1,20 @@ +{ + "id": "windows_4_2_8", + "source": "http://dlc.sun.com.edgesuite.net/virtualbox/4.2.8/VirtualBox-4.2.8-83876-Win.exe", + "filename": "VirtualBox-4.2.8-83876-Win.exe", + "arch": [ + "i686", + "x86_64" + ], + "checksum": "7864b538152b6ba672f94ac0e2be7e6a892d686bcf8035cd155e1fb1578ac77a", + "version": "4.2.8", + "semantic_version": "4.2.8", + "os": { + "windows": [ + "2008r2", + "2012", + "7", + "8" + ] + } +} \ No newline at end of file