#!/usr/bin/perl

# ARGV[0] = Path to package being installed 
# ARGV[1] = Destination path of where package is being installed
# ARGV[2] = Mountpoint of the destination volume
# ARGV[3] = Path to the directory containing the System folder that contains the active Installation framework. 

use File::Spec;

# THIS VERSION OF THE FILE IS FOR THE SOFTWARE UPDATE

# Get the folder we're sitting in:
my $packageContainerPath = File::Spec->canonpath($ENV{'PACKAGE_PATH'});

# Inside of this is the stuff to be copied across:
my $SOURCE_OF_GOODNESS = $packageContainerPath . "/Contents/Resources/Installers/";

# The ARD app is not currently relocatable, so here's where we're installing stuff:
my $DESTINATION_IN_APP = $ARGV[2] . "/Applications/Remote Desktop.app/Contents/Resources/Installers/";

# Now copy the Client mpkg from source to destination:
system(	"/usr/bin/ditto", "-v", 
		$SOURCE_OF_GOODNESS . "RemoteDesktopClient220.mpkg", 
		$DESTINATION_IN_APP . "RemoteDesktopClient220.mpkg");
		
# Now we need to copy the receipt renamer script into the PantherSharing script's postflight_actions so
# it can move the receipt out of the way when that thing goes.

# Here's where it comes from:
my $RECEIPT_NAME	= $ENV{'RECEIPT_PATH'};
my $RENAMER_SCRIPT	= $RECEIPT_NAME . "/zz_RenameReceipt";

# Here's where it goes to:
my $WHERE_RENAMER_GOES = $DESTINATION_IN_APP . "RemoteDesktopClient220.mpkg/Contents/Installers/PantherSharing.pkg/Contents/Resources/postflight_actions/";

#print "-----\nSource: $RENAMER_SCRIPT\nDestionation: $WHERE_RENAMER_GOES\n-----\n";

#So let's copy it on down there:
system("/bin/cp", "-v", $RENAMER_SCRIPT, $WHERE_RENAMER_GOES);


# And now whack the placeholder
system( "/bin/rm", "-rf", $DESTINATION_IN_APP . "RemoteDesktopClient220.mpkg/Contents/Installers/placeholder");

# And now whack the old client mpkgs
system( "/bin/rm", "-rf", $DESTINATION_IN_APP . "RemoteDesktopClient200.mpkg");
system( "/bin/rm", "-rf", $DESTINATION_IN_APP . "RemoteDesktopClient210.mpkg");

# And always return 0
exit(0);

