#!/usr/bin/perl
# $Id$

=head1 NAME

postflight

=head1 AUTHOR

Jeroen Daanen
9 feb 2007

=head1 SYNOPSIS

Remove the installed Sami Proofing Tools

=head1 DESCRIPTION

Tries to remove the installed Sami Proofing Tools.
Looks up installation location from file,
removes installed files, copies backupped files back
to that location

usage: perl uninstall.pl pathToThisScript pathWhereFilesWereCopiedTo
e.g. perl uninstall.pl /Application/SamiProofingTools /Applications/Microsoft Office 2004/Shared applications/Proofing tools

=head1 COPYRIGHT

(c) 2007, Polderland Language & Speech Technology bv

=head1 TODO

=over

=item -

?(pending task)

=back

=head1 CHANGES

$Log$
Revision 1.6  2007/11/29 12:23:23  sjur
Still more filename corrections/updates.

NOW the installation & deinstallation should work.

Revision 1.5  2007/10/10 07:11:16  sjur
Now completely removes both the installation directory (/Applications/SamiProofingTools/) and the Receipt bundle, ie a complete and clean uninstall (all files and traces are completely removed).

The receipt file needs to be removed when uninstalling to avoid messages saying that it is already installed, or that nothing needs to/can be installed when installing later.

The next version to be released will require a manual removal of the receipt file! This is due to fixing a version number issue in the installer package.

Revision 1.4  2007/10/05 07:29:12  sjur
Added support for SMJ hyphenation.

Update from Polderland.

Revision 1.3  2007/09/20 07:45:13  sjur
Updated script files with the new filenames.

Revision 1.2  2007/07/06 08:35:40  sjur
Updated the filenames of the installed files to follow the new names.

Revision 1.1  2007/05/11 07:45:47  sjur
Added most supporting files for the Mac installer package maker

Revision 1.4  2007/09/18 13:21:19  wilko
- Added Administrator check to InstallationCheck-script
- Added error string about non-administrator user to string-table
- Changed filenames, and adapted postflight and uninstall.pl script.

Revision 1.3  2007/03/07 13:47:50  jeroen
added hyphenator files

Revision 1.2  2007/02/15 14:10:08  jeroen
removed back up files, files are now installed as catalan and basque.
No hyphenator

Revision 1.1  2007/02/09 12:51:16  jeroen
added



=cut

use strict;
use integer;
no utf8;
use warnings;

#old files
my @oldfiles;

#new files
my @newfiles = (
    "SamiLuleAsBasque-sp",
    "SamiLuleLexWithBasqueRez",
    "SamiNortAsCatalan-sp",
    "SamiNortLexWithCatalanRez",
    "SamiNorthy-diclx",
    "SamiNorthy-patlx",
    "SamiNortAsCatalan-hy",
    "SamiLuleAsBasque-hy",
    "SamiLule_hy-dic.lex",
    "SamiLule_hy-pat.lex"
);

my $receiptDir  = "/Library/Receipts";
my $receiptFile = "Divvun installer.pkg";

sub syscal
{
    my ($cmd, @args) = @_;
    if(scalar(@args)){
    	system(($cmd, @args));
    } else {
	system($cmd);
    }
}

my $locationFile = "location";
my $budir = $ARGV[0];
my $InstallLocation = $ARGV[1];




#remove the new files from location
foreach my $newfile (@newfiles){
    syscal("rm", "$InstallLocation/$newfile");
}

#copy the old files

foreach my $oldfile (@oldfiles) {
    syscal("ditto", "-rsrcFork", "$budir/$oldfile", "$InstallLocation/$oldfile");
    syscal("chmod", "g+rw,o+r", "$InstallLocation/$oldfile");
    
}

#delete the old files
if(length($budir)){
    syscal("rm", "-R", "$budir");
    syscal("rm", "-R", "$receiptDir/$receiptFile");
}


#succes message
print STDERR "Finished automatic uninstallation from $InstallLocation\n";

exit 0;


