#!/usr/bin/perl # $Id$ =head1 NAME postflight =head1 AUTHOR Jeroen Daanen 8 feb 2007 =head1 SYNOPSIS postflight actions =head1 DESCRIPTION Will be executed after installation. - Creates backup directory of original files - copies the new files to the existing directory, overwriting the original files - Removes the temporary directory =head1 COPYRIGHT (c) 2007, Polderland Language & Speech Technology bv =head1 TODO =over =item - ?(pending task) =back =head1 CHANGES $Log$ Revision 1.10 2007/11/29 12:23:23 sjur Still more filename corrections/updates. NOW the installation & deinstallation should work. Revision 1.9 2007/11/29 11:20:28 sjur Updated two filenames that was forgotten. Lead to parts of the speller package not being installed, and thus no working spellers. Revision 1.8 2007/10/10 07:40:14 sjur Improved AppleScript uninstaller - now it doesn't give an error message if the user cancels the uninstallation. Whitespace changes to make the AppleScript syntax easier to read in the perl print code. Revision 1.7 2007/10/10 07:07:36 sjur Only formatting changes. Revision 1.6 2007/10/09 20:34:57 sjur • trimmed some folder references to avoid double slashes at the root level • changed the uninstaller from a terminal command to an AppleScript application (double-clickable). One more step to do: remove the folder containing the installed tools (/Applications/SamiProofingTools/) and the receipt file. Revision 1.5 2007/10/09 10:02:20 sjur New version from Polderland, which replaces the MacPerl call with a call to osascript. That makes the uninstallation more robust across OS installations. Revision 1.4 2007/10/05 07:27:49 sjur Added support for SMJ hyphenation. Better uninstaller with proper admin right request via AppleScript. 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.5 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.4 2007/03/07 13:47:50 jeroen added hyphenator files Revision 1.3 2007/02/15 14:10:08 jeroen removed back up files, files are now installed as catalan and basque. No hyphenator Revision 1.2 2007/02/09 12:51:35 jeroen included creation of uninstaller Revision 1.1 2007/02/09 10:10:01 jeroen adapted from other installation and added to repository =cut use strict; use integer; no utf8; use warnings; #posible installation directories my @dirs =( "Applications/Microsoft Office 2004/Shared applications/Proofing tools", "Applications/Microsoft Office 2004/Gedeelde toepassingen/Taalprogramma's", "Applications/Microsoft Office 2004/Gemeinsame Anwendungen/Korrekturhilfen", "Applications/Microsoft Office 2004/Aplicaciones compartidas/Herramientas de correccio\314\201n", "Applications/Microsoft Office 2004/Applications partage\314\201es/Outils de ve\314\201rification", "Applications/Microsoft Office 2004/Applicazioni condivise/Strumenti di correzione", "Applications/Microsoft Office 2004/Delade program/Spra\314\212kverktyg", "Applications/Microsoft Office 10/Shared applications/Proofing tools", "Applications/Microsoft Office 10/Gedeelde toepassingen/Taalprogramma's", "Applications/Microsoft Office 10/Gemeinsame Anwendungen/Korrekturhilfen", "Applications/Microsoft Office 10/Aplicaciones compartidas/Herramientas de correccio\314\201n", "Applications/Microsoft Office 10/Applications partage\314\201es/Outils de ve\314\201rification", "Applications/Microsoft Office 10/Applicazioni condivise/Strumenti di correzione", "Applications/Microsoft Office 10/Delade program/Spra\314\212kverktyg" ); my $installDir = $ARGV[2]."Applications/SamiProofingTools"; my $budir = ""; my $uninstallerApp = "$installDir/Remove SamiProofingTools.app"; my $uninstallerScriptFile = "$installDir/uninstallData/uninstall.pl"; my $uninstallerAppleScriptFile = "$installDir/uninstallData/uninstall.scpt"; #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" ); sub syscal { my ($cmd, @args) = @_; if(scalar(@args)){ system(($cmd, @args)); } else { system($cmd); } } my $firsttime = 1; foreach my $installdir (@dirs){ my $targetdir = $ARGV[2].$installdir; if(-e $targetdir){ #check if the budir already exists and create it if(length($budir)){ if (-e $budir){ #seems this installation has already run before $firsttime = 0; } else { syscal("mkdir", $budir); } } #copy old files to backup directory #only if this is the first time the installer is installed if($firsttime){ foreach my $oldfile (@oldfiles){ syscal("ditto", "-rsrcFork", "$targetdir/$oldfile", "$budir/$oldfile"); } } #always remove the old files foreach my $oldfile (@oldfiles){ syscal("rm", "$targetdir/$oldfile"); } #copy the new files from the installDir to the targetdir foreach my $newfile (@newfiles) { syscal("ditto", "-rsrcFork", "$installDir/$newfile", "$targetdir/$newfile"); syscal("chmod", "g+rw,o+r", "$targetdir/$newfile"); } #UNINSTALLATION: open(UAS, ">$uninstallerAppleScriptFile") or die "Cannot open $uninstallerAppleScriptFile. $!"; print UAS "try\n"; print UAS "do shell script \"\'$uninstallerScriptFile\' \'$installDir\' \'$targetdir\'\" with administrator privileges\n"; print UAS "tell application \"Finder\"\n"; print UAS "activate\n"; print UAS "display dialog \"Finished Automatic uninstallation from $targetdir\" buttons {\"OK\"}\n"; print UAS "end tell\n"; print UAS "on error errText number errNum\n"; print UAS "if (errNum is equal to -128) then\n"; print UAS "-- User cancelled, do nothing.\n"; print UAS "else\n"; print UAS "tell application \"Finder\"\n"; print UAS "activate\n"; print UAS "display dialog \"Uninstallation from $targetdir failed!\" & return & return & \"Cause: \" & errText buttons {\"OK\"}\n"; print UAS "end tell\n"; print UAS "end if\n"; print UAS "end try\n"; close(UAS) or die "Cannot close $uninstallerAppleScriptFile. $!"; #compile the uninstallation AppleScript into a double-clickable application syscal("osacompile", "-o", "$uninstallerApp", "$uninstallerAppleScriptFile"); #remove the applescript text file now that we have a compiled application: syscal("rm", "-f", "$uninstallerAppleScriptFile"); #changes file permissions in installation directory syscal("chmod", "-R", "g+rw,o+rw", "'$installDir'"); #we've found what we were looking for, exit the loop last; } } exit 0;