Skip to content

Instantly share code, notes, and snippets.

@JeanMertz
Created May 2, 2012 13:07
Show Gist options
  • Select an option

  • Save JeanMertz/2576419 to your computer and use it in GitHub Desktop.

Select an option

Save JeanMertz/2576419 to your computer and use it in GitHub Desktop.
ruby_block 'mount_install_unmount' do
block do
volumes_dir = new_resource.volumes_dir
# Mount the image
%x[hdiutil mount '#{dmg_file}'] unless %x[hdiutil info | grep -q 'image-path.*#{dmg_file}'].strip!
# Get the volume name
unless volumes_dir
all_volumes = %x[hdiutil info -plist].gsub!(/(\t|\n)/, '')\
.scan(/(?:<key>image-path<\/key>)<string>(.*?)<\/string>.*?(?:<key>mount-point<\/key>)<string>(.*?)<\/string>/)\
.each do |image_path, mount_point|
volumes_dir = mount_point if image_path == dmg_file
end
end
# Install application
case extension
when ".mpkg"
%x[sudo installer -pkg #{volumes_dir}/#{new_resource.app}.mpkg -target /]
when ".prefPane"
destination = ::File.expand_path('~/Library/PreferencePanes') if destination == '/Applications'
FileUtils.cp_r "#{volumes_dir}/#{new_resource.app}#{extension}", destination
else
FileUtils.cp_r "#{volumes_dir}/#{new_resource.app}#{extension}", destination
end
# Unmount volume
%x[hdiutil unmount '#{volumes_dir}']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment