@@ -0,0 +1,81 @@
1+#!/usr/bin/perl
2+
3+# Script to remove all files installed by the OSX pandoc installer
4+# and unregister the package. Modified from a script contributed
5+# by Daniel T. Staal.
6+
7+use warnings;
8+use strict;
9+
10+use File::Spec;
11+
12+# The main info: this is the list of files to remove and the pkg_id.
13+my $pkg_id = 'net.johnmacfarlane.pandoc';
14+
15+my @pkg_info;
16+
17+# Find which, if any, volume Pandoc is installed on.
18+my $volume;
19+
20+# First check /, then other volumes on the box.
21+my $cur_test = `pkgutil --pkgs=$pkg_id`;
22+if ( $cur_test =~ m/$pkg_id/ ) {
23+ $volume = '/';
24+} else {
25+ opendir( my $dh, '/Volumes' ) or die "Can't list Volumes: $!\n";
26+ foreach my $dir ( readdir($dh) ) {
27+ next if $dir =~ m/^\./; # Skip dotfiles.
28+
29+ my $path = File::Spec->rel2abs( $dir, '/Volumes' );
30+ next if !( -d $path ); # Skip anything that isn't a directory.
31+
32+ my $cur_test = `pkgutil --pkgs=$pkg_id --volume '$path'`;
33+ if ( $cur_test =~ m/$pkg_id/ ) {
34+ $volume = $path;
35+ last;
36+ }
37+ }
38+}
39+
40+die "Pandoc not installed.\n" if !( defined($volume) );
41+
42+my @pkg_files = ();
43+my $f;
44+for $f (split '\n', `pkgutil --volume '$volume' --only-files --files $pkg_id`) {
45+ push @pkg_files, File::Spec->rel2abs($f, $volume);
46+};
47+
48+print "The following files will be deleted:\n\n";
49+print join("\n", @pkg_files);
50+print "\n\n";
51+print "Do you want to proceed and uninstall pandoc (Y/N)?";
52+my $input = <STDIN>;
53+
54+if ($input =~ m/^[Yy]/) {
55+
56+ # Actually remove the files.
57+ foreach $f (@pkg_files) {
58+ if (system("sudo rm $f") == 0) {
59+ warn "Deleted $f\n";
60+ } else {
61+ warn "Unable to delete $f: $!\n";
62+ warn "Aborting uninstall.\n";
63+ exit 1;
64+ }
65+ }
66+
67+ # Clean up the install.
68+ if (system("sudo pkgutil --forget $pkg_id --volume '$volume'") != 0) {
69+ warn "Unable to clean up install: $!\n";
70+ exit 1;
71+ }
72+
73+} else {
74+
75+ print "OK, aborting uninstall.\n";
76+ exit 0;
77+
78+}
79+
80+print "Pandoc has been successfully uninstalled.\n";
81+exit 0;