# This file is part of EPrints 3.
# Copyright (c) 2007 University of Southampton, UK. SO17 1BJ.
#
# *******************
# NOTE: This file is NOT licensed under the GPL!
# This code may not be redistributed in any way or for any purpose.
# *******************

use Data::Dumper;

print <<END;
EPrints 3 initial configuration
-------------------------------

Please enter the fully qualified host name of your site's SMTP server.
Example: smtp.example.org

END

my $input = <STDIN>;
$input =~ s/\r?\n?$//;
while ($input !~ /^\S+$/) {
	print "Invalid input; please try again.";
	$input = <STDIN>;
	$input =~ s/\r?\n?$//;
}

my $smtp = $input;

print <<END;

Setting configuration, and applying Windows platform customizations...

END

my $syshash = {
	apache => "2",
	smtp_server=>$smtp,
	base_path => "C:/EPrints/EPrints",
	geoip => {
		class => "Geo::IP",
		country => "/usr/local/share/GeoIP/GeoIP.dat",
		organisation => "/usr/local/share/GeoIP/GeoOrg.dat",
	},
	executables => {
		unzip 	=> "/usr/bin/unzip",
		wget 	=> "/usr/bin/wget",
		sendmail => "/usr/sbin/sendmail",
		gunzip 	=> "/bin/gunzip",
		tar 	=> "/bin/tar",
		latex 	=> "/usr/bin/latex",
		dvips 	=> "/usr/bin/dvips",
		convert	=> "C:/EPrints/ImageMagick/convert.exe",
		mimetex	=> "/export/0/home/cjg/Projects/eprints2_stable/eprints/system/mimetex.cgi",
		cp		=> "/bin/cp",
		rm		=> "/bin/rm",
	},
	invocation => {
		zip 	=> '$(unzip) 1>/dev/null 2>&1 -qq -o -d \'$(DIR)\' \'$(ARC)\'',
	        targz  	=> '$(gunzip) -c < \'$(ARC)\' 2>/dev/null | $(tar) xf - -C \'$(DIR)\' >/dev/null 2>&1',
		wget 	=> '$(wget)  -r -L -q -m -nH -np --execute="robots=off" --cut-dirs=$(CUTDIRS) \'$(URL)\'',
		sendmail => '$(sendmail) -oi -t -odb --',
		latex => '$(latex) \'$(SOURCE)\'',
		dvips => '$(dvips) \'$(SOURCE)\' -o \'$(TARGET)\'',
		convert_crop_white => '$(convert) -crop 0x0 -bordercolor white -border 4x4 \'$(SOURCE)\' \'$(TARGET)\'',
		cpall => '$(cp) -pR \'$(SOURCE)\'/* \'$(TARGET)\'',
		rmall => '$(rm) -rf \'$(TARGET)\'/*',
	},
	archive_extensions => {
		"zip"    =>  ".zip",
		"targz"  =>  ".tar.gz",
	},
	archive_formats => [ "zip", "targz" ],
	version_id => "CVS",
	version => "EPrints 3 (development version)",
	user => "eprints",
	group => "eprints",
	disable_df => 1,
	show_ids_in_log => 0,
	enable_gdome => 0,
	file_perms => 0664,
	dir_perms => 02775,
	platform => "w32",

};

my $dumper = Data::Dumper->new(
	[ $syshash ],
	[ 'EPrints::SystemSettings::conf' ]);

open(OUT, ">perl_lib/EPrints/SystemSettings.pm");
binmode OUT;
print OUT <<END;
package EPrints::SystemSettings;

END
print OUT $dumper->Dump();
print OUT <<END;

1;
END
close(OUT);

{
open(IN, "lib/defaultcfg/cfg.d/oai.pl");
binmode IN;
my @lines = <IN>;
close(IN);
open(OUT, ">lib/defaultcfg/cfg.d/oai.pl");
binmode OUT;
foreach my $line (@lines) {
	print OUT $line unless $line =~ /OAI_UKETD_DC/;
}
close(OUT);
}

open(OUT, ">perl_lib/EPrints/Platform/W32.pm");
binmode(OUT);
while(<DATA>) { print OUT $_; }
close(OUT);

print <<END;

Installation complete. Press [Enter] to exit.

END
<STDIN>;

__DATA__
######################################################################
#
# EPrints::Platform::W32
#
######################################################################
#
# This file is part of EPrints 3.
# Copyright (c) 2007 University of Southampton, UK. SO17 1BJ.
#
# *******************
# NOTE: This file is NOT licensed under the GPL!
# This code may not be redistributed in any way or for any purpose.
# *******************
#
######################################################################


=pod

=head1 NAME

B<EPrints::Platform> - Functions for the W32 Platform

=over 4

=cut

package EPrints::Platform::W32;

use strict;
use EPrints::Time;

sub chmod 
{
	return 1;
} 

sub chown 
{
	return 1;
}

sub getgrnam 
{
	return undef;
}

sub getpwnam 
{
	return undef;
}

sub test_uid
{
	return 1;
}

sub mkdir {
	my ($full_path, $perms) = @_;
	use File::Path;
	return mkpath([$full_path], 0, $perms);
}

sub exec {
	my( $repository, $cmd_id, %map ) = @_;

	my $command = $repository->invocation( $cmd_id, %map );

	
	$command =~ s/\\/\\\\/g;
	$command =~ s/\"/\\\"/g;
	$repository->log( "Executing command: $command" );


	$repository->log( "External command support not implemented." );
	return 1;
}

sub get_hash_name
{
	my $timestamp = EPrints::Time::get_iso_timestamp();
	$timestamp =~ s/:/_/g;
	return "$timestamp.xsh";
}
1;
