diff options
author | Clare Macrae <github@cfmacrae.fastmail.co.uk> | 2014-06-29 19:22:31 +0100 |
---|---|---|
committer | Clare Macrae <github@cfmacrae.fastmail.co.uk> | 2014-06-29 19:22:31 +0100 |
commit | 717e16660d1ee83f690b35d0aa9b60c8ac9d6b61 (patch) | |
tree | aa850d4ee99fa0b14da9ba0396ba6aa67e2037e3 /osx/uninstall-pandoc.pl | |
parent | fccfc8429cf4d002df37977f03508c9aae457416 (diff) | |
parent | ce69021e42d7bf50deccba2a52ed4717f6ddac10 (diff) | |
download | pandoc-717e16660d1ee83f690b35d0aa9b60c8ac9d6b61.tar.gz |
Merge remote-tracking branch 'jgm/master' into dokuwiki
Diffstat (limited to 'osx/uninstall-pandoc.pl')
-rwxr-xr-x | osx/uninstall-pandoc.pl | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/osx/uninstall-pandoc.pl b/osx/uninstall-pandoc.pl new file mode 100755 index 000000000..a5194d9bd --- /dev/null +++ b/osx/uninstall-pandoc.pl @@ -0,0 +1,79 @@ +#!/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'; + +# 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) ); + +# Get the list of files to remove. +my @pkg_files = `pkgutil --volume '$volume' --only-files --files '$pkg_id'`; +@pkg_files = map { chomp; File::Spec->rel2abs($_, $volume) } @pkg_files; + +# Confirm uninistall with the user. +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 my $file (@pkg_files) { + if ( -e $file ) { + if ( system( 'sudo', 'rm', $file ) == 0 ) { + warn "Deleted $file\n"; + } else { + warn "Unable to delete $file: $?\n"; + die "Aborting Uninstall.\n"; + } + } else { + warn "File $file does not exist. Skipping.\n"; + } + } + + # Clean up the install. + if (system('sudo', 'pkgutil', '--forget', $pkg_id, '--volume', $volume) != 0) { + die "Unable to clean up install: $?\n"; + } + +} else { + + print "OK, aborting uninstall.\n"; + exit; +} + +print "Pandoc has been successfully uninstalled.\n"; +exit; |