git.iko.soy/typeable/pandoc
on 2.11.1 help sign in
typeable/pandoc/macos/uninstall-pandoc.pl
79 lines 2.2 kB history raw
1#!/usr/bin/perl
3# Script to remove all files installed by the macOS pandoc installer
4# and unregister the package. Modified from a script contributed
5# by Daniel T. Staal.
7use warnings;
8use strict;
10use File::Spec;
12# The main info: this is the list of files to remove and the pkg_id.
13my $pkg_id = 'net.johnmacfarlane.pandoc';
15# Find which, if any, volume Pandoc is installed on.
16my $volume;
18# First check /, then other volumes on the box.
19my $cur_test = `pkgutil --pkgs=$pkg_id`;
20if ( $cur_test =~ m/$pkg_id/ ) {
21 $volume = '/';
22} else {
23 opendir( my $dh, '/Volumes' ) or die "Can't list Volumes: $!\n";
24 foreach my $dir ( readdir($dh) ) {
25 next if $dir =~ m/^\./; # Skip dotfiles.
27 my $path = File::Spec->rel2abs( $dir, '/Volumes' );
28 next if !( -d $path ); # Skip anything that isn't a directory.
30 my $cur_test = `pkgutil --pkgs=$pkg_id --volume '$path'`;
31 if ( $cur_test =~ m/$pkg_id/ ) {
32 $volume = $path;
33 last;
34 }
35 }
38die "Pandoc not installed.\n" if !( defined($volume) );
40# Get the list of files to remove.
41my @pkg_files = `pkgutil --volume '$volume' --only-files --files '$pkg_id'`;
42@pkg_files = map { chomp; File::Spec->rel2abs($_, $volume) } @pkg_files;
44# Confirm uninistall with the user.
45print "The following files will be deleted:\n\n";
46print join("\n", @pkg_files);
47print "\n\n";
48print "Do you want to proceed and uninstall pandoc (Y/N)?";
49my $input = <STDIN>;
51if ($input =~ m/^[Yy]/) {
53 # Actually remove the files.
54 foreach my $file (@pkg_files) {
55 if ( -e $file ) {
56 if ( system( 'sudo', 'rm', $file ) == 0 ) {
57 warn "Deleted $file\n";
58 } else {
59 warn "Unable to delete $file: $?\n";
60 die "Aborting Uninstall.\n";
61 }
62 } else {
63 warn "File $file does not exist. Skipping.\n";
64 }
65 }
67 # Clean up the install.
68 if (system('sudo', 'pkgutil', '--forget', $pkg_id, '--volume', $volume) != 0) {
69 die "Unable to clean up install: $?\n";
70 }
72} else {
74 print "OK, aborting uninstall.\n";
75 exit;
78print "Pandoc has been successfully uninstalled.\n";
79exit;