#!perl # # BEGIN COPYRIGHT BLOCK # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission. # Copyright (C) 2005 Red Hat, Inc. # All rights reserved. # END COPYRIGHT BLOCK # # print begin message $now_time = gmtime; print "BEGIN DSGW migration at ", $now_time, " GMT\n"; # get the commandline options if (!getopts('s:d:h:') || !$opt_s || !$opt_d || !$opt_h ) { print "usage: dsgwmig options\n"; print "\noptions:\n"; print " -s directory\tdirectory containing the 3.0 Gateway\n"; print " -d directory\tdirectory containing the 4.1 Gateway\n"; print " -h host[:port]\tthe host and port of the directory server\n"; print " \t\t\tto which the migrated gateway will query\n"; print "\nexample:\n dsgwmig -s /usr/tmp/ds30/slapd-host/dsgw -d /usr/tmp/ds40/dsgw -h gargoyle:1974\n"; exit; } sub reportAndExit { my $now_time = gmtime; print "END DSGW migration at ", $now_time, " GMT\n"; print "DSGW Exit status is ", $exitCode, "\n"; if ($? == 0 && $exitCode == 0) { print "NMC_STATUS: 0\n"; } else { print '$?=', $?+0, ' $!=', $!+0, ' $exitCode=', $exitCode, "\n"; print shift, "\n"; print "NMC_STATUS: $exitCode\n"; } print "###DSGW MIGRATION FINISHED###\n"; exit($exitCode); } $SIG{__DIE__} = 'exit'; $SIG{'QUIT'} = 'exit'; $SIG{'INT'} = 'exit'; $SIG{'TERM'} = 'exit'; # the atexit handler END { $! = 0; $? = $exitCode; &reportAndExit; } # setup the path separator $isNT = -d '\\'; $PS = $isNT ? "\\" : "/"; #make sure that the target directory exists if (! -e $opt_d) { print "$opt_d does not exist\n"; exit; } print "Migrating the config directory...\n"; # First migrate the config directory migrate_html("config"); print "Migrating the html directory...\n"; # Then migrate the html directory migrate_html("html"); print "Migrating the dsgw.conf...\n"; # Then migrate dsgw.conf migrate_config(); # Then copy over certain files like alert.html, confirm.html and emptyFrame from # the regular *4.1* DSGW to the newly migrated *4.1* gateway. if (! -e "$opt_d"."$PS"."html-30"."$PS"."alert.html") { print "copy ", "$opt_d"."$PS"."html"."$PS"."alert.html", " $opt_d"."$PS"."html-30"."$PS"."alert.html", "\n"; copyFile("$opt_d"."$PS"."html"."$PS"."alert.html", "$opt_d"."$PS"."html-30"."$PS"."alert.html"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."confirm.html") { print "copy ", "$opt_d"."$PS"."html"."$PS"."confirm.html", " $opt_d"."$PS"."html-30"."$PS"."confirm.html", "\n"; copyFile("$opt_d"."$PS"."html"."$PS"."confirm.html", "$opt_d"."$PS"."html-30"."$PS"."confirm.html"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."confirm.gif") { copyFile("$opt_d"."$PS"."html"."$PS"."confirm.gif", "$opt_d"."$PS"."html-30"."$PS"."confirm.gif"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."alert.gif") { copyFile("$opt_d"."$PS"."html"."$PS"."alert.gif", "$opt_d"."$PS"."html-30"."$PS"."alert.gif"); } if (! -e "$opt_d"."$PS"."html-30"."$PS"."emptyFrame.html") { copyFile("$opt_d"."$PS"."html"."$PS"."emptyFrame.html", "$opt_d"."$PS"."html-30"."$PS"."emptyFrame.html"); } print "end of migratedsgw\n"; $exitCode = 0; exit $exitCode; sub migrate_html { my $target_dir = shift(@_); my $orig_target = "$target_dir"; my $full_target_dir; my @subdirlist; my @dsgwfiles; # cd into the source directory chdir "$opt_s"."$PS"."$target_dir" or die "Unable to cd to $opt_s$PS$target_dir: $!\n"; # read the files opendir DSGW_OLD, "." or die "$!"; @dsgwfiles = grep !/^\.\.?$/, readdir DSGW_OLD; closedir DSGW_OLD; # Before we go on, we need to make the directory # in the 4.1 space. If we're working on the config # or html directory, then we have to rename them. $target_dir =~ s/^(config|html)/$1\-30/; $full_target_dir = "$opt_d". "$PS". "$target_dir"; if (! -d $full_target_dir) { mkdir $full_target_dir, 0755 or die "can't create $opt_d$PS$target_dir. $!\n"; } # foreach file in the current directory, # either skip it (if it's a subdir) # copy it to the new directory # copy and modify it to the new directory foreach $file (@dsgwfiles){ # #Skip directories if (-d $file) { # print "Skipping Directory $file\n"; push @subdirlist, $file; next; } if ($file =~ m/.*?\.html/) { # open the old file open(OLDFILE, "$file") or die "Cannot read $file. $!\n"; # open the new file open(NEWFILE, ">"."$full_target_dir"."$PS"."$file") or die "Cannot write $full_target_dir$PS$file. $!\n"; for ($line=; $line ; $line=) { # replace all ACTION=/ds/cgi with ACTION=/dsgw/bin/cgi $line =~ s:(?i)(action\s*=\s*("){0,1}\s*(http(s){0,1}\://.*?){0,1})/ds/(\w*):$1/dsgw/bin/$5:g; #")) # Langify the gifs, but not those that are already langified. Look for ="blah.gif" $line =~ s:(?i)=\s*("){0,1}\s*([\w|\-|_]*)\.(gif|jpg|jpeg):=$1/dsgw/bin/lang?\