#!/usr/bin/perl use strict; use integer; no utf8; use warnings; #posible installation directories my @dirs =( "/Applications/Microsoft Office 2011/Office/Shared applications/Proofing tools", "/Applications/Microsoft Office 2011/Office/Gedeelde toepassingen/Taalprogramma's", "/Applications/Microsoft Office 2011/Office/Gemeinsame Anwendungen/Korrekturhilfen", "/Applications/Microsoft Office 2011/Office/Aplicaciones compartidas/Herramientas de correccio\314\201n", "/Applications/Microsoft Office 2011/Office/Applications partage\314\201es/Outils de ve\314\201rification", "/Applications/Microsoft Office 2011/Office/Applicazioni condivise/Strumenti di correzione", "/Applications/Microsoft Office 2011/Office/Delade program/Spra\314\212kverktyg", "/Applications/Microsoft Office 14/Office/Shared applications/Proofing tools", "/Applications/Microsoft Office 14/Office/Gedeelde toepassingen/Taalprogramma's", "/Applications/Microsoft Office 14/Office/Gemeinsame Anwendungen/Korrekturhilfen", "/Applications/Microsoft Office 14/Office/Aplicaciones compartidas/Herramientas de correccio\314\201n", "/Applications/Microsoft Office 14/Office/Applications partage\314\201es/Outils de ve\314\201rification", "/Applications/Microsoft Office 14/Office/Applicazioni condivise/Strumenti di correzione", "/Applications/Microsoft Office 14/Office/Delade program/Spra\314\212kverktyg" ); # This is the temporary installer folder, it will be deleted afterwards: my $sourceDir = $ARGV[2]."Library/DivvunTools/MSOffice2011"; $sourceDir =~ s/\/\//\//g; # Simplify double // which may result from $ARGV[2] being /: my $uninstallerApp = "$sourceDir/Remove Divvun for Office 2011.app"; my $uninstallerScriptFile = "$sourceDir/uninstallData/uninstall.pl"; my $uninstallerAppleScriptFile = "$sourceDir/uninstallData/uninstall.scpt"; my $title = "Divvun for MS Office 2011"; my $component_ID = "no.samediggi.divvun.msoffice.2011.proofingtools.pkg"; #new files my @newfiles = ( # sme: "SamiNortAsCatalan\ Hyphenator.proofingtool", "SamiNortAsCatalan\ Speller.proofingtool", # smj: "SamiLuleAsBasque\ Hyphenator.proofingtool", "SamiLuleAsBasque\ Speller.proofingtool", # sma: "SamiSoutAsSlovak\ Hyphenator.proofingtool", "SamiSoutAsSlovak\ Speller.proofingtool" ); my @oldfiles = @newfiles; my @collidefiles = ( "Catalan\ Hyphenator.proofingtool", "Catalan\ Speller.proofingtool", "Catalan\ Thesaurus.proofingtool" ); sub syscal { my ($cmd, @args) = @_; if(scalar(@args)){ # print STDERR "Divvun MSOffice2011 installer: command is: $cmd @args\n"; system(($cmd, @args)); } else { # print STDERR "Divvun MSOffice2011 installer: command is: $cmd\n"; system($cmd); } } foreach my $installdir (@dirs){ my $targetdir = $ARGV[2].$installdir; $targetdir =~ s/\/\//\//g; # simplify // # print STDERR "Divvun MSOffice2011 installer: targetdir is: $targetdir\n"; if(-e $targetdir){ my $testfile = "$targetdir/$collidefiles[1]"; if (-e $testfile) { # Archive colliding languages before installing our own: system("cd \"$targetdir\" && zip -qr Catalan Catalan*"); system("cd \"$targetdir\" && rm -rf Catalan\ Hyphenator.proofingtool"); system("cd \"$targetdir\" && rm -rf Catalan\ Speller.proofingtool"); system("cd \"$targetdir\" && rm -rf Catalan\ Thesaurus.proofingtool"); } #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;