summaryrefslogtreecommitdiffstats
path: root/ldap/cm/fixSetupInf.pl
blob: bd10f5c60ab26ecacb6dcd86ecf63ae30768b9fd (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
#
# BEGIN COPYRIGHT BLOCK
# Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
# Copyright (C) 2005 Red Hat, Inc.
# All rights reserved.
# END COPYRIGHT BLOCK
#
#
#

$isNT = -d '\\';

if ($isNT) {
  $ServerDir = "/Brandx/Servers";
} else {
  $ServerDir = "/usr/brandx/servers";
}
$ServerDirKey = "DefaultInstallDirectory";

$input = shift;
$output = shift;
die "cannot open input file $input" unless open( FILE, $input );
die "cannot open output file $output" unless open( OUT, ">$output" );
$inGeneralSection = 0;
$addServerDir = 1; # add the server dir if it's not already there
while ( <FILE> ) {
	# if the line begins with Components and does not contain
	# slapd already, add ", slapd" to the end 
	# else, just copy the line to output
	if ( /^Components/ ) {
		chomp;
		if (! /slapd/) {
			$_ .= ", slapd";
			$addedSlapd = 1;
		}
		if (! /nsperl/) {
			$_ .= ", nsperl";
			$addedNSperl = 1;
		}
		if (! /perldap/) {
			$_ .= ", perldap";
			$addedPerLDAP = 1;
		}
		$_ .= "\n";
	}
	if ( $inGeneralSection && /^$ServerDirKey/ ) {
		$addServerDir = 0; # already there, don't add it
	}
	if ( $inGeneralSection && /^\[/ ) {
		if ( $addServerDir ) {
			$_ = "$ServerDirKey = $ServerDir\n$_";
			$addServerDir = 0;
		}
		$inGeneralSection = 0;
	}
	if ( /^\[General\]/ ) {
		$inGeneralSection = 1;
	}
	print OUT $_;
}

close ( FILE );

# now, print the slapd section information
if ($addedSlapd) {
	print OUT "\n[slapd]\n";
	print OUT "ComponentInfoFile = slapd/slapd.inf\n";
}

if ($addedNSperl) {
	print OUT "\n[nsperl]\n";
	print OUT "ComponentInfoFile = nsperl/nsperl.inf\n";
}

if ($addedPerLDAP) {
	print OUT "\n[perldap]\n";
	print OUT "ComponentInfoFile = perldap/perldap.inf\n";
}

close ( OUT ); 

exit(0);