#!/usr/bin/perl

#####################################################################################################
#
# Restore the permissions of the root node of the install
#
#####################################################################################################

my $permissions_info_file = "/tmp/com.apple.installation.savedperm";
my @stat_info;
my $MODE = 2;
my $UID = 4;
my $GID = 5;

my $destPath = $ARGV[2];


if(-e $permissions_info_file) {
	if(open(PERMS_FILE_HDL, "$permissions_info_file")) {
		while(<PERMS_FILE_HDL>) {
			my $item = $_;
			chomp($item);
			push(@stat_info, $item);
		}
		close(PERMS_FILE_HDL);
		unlink($permissions_info_file);

		chown($stat_info[$UID], $stat_info[$GID], $destPath);
		chmod($stat_info[$MODE] & 07777, $destPath);
	}
} else {
	
	print "Couldn\'t find saved permissions file.\n";

}
