Skip to content

Instantly share code, notes, and snippets.

@codebutler
Created May 29, 2010 19:56
Show Gist options
  • Save codebutler/418498 to your computer and use it in GitHub Desktop.
Save codebutler/418498 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# Example script to "uninstall" OSX .pkg files
# Probably very dangerous.
#
# Eric Butler <eric@codebutler.com>
require 'fileutils'
PKGS = %w(
net.refractions.postgis14-snow
org.postgresql.postgresql-snow
dbsgeo.com.mapnikFramework.Libraries.pkg
dbsgeo.com.mapnikFramework.mapnik.pkg
dbsgeo.com.mapnikFramework.postgis.pkg
dbsgeo.com.mapnikFramework.raster.pkg
dbsgeo.com.mapnikFramework.shape.pkg
dbsgeo.com.mapnikFramework.ttf.pkg
dbsgeo.com.mapnikPython26.cairo.pkg
dbsgeo.com.mapnikPython26.libboost_python_system2.6.pkg
dbsgeo.com.mapnikPython26.mapnik-1.pkg
dbsgeo.com.mapnikPython26.mapnik.pkg
dbsgeo.com.mapnikPython26.ogcserver.pkg
net.refractions.geos-framework-snow
net.refractions.postgis14-snow
)
PKGS.each do |pkg|
puts pkg
info = `pkgutil --info #{pkg}`
if $? == 0
info = Hash[info.split("\n").map { |line| line.split(':').map{ |x| x.strip } }]
prefix = File.join(info['volume'], info['location'])
files = `pkgutil --files #{pkg}`.split("\n").map { |file| File.join(prefix, file) }
files.each do |file|
if File.file?(file)
puts "Removing #{file}"
File.delete(file)
elsif File.directory?(file)
puts "Removing dir #{file}"
FileUtils.rm_rf(file)
else
puts "File not found: #{file}"
end
end
`pkgutil --forget #{pkg}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment