From 9330373465f2b235d910bd20d1f32198bdc1247c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexander=20K=C3=B6nig?= <Alexander.Koenig@eurac.edu>
Date: Fri, 29 Sep 2017 18:55:37 +0200
Subject: [PATCH] added a script to adapt the TOS based on the local.properties

---
 commul-customization/adapt_tos.pl | 78 +++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
 create mode 100644 commul-customization/adapt_tos.pl

diff --git a/commul-customization/adapt_tos.pl b/commul-customization/adapt_tos.pl
new file mode 100644
index 0000000..7409a1d
--- /dev/null
+++ b/commul-customization/adapt_tos.pl
@@ -0,0 +1,78 @@
+#!/usr/bin/perl
+
+use Modern::Perl '2015';
+
+my $tosfile = '/opt/repository/sources/dspace/dspace-xmlui/src/main/webapp/themes/UFAL/lib/html/terms-of-service.html';
+my $outfile = '/opt/repository/sources/dspace/dspace-xmlui/src/main/webapp/themes/UFAL/lib/html/terms-of-service.html.new';
+my $locpropfile = '/opt/repository/sources/dspace/local.properties';
+
+my ($repo_name,$centre_legal_entity,$full_address,$country,$city);
+
+open (my $tos, '<', $tosfile);
+open (my $out, '>', $outfile);
+open (my $lp, '<', $locpropfile);
+
+while (my $in = <$lp>)
+{
+	if ($in =~ /^dspace\.name/)
+	{
+		(undef,$repo_name) = split /=/, $in;
+		chomp $repo_name;
+		$repo_name =~ s/^\s//;
+	}
+	elsif ($in =~ /^lr.description.institution /)
+	{
+		(undef,$centre_legal_entity) = split /=/, $in;
+		chomp $centre_legal_entity;
+		$centre_legal_entity =~ s/^\s//;
+	}
+	elsif ($in =~ /^lr.description.location/)
+	{
+		(undef,$full_address) = split /=/, $in;
+		chomp $full_address;
+		$full_address =~ s/^\s//;
+	}
+	elsif ($in =~ /^lr.description.shortLocation/)
+	{
+		(undef,my $location) = split /=/, $in;
+		chomp $location;
+		($city,$country) = split /,/,  $location;
+		$city =~ s/^\s//;
+		$country =~ s/^\s//;
+	}
+}
+
+while (my $line = <$tos>)
+{
+	if ($line =~ /REPOSITORY_NAME/)
+	{
+		$line =~ s/\$REPOSITORY_NAME/$repo_name/;
+	}
+	if ($line =~ /A_CENTRE_OR_UNIT_WITH_LEGAL_PERSONALITY/)
+	{
+		$line =~ s/\$A_CENTRE_OR_UNIT_WITH_LEGAL_PERSONALITY/$centre_legal_entity/;
+	}
+	if ($line =~ /FULL_ADDRESS/)
+	{
+		$line =~ s/\$FULL_ADDRESS/$full_address/;
+	}
+	if ($line =~ /COUNTRY/)
+	{
+		$line =~ s/\$COUNTRY/$country/;
+	}
+	if ($line =~ /CITY/)
+	{
+		$line =~ s/\$CITY/$city/;
+	}
+	print $out $line;
+}
+
+	#print "-$repo_name--$centre_legal_entity--$full_address--$city--$country-\n";
+
+
+__DATA__
+$REPOSITORY_NAME							dspace.name
+$A_CENTRE_OR_UNIT_WITH_LEGAL_PERSONALITY	lr.description.institution
+$FULL_ADDRESS								lr.description.location
+$COUNTRY									lr.description.shortLocation[1]
+$CITY										lr.description.shortLocation[0]
-- 
GitLab