#!/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;

my $SOURCE              = $ARGV[0];
my $DESTINATION		= $ARGV[2] . "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Installers/RemoteDesktopClient.pkg";

# Now copy the Client.pkg from source to destination:
$TEMPDIR=`mktemp -d  "/private/tmp/copypackages.XXXXXX"`;

chomp($TEMPDIR);
if ( ! -d "$TEMPDIR" ) {
        print "Error calling mktemp, exiting.";
        exit(1);
}

system("/usr/bin/ditto", "-v", "$SOURCE", $TEMPDIR. "/RemoteDesktopClient.pkg");
system("chown -hR root:admin '$TEMPDIR/RemoteDesktopClient.pkg'");
system("/usr/bin/ditto", "-v", $TEMPDIR. "/RemoteDesktopClient.pkg", $DESTINATION);
system("chown -hR root:admin '$DESTINATION'");

# And always return 0
exit(0);


