#!/bin/sh
. /etc/storade/setup
$RASSBIN/run_perld $* <<'EOF'

#
# Usage:
#  cd /opt/SUNWstade
#  relocate rasserv/conf/httpd.conf
#

$RASHOME= $ENV{RASHOME};

foreach my $f (@ARGV) {
  print "RELOCATE $f\n";

  my ($new, $change);
  open(O, $f);
  while ($l = <O>) {
    if ($l =~ /\$(RAS\w+)/ && exists $ENV{$1}) {
      my $n = $1;
      my $v = $ENV{$n};
      $l =~ s/\$$n/$v/;
      $change++;
    }
    $new .= $l;
  }
  close(O);
  if ($change) {
     &write($f, $new);
  }
}

sub write {
  my($file, $new) = @_;
  my @dirs = split(/\//, $file);
  my $BASE0 = "$RASHOME/DATA/reloc";
  my $BASE = $BASE0;
  mkdir $BASE, 0775 if (! -d $BASE);
  for ($x=0; $x < $#dirs; $x++) {
     my $dir = "$BASE/$dirs[$x]";
     mkdir $dir, 0775 if (! -d $dir);
     $BASE .= "/$dirs[$x]";
  }
  open(O, ">$BASE0/$file");
  print O $new;
  close(O);
}


EOF
