aboutsummaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/scripts/install/siteconf.pl
blob: d035851d06aba9b3b869d8a5d41bbd838b43172f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/perl
# CC_ID_SITECONF_PL[] = "@(#)/vobs/waas/src/oam/siteconf.pl@@/main/4"

#.Description
# This perl script takes as input template file, 
# and one or more configuration files.  It uses the values in the 
# configuration files as substitutions for the matching tags in the template 
# file.

#.Constraints
# The input files must be readable by the script.

#.See Also
#

use Getopt::Std;

local $dbg=0;

getopts ('dt:c:');

if ($opt_d) {
	$dbg=$opt_d;
}

if ($dbg) {
	print STDERR "opt_d=$opt_d\n";
	print STDERR "opt_t=$opt_t\n";
	print STDERR "opt_c=$opt_c\n";
}

###
# Print usage if no arguments passed
if (! $opt_t) {
	print STDERR "Usage:  $0 -t templatefile -c configfilelist\n";
	exit (1);
}

# process the template file variable
if ($opt_t) {
	if (! -r $opt_t) {
		print STDERR "Error:  Can't read template file $opt_t\n";
		exit (2);
	}
	$templatefile = $opt_t;
}
else {
	print STDERR "Error:  You must enter the template file name\n";
	exit (2);
}

###
# Global error flag for return code when exiting
$err = 0;

$configlist = '';
if ($opt_c) {
	$configlist = $opt_c;
}

# process the site configuration file variable
if ($configlist) {
	@siteary = split /,/, $configlist; 
}

# Add PROJECT_HOME to Conf dictionary
$Conf{'PROJECT_HOME'} = $ENV{'PROJECT_HOME'};

foreach $arg (@siteary) {
	if ($dbg) { print STDERR "Opening $arg\n" }

	open(CONF, $arg) || die $!, ", '$arg'\n";

	while (<CONF>) {
	    #1 while chomp();
	    $_ =~ s/[\r\n]$//g; # strip newlines and dos-injected carriage returns
		if ( /=/ ) {
			($attr,$value) = split(/=/,$_,2);
			$value =~ s/\$PHOME/$ENV{'PROJECT_HOME'}/;
			$value =~ s/\$PROJECT_HOME/$ENV{'PROJECT_HOME'}/;
			$Conf{$attr} = $value;
		}
	}

	close CONF;
}

if ($dbg) { print STDERR "Expanding $templatefile\n" }

# Expand a config file 

open(TEMPLATE, $templatefile) || die $!, ", '$templatefile'\n";
while (<TEMPLATE>) {
	# handle strings such as @HTTP_ROOT@@HTTP_PORT@
	s/@(\w+)@/$Conf{$1}/g;
	print;
}
	
close TEMPLATE;