1
# BEGIN COPYRIGHT BLOCK
2
# This Program is free software; you can redistribute it and/or modify it under
3
# the terms of the GNU General Public License as published by the Free Software
4
# Foundation; version 2 of the License.
6
# This Program is distributed in the hope that it will be useful, but WITHOUT
7
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
10
# You should have received a copy of the GNU General Public License along with
11
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
12
# Place, Suite 330, Boston, MA 02111-1307 USA.
14
# In addition, as a special exception, Red Hat, Inc. gives You the additional
15
# right to link the code of this Program with code not covered under the GNU
16
# General Public License ("Non-GPL Code") and to distribute linked combinations
17
# including the two, subject to the limitations in this paragraph. Non-GPL Code
18
# permitted under this exception must only link to the code of this Program
19
# through those well defined interfaces identified in the file named EXCEPTION
20
# found in the source code files (the "Approved Interfaces"). The files of
21
# Non-GPL Code may instantiate templates or use macros or inline functions from
22
# the Approved Interfaces without causing the resulting work to be covered by
23
# the GNU General Public License. Only Red Hat, Inc. may make changes or
24
# additions to the list of Approved Interfaces. You must obey the GNU General
25
# Public License in all respects for all of the Program code and other code used
26
# in conjunction with the Program except the Non-GPL Code covered by this
27
# exception. If you modify this file, you may extend this exception to your
28
# version of the file, but you are not obligated to do so. If you do not wish to
29
# provide this exception without modification, you must delete this exception
30
# statement from your version and license this file solely under the GPL without
34
# Copyright (C) 2007 Red Hat, Inc.
35
# All rights reserved.
39
###########################
41
# This perl module provides a way to set up a new installation after
42
# the binaries have already been extracted. This is typically after
43
# using native packaging support to install the package e.g. RPM,
44
# pkgadd, depot, etc. This script will show the license, readme,
45
# dsktune, then run the usual setup pre and post installers.
47
##########################
52
@EXPORT = qw($SILENT $EXPRESS $TYPICAL $CUSTOM);
53
@EXPORT_OK = qw($SILENT $EXPRESS $TYPICAL $CUSTOM);
56
use Net::Domain qw(hostfqdn);
59
use Mozilla::LDAP::Conn;
60
use Mozilla::LDAP::Utils qw(normalizeDN);
61
use Mozilla::LDAP::API qw(ldap_explode_dn);
62
use Mozilla::LDAP::LDIF;
71
use vars qw($EXPRESS $TYPICAL $CUSTOM $SILENT);
79
# process command line options
80
Getopt::Long::Configure(qw(bundling)); # bundling allows -ddddd
83
print "@capbrand@ Directory Server Setup Program Version @PACKAGE_VERSION@\n";
88
Usage: $0 [--options] -- [args]
91
--version Print the version and exit
92
--debug Turn on debugging
93
--silent Use silent setup - no user input
94
--file=name Use the file 'name' in .inf format to supply the default answers
95
--keepcache Do not delete the temporary .inf file generated by this program
96
--logfile Log setup messages to this file - otherwise, a temp file will be used
97
--update Update an existing installation (e.g. after upgrading packages)
98
--continue (update only) keep going despite errors (also --force)
99
For all options, you can also use the short name e.g. -h, -d, etc. For the -d argument,
100
specifying it more than once will increase the debug level e.g. -ddddd
103
You can supply default .inf data in this format:
106
General.FullMachineName=foo.example.com
108
"slapd.Suffix=dc=example,dc=com"
109
Values passed in this manner will override values in an .inf file given with the -f argument.
116
$self = bless $self, $type;
123
$self->{res} = shift;
124
my ($silent, $inffile, $keep, $preonly, $logfile, $update, $force);
126
GetOptions('help|h|?' => sub { VersionMessage(); HelpMessage(); exit 0 },
127
'version|v' => sub { VersionMessage(); exit 0 },
128
'debug|d+' => \$DSUtil::debuglevel,
129
'silent|s' => \$silent,
130
'file|f=s' => \$inffile,
131
'keepcache|k' => \$keep,
132
'preonly|p' => \$preonly,
133
'logfile|l=s' => \$logfile,
134
'update|u' => \$update,
135
'continue|force|c' => \$force
138
$self->{silent} = $silent;
139
$self->{keep} = $keep;
140
$self->{preonly} = $preonly;
141
$self->{update} = $update;
142
$self->{force} = $force;
143
$self->{logfile} = $logfile;
144
$self->{log} = new SetupLog($self->{logfile});
145
DSUtil::setDebugLog($self->{log});
146
# if user supplied inf file, use that to initialize
147
if (defined($inffile)) {
148
$self->{inf} = new Inf($inffile);
150
$self->{inf} = new Inf;
153
# see if user passed in default inf values - also, command line
154
# arguments override those passed in via an inf file - this
155
# allows the reuse of .inf files with some parameters overridden
156
if (!$self->{inf}->updateFromArgs(@ARGV)) {
161
# this is the base config directory - the directory containing
162
# the slapd-instance instance specific config directories
163
$self->{configdir} = $ENV{DS_CONFIG_DIR} || "@instconfigdir@";
166
# log only goes the the logfile
170
$self->{log}->logMessage($level, "Setup", @_);
173
# msg does to the screen and optionally to the log file
174
# if you use msg like this:
175
# msg(0, "some message")
176
# it will go only to the screen
177
# if you use msg like this:
178
# msg($WARN, "some message")
179
# it will go to the screen and to the log at the $WARN level
180
# all messages are localizable - you must define a resource key
181
# the first string passed to this method is a resource key
182
# additional strings are used as "arguments" to that resource key
183
# if you want to print un-localizable messages, use debug or write
184
# directly to the log or screen
189
if (!$level && @ary) {
190
# e.g. msg(0, "string") - no logging
191
} elsif ($level and @ary and grep {/^$level$/} $self->{log}->levels()) {
192
# e.g. msg($WARN, "string") - print and log
194
# log at default INFO level
195
unshift @ary, $level;
198
# @text is an array of strings for one message or
199
# an array of array refs, each one is a message
201
my @text = shift @ary;
203
last if (!@text or !$text[0]);
205
# element is an array ref - just pass to getText
206
# else is a list of strings
207
# NOTE: this will NOT work if ary contains
208
# consecutive simple string errors not separated
209
# by an array ref e.g. this will work
210
# ARRAY, 'errkey', arg, arg, ARRAY
212
# ARRAY, 'errkey', arg, 'errkey2', arg2, ARRAY
213
while (@ary and !ref($ary[0])) {
214
push @text, shift @ary;
216
my $string = $self->{res}->getText(@text);
218
$self->log($level, $string);
227
if (!defined($code)) {
232
$self->msg($FATAL, 'setup_exiting', $self->{log}->{filename});
234
$self->msg($SUCCESS, 'setup_exiting', $self->{log}->{filename});
239
# get a list of the directory servers in configdir
242
if (!$self->{dirservers}) {
243
$self->{dirservers} = [];
244
for my $dir (glob("$self->{configdir}/slapd-*")) {
245
next if ($dir =~ /\.removed$/); # skip removed instances
247
$dir =~ s,$self->{configdir}/,,; # strip off dir part
248
push @{$self->{dirservers}}, $dir;
252
return @{$self->{dirservers}};
256
#############################################################################
257
# Mandatory TRUE return value.
264
# indent-tabs-mode: nil