#!/usr/bin/env perl # # BEGIN COPYRIGHT BLOCK # This Program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation; version 2 of the License. # # This Program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place, Suite 330, Boston, MA 02111-1307 USA. # # In addition, as a special exception, Red Hat, Inc. gives You the additional # right to link the code of this Program with code not covered under the GNU # General Public License ("Non-GPL Code") and to distribute linked combinations # including the two, subject to the limitations in this paragraph. Non-GPL Code # permitted under this exception must only link to the code of this Program # through those well defined interfaces identified in the file named EXCEPTION # found in the source code files (the "Approved Interfaces"). The files of # Non-GPL Code may instantiate templates or use macros or inline functions from # the Approved Interfaces without causing the resulting work to be covered by # the GNU General Public License. Only Red Hat, Inc. may make changes or # additions to the list of Approved Interfaces. You must obey the GNU General # Public License in all respects for all of the Program code and other code used # in conjunction with the Program except the Non-GPL Code covered by this # exception. If you modify this file, you may extend this exception to your # version of the file, but you are not obligated to do so. If you do not wish to # provide this exception without modification, you must delete this exception # statement from your version and license this file solely under the GPL without # exception. # # # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission. # Copyright (C) 2005 Red Hat, Inc. # All rights reserved. # END COPYRIGHT BLOCK # # This script is used to copy over files from 'install' directory # to the server instance. BEGIN { $isNT = -d "\\"; $PS = $isNT ? "\\" : "/"; $SEP = $isNT ? ";" : ":" ; $slapdExecName = $isNT ? "slapd.exe" : "ns-slapd"; # NT needs quotes around some things unix doesn't $quote = $isNT ? "\"" : ""; } $sroot = $ARGV[0]; $prefix = $ARGV[1]; $installDir = sprintf("%s%s%s%s%s%s%s", $sroot, ${PS}, "bin", ${PS}, "slapd", ${PS}, "install"); push @INC, "$sroot/bin/slapd/admin/bin"; require 'uname.lib'; my $os = &uname("-s"); my $shlibsuf; SWITCH: { if ($os eq "AIX") { $LIB_PATH = "LIBPATH" ; $shlibsuf = ".so"; last SWITCH ; } if ($os eq "HP-UX") { $LIB_PATH = "SHLIB_PATH" ; my $arch = &uname("-p"); if ($arch eq "ia64") { $shlibsuf = ".so"; } else { $shlibsuf = ".sl"; } last SWITCH ; } if ($isNT) { $LIB_PATH = "PATH" ; $shlibsuf = ".dll"; last SWITCH ; } else { $LIB_PATH = "LD_LIBRARY_PATH" ; $shlibsuf = ".so"; last SWITCH ; } } # This subroutine takes source directory and destination directory # as the arguments. sub copy_files { my $destDir = pop(@_); my $srcDir = pop(@_); my $buf = ""; my $bufsize = 8192; opendir(SRCDIR, $srcDir) || die "Can not open source directory $src_dir\n"; my @srcfiles = readdir(SRCDIR); closedir(SRCDIR); my $count = 0; while ($count <= $#srcfiles) { if ($srcfiles[$count] eq "." || $srcfiles[$count] eq ".." || $srcfiles[$count] eq "99user.ldif" ) { $count++; next; } my $fullpath_srcfile = sprintf("%s%s%s", $srcDir, ${PS}, $srcfiles[$count]); my $fullpath_destfile = sprintf("%s%s%s", $destDir, ${PS}, $srcfiles[$count]); open( SRC, $fullpath_srcfile ) || die "Can't open $fullpath_srcfile: $!\n"; open( DEST, ">$fullpath_destfile" ) || die "Can't create $fullpath_destfile: $!\n"; while (read(SRC, $buf, $bufsize)) { print DEST $buf; } close( SRC ); close( DEST ); $count++; } } # Copy schema ldiffiles from /bin/slapd/install/schema to # //config/schema sub copy_schema_files { my $schema_bakdir = sprintf("%s%s%s%s%s%s%s", $sroot, ${PS}, ${prefix}, ${PS}, "config", ${PS}, "schema-bak"); my $schema_srcdir = sprintf("%s%s%s", $installDir, ${PS}, "schema"); my $schema_destdir = sprintf("%s%s%s%s%s%s%s", $sroot, ${PS}, ${prefix}, ${PS}, "config", ${PS}, "schema"); # First, back up the original schema ldiffiles under schema-bak directory unless (-d $schema_bakdir) { mkdir ($schema_bakdir, 0755) || die "Cannot create directory $schema_bakdir: $!\n"; } copy_files( $schema_destdir, $schema_bakdir ); # Now, copy the latest schema ldiffiles copy_files( $schema_srcdir, $schema_destdir ); } sub modify_dse_ldif { my $dse_ldiffile = sprintf("%s%s%s%s%s%s%s", $sroot, ${PS}, ${prefix}, ${PS}, "config", ${PS}, "dse.ldif"); my $isOID = 0; my $isJPEG = 0; my $isSpInSt = 0; my $reqNameChange = 0; open( DSE, "$dse_ldiffile" ) || die "Can't open $dse_ldiffile: $!\n"; my $new_filename = "$dse_ldiffile"."_new"; open( OUTFILE, "> $new_filename" ); while($line = ) { $isOID = 1 if ( $line =~ /^dn:\s*cn=OID Syntax,\s*cn=plugins,\s*cn=config/i); $isJPEG = 1 if ( $line =~ /^dn:\s*cn=JPEG Syntax,\s*cn=plugins,\s*cn=config/i); $isSpInSt = 1 if ( $line =~ /^dn:\s*cn=Space Insensitive String Syntax,\s*cn=plugins,\s*cn=config/i); if( ($line =~ s/uid uniqueness/attribute uniqueness/) || ($line =~ s/uid-plugin/attr-unique-plugin/) ){ # the plugin name has changed $reqNameChange = 1; print OUTFILE $line; } else { print OUTFILE $line; } } close( DSE ); close(OUTFILE); if ($isOID && $isJPEG && $isSpInSt && !$reqNameChange) { # nothing to be done - just return unlink($new_filename); return; } if($reqNameChange){ # if the name change is required copy the contents of the edited dse.ldif_new to the dse.ldif open( DSE, ">$dse_ldiffile" ) || die "Can't open $dse_ldiffile: $!\n"; open( OUTFILE, "$new_filename" ) || die "Can't open $new_filename: $!\n"; while($line = ) { print DSE $line; } close( DSE ); close(OUTFILE); } unlink($new_filename) or die "Cannot unlink $new_filename \n"; open( DSE, ">>$dse_ldiffile" ) || die "Can't open $dse_ldiffile: $!\n"; unless ($isOID) { # Add OID Syntax entry print DSE "dn: cn=OID Syntax,cn=plugins,cn=config\n"; print DSE "objectClass: top\n"; print DSE "objectClass: nsSlapdPlugin\n"; print DSE "objectClass: extensibleObject\n"; print DSE "cn: OID Syntax\n"; print DSE "nsslapd-pluginPath: $sroot/lib/syntax-plugin$shlibsuf\n"; print DSE "nsslapd-pluginInitfunc: oid_init\n"; print DSE "nsslapd-pluginType: syntax\n"; print DSE "nsslapd-pluginEnabled: on\n"; print DSE "nsslapd-pluginId: oid-syntax\n"; print DSE "nsslapd-pluginVersion: 1.0.3\n"; print DSE "nsslapd-pluginVendor: 389 Project\n"; print DSE "nsslapd-pluginDescription: OID attribute syntax plugin\n"; print DSE "\n"; } unless ($isJPEG) { # Add JPEG Syntax entry print DSE "dn: cn=JPEG Syntax,cn=plugins,cn=config\n"; print DSE "objectClass: top\n"; print DSE "objectClass: nsSlapdPlugin\n"; print DSE "objectClass: extensibleObject\n"; print DSE "cn: JPEG Syntax\n"; print DSE "nsslapd-pluginPath: $sroot/lib/syntax-plugin$shlibsuf\n"; print DSE "nsslapd-pluginInitfunc: jpeg_init\n"; print DSE "nsslapd-pluginType: syntax\n"; print DSE "nsslapd-pluginEnabled: on\n"; print DSE "nsslapd-pluginId: jpeg-syntax\n"; print DSE "nsslapd-pluginVersion: 1.0.3\n"; print DSE "nsslapd-pluginVendor: 389 Project\n"; print DSE "nsslapd-pluginDescription: JPEG attribute syntax plugin\n"; print DSE "\n"; } unless ($isSpInSt) { # Add Space Insensitive String Syntax entry print DSE "dn: cn=Space Insensitive String Syntax,cn=plugins,cn=config\n"; print DSE "objectClass: top\n"; print DSE "objectClass: nsSlapdPlugin\n"; print DSE "objectClass: extensibleObject\n"; print DSE "cn: Space Insensitive String Syntax\n"; print DSE "nsslapd-pluginPath: $sroot/lib/syntax-plugin$shlibsuf\n"; print DSE "nsslapd-pluginInitfunc: sicis_init\n"; print DSE "nsslapd-pluginType: syntax\n"; print DSE "nsslapd-pluginEnabled: on\n"; print DSE "nsslapd-pluginId: spaceinsensitivestring-syntax\n"; print DSE "nsslapd-pluginVersion: 1.0.3\n"; print DSE "nsslapd-pluginVendor: 389 Project\n"; print DSE "nsslapd-pluginDescription: space insensitive string attribute syntax plugin\n"; print DSE "\n"; } close( DSE ); } sub get_changelog_dir { my $dse_ldiffile = sprintf("%s%s%s%s%s%s%s", $sroot, ${PS}, ${prefix}, ${PS}, "config", ${PS}, "dse.ldif"); my $inClEntry = 0; my $clDir; # first find the changelog dir, if any open( DSE, "$dse_ldiffile" ) || die "Can't open $dse_ldiffile: $!\n"; while() { if (/^dn:\s*cn=changelog5,\s*cn=config/i) { $inClEntry = 1; next; } if (/^\s*$/ && $inClEntry) { $inClEntry = 0; last; # not found, just abort } if ($inClEntry && /^nsslapd-changelogdir:\s*/i) { $clDir = $'; #' chomp($clDir); last; } } close( DSE ); return $clDir; } sub fix_changelog { my $clDir = shift; my $newver = shift; # look for the region files and remove them - they are the files # that start with "__" - like __db.001 opendir CLDIR, $clDir || die "Error: can't open changelog db dir $clDir: $!"; while (my $ff = readdir CLDIR) { unlink $clDir."/".$ff if ($ff =~ /^__/); } closedir CLDIR; # change the dbversion my $dbverfile = $clDir . "/DBVERSION"; my $tmpverfile = $clDir . "/DBVERSION.tmp"; open DBVER, $dbverfile or die "Error: could not read file $dbverfile: $!"; open TMPVER, ">$tmpverfile" or die "Error: could not write file $tmpverfile: $!"; while () { s/\d+\.\d+$/$newver/; print TMPVER; } close TMPVER; close DBVER; unlink $dbverfile; rename $tmpverfile, $dbverfile; } # get the new (current) version from slapd itself # not currently used sub getSlapdVersion { my $dir = shift; my $version = 0; # major version of e.g. 6.1 == 6 my $minor = 0; # minor version of e.g. 6.1 == 1 my $subminor = 0; # subminor version of e.g. 6.1.2 == 2 my $buildNumber = 0; my $progDir = "${PS}bin${PS}slapd${PS}server${PS}"; # find the slapd executable $prog = $dir . $progDir . $slapdExecName; if (! -f $prog) { die "Could not run slapd program $prog: $!"; } else { chdir($dir . $progDir); } open(F, "${quote}${quote}$prog${quote} -v${quote} 2>&1 |") or die "Could not run slapd program $prog: $!"; sleep(1); # allow some data to accumulate in the pipe # print "Output from $prog -v:\n"; while () { if (/^Red Hat-Directory\/(\d+)\.(\d+)(?:\.(\d+))?(?:b\d)*\s+(\S+)/) { $version = $1; $minor = $2; if ($4) { $subminor = $3; $buildNumber = $4; } else { $buildNumber = $3; } last; } elsif (/^389-Directory\/(\d+)\.(\d+)(?:\.(\d+))?(?:b\d)*\s+(\S+)/) { $version = $1; $minor = $2; if ($4) { $subminor = $3; $buildNumber = $4; } else { $buildNumber = $3; } last; } elsif (/^Fedora-Directory\/(\d+)\.(\d+)(?:\.(\d+))?(?:b\d)*\s+(\S+)/) { $version = $1; $minor = $2; if ($4) { $subminor = $3; $buildNumber = $4; } else { $buildNumber = $3; } last; } elsif (/^Netscape-Directory\/(\d+)\.(\d+)(?:\.(\d+))?(?:b\d)*\s+(\S+)/) { $version = $1; $minor = $2; if ($4) { $subminor = $3; $buildNumber = $4; } else { $buildNumber = $3; } last; } elsif (/^Netscape-Directory\(restrict?ed-mode\)\/(\d+)\.(\d+)(?:\.(\d+))?\s+(\S+)/) { # we can have restricted-mode or restriced-mode ... # version could be X.Y or X.Y.Z $version = $1; $minor = $2; if ($4) { $subminor = $3; $buildNumber = $4; } else { $buildNumber = $3; } last; } elsif (/^iPlanet-Directory\/(\d+)\.(\d+)\s+(\S+)/i) { $version = $1; $minor = $2; $buildNumber = $3; last; } } my $code = close(F); if ($version == 0) { die "\nCould not determine version of the directory server in $dir: \n"; } # distinguish the 4.1 and the 4.11 thanks to the buildNumber if (($version == 4) && ($minor == 1)){ if (! ($buildNumber =~ /^B99\.16/)) { # it's not a 4.1 Netscape Directory Server => it's a 4.11 $minor = 11 ; } } return ( $version, $minor, $subminor ); } # get the old version from the $sroot/setup/slapd/slapd.inf file # not currently used sub getInfVersion { my $inffile = "$sroot/setup/slapd/slapd.inf"; open INF, $inffile || die "Error: could not read file $inffile: $!"; my $inslapdsection = 0; while () { if (/^\[slapd\]/) { $inslapdsection = 1; } elsif ($inslapdsection && /^\[/) { $inslapdsection = 0; last; } elsif ($inslapdsection && /^\s*Version\s*=\s*(\d+)\.(\d+)(?:\.(\d+))?/) { close INF; return ($1, $2, $3); } } close INF; return ('0', '0'); } sub getChangelogVersion { my $cldir = shift; my $versionfile = $cldir . "/DBVERSION"; my $version = "0.0"; open DBVER, $versionfile or return '0.0'; while () { if (/(\d+\.\d+)$/) { $version = $1; } } close DBVER; return $version; } sub instantiate_new_package_scripts { my @newtemplates = ( "$sroot/bin/slapd/admin/scripts/template-cl-dump.pl", "$sroot/bin/slapd/admin/scripts/template-migrate5to7", "$sroot/bin/slapd/admin/scripts/template-migrate6to7", "$sroot/bin/slapd/admin/scripts/template-migrateInstance7", "$sroot/bin/slapd/admin/scripts/template-migrateTo7", "$sroot/bin/slapd/admin/scripts/template-repl-monitor-cgi.pl", ); foreach $src ( @newtemplates ) { $dest = "$sroot/bin/slapd/admin/bin/$1" if $src =~ /.*template-(.*)$/; # repl mon cgi script goes in bin/admin/admin/bin if ($src =~ /repl-monitor-cgi.pl/) { $dest =~ s@/bin/slapd/admin/bin/@/bin/admin/admin/bin/@; } unless ( open ( template, $src )) { print "Can't open $src: $!\n"; next; } unless ( open ( target, ">$dest" )) { print "Can't open $dest: $!\n"; close template; next; } while (