#!/usr/bin/perl use strict; use integer; no utf8; use warnings; #posible installation directories my @dirs =( "/Applications/Microsoft Office 2008/Office/Shared applications/Proofing tools", "/Applications/Microsoft Office 2008/Office/Gedeelde toepassingen/Taalprogramma's", "/Applications/Microsoft Office 2008/Office/Gemeinsame Anwendungen/Korrekturhilfen", "/Applications/Microsoft Office 2008/Office/Aplicaciones compartidas/Herramientas de correccio\314\201n", "/Applications/Microsoft Office 2008/Office/Applications partage\314\201es/Outils de ve\314\201rification", "/Applications/Microsoft Office 2008/Office/Applicazioni condivise/Strumenti di correzione", "/Applications/Microsoft Office 2008/Office/Delade program/Spra\314\212kverktyg", "/Applications/Microsoft Office 12/Office/Shared applications/Proofing tools", "/Applications/Microsoft Office 12/Office/Gedeelde toepassingen/Taalprogramma's", "/Applications/Microsoft Office 12/Office/Gemeinsame Anwendungen/Korrekturhilfen", "/Applications/Microsoft Office 12/Office/Aplicaciones compartidas/Herramientas de correccio\314\201n", "/Applications/Microsoft Office 12/Office/Applications partage\314\201es/Outils de ve\314\201rification", "/Applications/Microsoft Office 12/Office/Applicazioni condivise/Strumenti di correzione", "/Applications/Microsoft Office 12/Office/Delade program/Spra\314\212kverktyg" ); # This is the library installer dir, from which the tools will be copied into the proper Word dir: my $sourceDir = $ARGV[2]."Library/DivvunTools/MSOffice2008"; $sourceDir =~ s/\/\//\//g; # Simplify double // which may result from $ARGV[2] being /: my $uninstallerApp = "$sourceDir/Remove Divvun for Office 2008.app"; my $uninstallerScriptFile = "$sourceDir/uninstallData/uninstall.pl"; my $uninstallerAppleScriptFile = "$sourceDir/uninstallData/uninstall.scpt"; my $title = "Divvun for MS Office 2008"; my $component_ID = "no.samediggi.divvun.msoffice.2008.proofingtools.pkg"; #new files my @newfiles = ( # sme: "SamiNortAsCatalanHyphenation.proofingtool", "SamiNortAsCatalanSpeller.proofingtool", # smj: "SamiLuleAsBasqueHyphenation.proofingtool", "SamiLuleAsBasqueSpeller.proofingtool", # sma: "SamiSoutAsSlovakHyphenation.proofingtool", "SamiSoutAsSlovakSpeller.proofingtool" ); my @oldfiles = @newfiles; sub syscal { my ($cmd, @args) = @_; if(scalar(@args)){ # print STDERR "Divvun MSOffice2008 installer: command is: $cmd @args\n"; system(($cmd, @args)); } else { # print STDERR "Divvun MSOffice2008 installer: command is: $cmd\n"; system($cmd); } } foreach my $installdir (@dirs){ my $targetdir = $ARGV[2].$installdir; $targetdir =~ s/\/\//\//g; # simplify // # print STDERR "Divvun MSOffice2008 installer: targetdir is: $targetdir\n"; if(-e $targetdir){ #always remove the old files before installing the new ones: foreach my $oldfile (@oldfiles){ syscal("rm", "-rf", "$targetdir/$oldfile/"); } #copy the new files from the installDir to the targetdir foreach my $newfile (@newfiles) { syscal("cp", "-fR", "$sourceDir/$newfile", "$targetdir/$newfile"); syscal("chmod", "-R", "g+rw,o+r", "$targetdir/$newfile"); } #UNINSTALLATION: open(UAS, ">$uninstallerAppleScriptFile") or die "Cannot open $uninstallerAppleScriptFile. $!"; print UAS "display dialog (localized string of \"Are you sure you want to uninstall:\") & return & return & \"$title\" with title (localized string of \"Uninstall\") & \": $title\" with icon caution buttons {{localized string of \"Cancel\"}, {localized string of \"Uninstall\"}} cancel button 1 default button 2\n"; print UAS "try\n"; print UAS "do shell script \"\'$uninstallerScriptFile\' \'$sourceDir\' \'$targetdir\' \'$component_ID\'\" with administrator privileges\n"; print UAS "tell application \"Finder\"\n"; print UAS "activate\n"; print UAS "display dialog (localized string of \"Finished uninstallation of\") & return & return & \"$title\" with title (localized string of \"Uninstallation done\") buttons {localized string of \"OK\"} default button 1\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 (localized string of \"Uninstallation failed.\") & return & return & (localized string of \"Cause:\") & errText with title (localized string of \"Uninstallation failed.\") with icon caution buttons {localized string of \"OK\"} default button 1\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"); #copy locale files to uninstaller app: system("cp -rf $sourceDir/*.lproj \"$uninstallerApp/Contents/Resources/\""); system("rm -rf $sourceDir/*.lproj"); #we've found what we were looking for, exit the loop last; } } exit 0;