Created
April 23, 2016 18:35
-
-
Save jasiek/5b36d556baa4fc457169edfe5754db89 to your computer and use it in GitHub Desktop.
Remove a .pkg (package) and its contents from MacOS X.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
package = ARGV.shift | |
info = `pkgutil --pkg-info #{package}`.split("\n") | |
exit if info.empty? | |
files = `pkgutil --files #{package}`.split("\n") | |
volume = nil | |
location = nil | |
directory = nil | |
info.each do |line| | |
/^volume: (.*)/.match(line) do |m| | |
volume = m[1] | |
end | |
/^location: (.*)/.match(line) do |m| | |
location = m[1] | |
end | |
end | |
directory = File.join(volume, location) | |
Dir.chdir(directory) do | |
FileUtils.rm_rf(files) | |
files.each do |file| | |
puts "File still exists: #{file}" if File.exists?(file) | |
end | |
end | |
`pkgutil --forget #{package}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment