diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2014-05-12 19:59:44 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2014-05-12 19:59:44 -0700 |
commit | 1e8cd2c27755bac4086489e9a6eed19bf4d72d45 (patch) | |
tree | bcd1f56a06213753d5855cf4c591bd80001c27a8 /osx/uninstall-pandoc.pl | |
parent | 77b2589d3f10f988ddf6804dee401112057f5a17 (diff) |
Moved osx package stuff to osx directory; added uninstall script.
Thanks to Daniel T. Staal for an uninstall script from which this
one is modified.
Diffstat (limited to 'osx/uninstall-pandoc.pl')
-rwxr-xr-x | osx/uninstall-pandoc.pl | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/osx/uninstall-pandoc.pl b/osx/uninstall-pandoc.pl new file mode 100755 index 000000000..292bcfd96 --- /dev/null +++ b/osx/uninstall-pandoc.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl + +# Script to remove all files installed by the OSX pandoc installer +# and unregister the package. Modified from a script contributed +# by Daniel T. Staal. + +use warnings; +use strict; + +use File::Spec; + +# The main info: this is the list of files to remove and the pkg_id. +my $pkg_id = 'net.johnmacfarlane.pandoc'; + +my @pkg_info; + +# Find which, if any, volume Pandoc is installed on. +my $volume; + +# First check /, then other volumes on the box. +my $cur_test = `pkgutil --pkgs=$pkg_id`; +if ( $cur_test =~ m/$pkg_id/ ) { + $volume = '/'; +} else { + opendir( my $dh, '/Volumes' ) or die "Can't list Volumes: $!\n"; + foreach my $dir ( readdir($dh) ) { + next if $dir =~ m/^\./; # Skip dotfiles. + + my $path = File::Spec->rel2abs( $dir, '/Volumes' ); + next if !( -d $path ); # Skip anything that isn't a directory. + + my $cur_test = `pkgutil --pkgs=$pkg_id --volume '$path'`; + if ( $cur_test =~ m/$pkg_id/ ) { + $volume = $path; + last; + } + } +} + +die "Pandoc not installed.\n" if !( defined($volume) ); + +my @pkg_files = (); +my $f; +for $f (split '\n', `pkgutil --volume '$volume' --only-files --files $pkg_id`) { + push @pkg_files, File::Spec->rel2abs($f, $volume); +}; + +print "The following files will be deleted:\n\n"; +print join("\n", @pkg_files); +print "\n\n"; +print "Do you want to proceed and uninstall pandoc (Y/N)?"; +my $input = <STDIN>; + +if ($input =~ m/^[Yy]/) { + + # Actually remove the files. + foreach $f (@pkg_files) { + if (system("sudo rm $f") == 0) { + warn "Deleted $f\n"; + } else { + warn "Unable to delete $f: $!\n"; + warn "Aborting uninstall.\n"; + exit 1; + } + } + + # Clean up the install. + if (system("sudo pkgutil --forget $pkg_id --volume '$volume'") != 0) { + warn "Unable to clean up install: $!\n"; + exit 1; + } + +} else { + + print "OK, aborting uninstall.\n"; + exit 0; + +} + +print "Pandoc has been successfully uninstalled.\n"; +exit 0; |