#!/usr/bin/perl

# This script will replace the server side includes in all the
# shtml files for the atlas website.
# To call the script:
# ./movesite old_path new_path
#
# Example:
# ./movesite.pl /~igable/atlas/ /~web-atlas/atlas/


$oldpath = $ARGV[0];
$newpath = $ARGV[1];

system "find . -name \\*.shtml > list.txt";

system "cat list.txt";
print "Found the above .shtml files to change\n";
print "Do you wish to continue (y/n): ";
$answer = <STDIN>;
chomp($answer);
print "\n";

if($answer ne 'y'){
	system "rm list.txt";
	print "Terminating move.\n";
	exit 1;
}

open FILELIST, "list.txt" or die "can't open file list\n";

while($file =<FILELIST>){
	chomp($file);
	$fulltext = "";
	open FILE, $file or die "Can't open file $file\n";
	while ($line = <FILE>){
		
		$fulltext = $fulltext.$line;
	}
	
	$fulltext =~ s/\!--\#include virtual=\"$oldpath/\!--\#include virtual=\"$newpath/gs;
	
	$tempfile = $file;
	$tempfile =~ s/\.shtml/\.shtml.1/;
	open TEMPFILE , ">".$tempfile or die "Can't open $tempfile\n";

	print TEMPFILE $fulltext;
	close FILE;
	close TEMPFILE;
	
	system "rm $file";
	system "cp $tempfile $file";
}

close FILELIST;
system "rm list.txt";

