## PERL SCRIPT FOR CONFIGURING iFOLDER ON LINUX CLUSTER
## Author: Yatin Manerker
## Email : ymanerker@novell.com


############## Main program starts here  
print"#####################################################\n";
print"Example: Enter the path of shared volume:/mnt/ifolder\n";
print"#####################################################\n";
print"Enter the path of the shared volume:";
my $get_path=<STDIN>;
chomp($get_path);


#Stop ifolder services
system ('/etc/init.d/novell-ifolder stop');


#create directory on the shared disk
$directory1="mkdir -p $get_path/etc/opt/novell/ifolder";
system ($directory1);
$directory2="mkdir -p $get_path/var/opt/novell/ifolder";
system ($directory2);
$directory3="mkdir -p $get_path/srv/www/ifolder";
system ($directory3);

##### copy the content to shared volume
$copy1="cp -av /etc/opt/novell/ifolder/* $get_path/etc/opt/novell/ifolder/";
system($copy1);
$copy2="cp -av /var/opt/novell/ifolder/* $get_path/var/opt/novell/ifolder/";
system($copy2);
$copy3="cp -av /srv/www/ifolder/* $get_path/srv/www/ifolder/";
system($copy3);


sleep(5);
#############Configure httpd.conf and httpd_ifolder_unix.conf
&configure_conf_files;

############### recreate link on cluster
#system('rm /opt/novell/ifolder/DocumentRoot');
#$link='ln -s /opt/novell/ifolder/DocumentRoot'.$getpath.'/var/opt/novell/ifolderDocumentRoot';
#system($link);

############# End of main program



############################ SUB PROGRAM STARTS HERE ############################################################
sub configure_conf_files
{
for($j=0;$j<2;$j++)
{
for($i=0;$i<3;$i++)
{
  @file=($get_path.'/etc/opt/novell/ifolder/conf/httpd.conf',$get_path.'/etc/opt/novell/ifolder/conf/httpd_ifolder_unix.conf');
  @search= ('/etc/opt/novell/ifolder','/var/opt/novell/ifolder','/srv/www/ifolder');
  @replace=($get_path.'/etc/opt/novell/ifolder',$get_path.'/var/opt/novell/ifolder',$get_path.'/srv/www/ifolder');

  my @contents;

  open (F, $file[$j]) || die "Can't open - $!\n";
  @File = <F>;
  close (F);

  open (F, ">$file[$j]") || die "Can't open - $!\n";

  for (@File) {
    s/$search[$i]/$replace[$i]/;
    push(@contents,$_);
  }

  # Go to the beginning of the file
  seek(F,0,0);

  # Update the contents with the data from our array
  print F (@contents);
  close(F);
 }
} 
}
################################### End of SUB PROGRAM









