+# if we need a different / special kernel version to make the hardware
+# work (e.g: https://github.com/openstreetmap/operations/issues/45) then
+# ensure that we have the package installed. the grub template will
+# make sure that this is the default on boot.
+if node[:hardware][:grub][:kernel]
+ kernel_version = node[:hardware][:grub][:kernel]
+
+ package "linux-image-#{kernel_version}-generic"
+ package "linux-image-extra-#{kernel_version}-generic"
+ package "linux-headers-#{kernel_version}-generic"
+
+ boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
+ boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
+ grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
+else
+ grub_entry = "0"
+end
+
+if File.exist?("/etc/default/grub")
+ execute "update-grub" do
+ action :nothing
+ command "/usr/sbin/update-grub"
+ end
+
+ template "/etc/default/grub" do
+ source "grub.erb"
+ owner "root"
+ group "root"
+ mode 0o644
+ variables :units => units, :entry => grub_entry
+ notifies :run, "execute[update-grub]"
+ end
+end
+
+execute "update-initramfs" do
+ action :nothing
+ command "update-initramfs -u -k all"
+ user "root"
+ group "root"
+end
+
+template "/etc/initramfs-tools/conf.d/mdadm" do
+ source "initramfs-mdadm.erb"
+ owner "root"
+ group "root"
+ mode 0o644
+ notifies :run, "execute[update-initramfs]"
+end
+
+package "haveged"
+service "haveged" do
+ action [:enable, :start]
+end
+
+if node[:kernel][:modules].include?("ipmi_si")
+ package "ipmitool"
+end
+
+if node[:lsb][:release].to_f >= 12.10
+ package "irqbalance"
+
+ template "/etc/default/irqbalance" do
+ source "irqbalance.erb"
+ owner "root"
+ group "root"
+ mode 0o644
+ end
+
+ service "irqbalance" do
+ action [:start, :enable]
+ supports :status => false, :restart => true, :reload => false
+ subscribes :restart, "template[/etc/default/irqbalance]"
+ end
+end
+
+tools_packages = []
+status_packages = {}
+
+node[:kernel][:modules].each_key do |modname|
+ case modname
+ when "cciss"
+ tools_packages << "hpssacli"
+ status_packages["cciss-vol-status"] ||= []
+ when "hpsa"
+ tools_packages << "hpssacli"
+ status_packages["cciss-vol-status"] ||= []
+ when "mptsas"
+ tools_packages << "lsiutil"
+ # status_packages["mpt-status"] ||= []
+ when "mpt2sas", "mpt3sas"
+ tools_packages << "sas2ircu"
+ status_packages["sas2ircu-status"] ||= []
+ when "megaraid_mm"
+ tools_packages << "megactl"
+ status_packages["megaraid-status"] ||= []
+ when "megaraid_sas"
+ tools_packages << "megacli"
+ status_packages["megaclisas-status"] ||= []
+ when "aacraid"
+ tools_packages << "arcconf"
+ status_packages["aacraid-status"] ||= []
+ when "arcmsr"
+ tools_packages << "areca"
+ end
+end
+
+node[:block_device].each do |name, attributes|
+ next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
+
+ if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
+ status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
+ else
+ Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
+ status_packages["cciss-vol-status"] |= [File.basename(sg)]
+ end
+ end
+end
+
+%w(hpssacli lsiutil sas2ircu megactl megacli arcconf).each do |tools_package|
+ if tools_packages.include?(tools_package)
+ package tools_package
+ else
+ package tools_package do
+ action :purge
+ end
+ end
+end
+
+if tools_packages.include?("areca")