
#!/usr/local/bin/perl
# 
# $Header: createtempfolder.pl 27-sep-2005.10:31:22 pshroff Exp $
#
# createtempfolder.pl
# 
# Copyright (c) 2005, Oracle. All rights reserved.  
#
#    NAME
#      createtempfolder.pl - <one-line expansion of the name>
#
#    DESCRIPTION
#      <short description of component this file declares/defines>
#
#    NOTES
#      <other useful comments, qualifications, etc.>
#
#    MODIFIED   (MM/DD/YY)
#    pshroff     09/27/05 - modifying as per OS/Image ReStrcuring
#    pshroff     08/29/05 - modifying folder-name from i386 to LinuxOSRoot 
#    pshroff     07/08/05 - adding more error handling 
#    pshroff     06/30/05 - pshroff_map_shiphome
#    rbhanush    06/10/05 - creating i386 folder and creating RedHat under it
#    rbhanush    05/06/05 - creating RedHat and its sub folders
#    rbhanush    03/22/05 - rbhanush_oscomp
#    rbhanush    03/21/05 - Added pathSeperator constant
#    pshroff     02/24/05 - Creation
# 

my $temp_folder=$ARGV[0];
my $rpms_folder=$ARGV[1];
my $base_folder=$ARGV[2];
my $username=$ARGV[3];

my $pathSeperator="/";
my $exitstatus;
 
mkdir $temp_folder;

#Creating RedHat/RPMS and RedHat/base folders 
my $rpms_path=$temp_folder.$pathSeperator.$rpms_folder;
my $create_rpm_cmd="mkdir -p $rpms_path";
system($create_rpm_cmd);
$exitstatus = $? >> 8;

if ($exitstatus == 0)
{
    my $base_path=$temp_folder.$pathSeperator.$base_folder;
    my $create_base_cmd="mkdir -p $base_path";
    system($create_base_cmd);
    $exitstatus = $? >> 8;

     if ($exitstatus == 0)
    {
        $command="cp /root/anaconda-ks.cfg $temp_folder";
        system($command);
        $exitstatus = $? >> 8; 
        if ($exitstatus == 0)
        {
            $command="chown -R $username $temp_folder";
            system($command);
            exit ($? >> 8);
        }
    }
}
exit $exitstatus;
