cvs updates from Wed Dec 15 17:45:22 EST 2010
[tridge/bind9.git] / win32utils / updateopenssl.pl
1 #!/usr/bin/perl
2 #
3 # Copyright (C) 2006, 2007, 2009, 2010  Internet Systems Consortium, Inc. ("ISC")
4 #
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
16
17 # $Id: updateopenssl.pl,v 1.13 2010/05/18 06:47:46 tbox Exp $
18
19 # updateopenssl.pl
20 # This script locates the latest version of OpenSSL in the grandparent
21 # directory and updates the build scripts to use that version.
22 #
23 # Path and directory
24 $path = "..\\..\\";
25
26 # List of files that need to be updated with the actual version of the
27 # openssl directory
28 @filelist = ("SetupLibs.bat",
29              "../lib/dns/win32/libdns.mak",
30              "../lib/dns/win32/libdns.dsp");
31
32 # Locate the openssl directory
33 $substr = getdirectory();
34 if ($substr eq 0) {
35      print "No directory found\n";
36 }
37 else {
38      print "Found $substr directory\n";
39 }
40 #Update the list of files
41 if ($substr ne 0) {
42    $ind = 0;
43    foreach $file (@filelist) {
44         print "Updating file $file\n";
45         updatefile($file, $substr);
46         $ind++;
47    }
48 }
49
50 # Function to find the
51 sub getdirectory {
52     my(@namelist);
53     my($file, $name);
54     my($cnt);
55     opendir(DIR,$path) || die "No Directory: $!";
56     @namelist = grep (/^openssl-[0-9]+\.[0-9]+\.[0-9]+[a-z]{0,1}$/i, readdir(DIR));
57     closedir(DIR);
58
59     # Make sure we have something
60     if (scalar(@namelist) == 0) {
61         return (0);
62     }
63     # Now see if we have a directory or just a file.
64     # Make sure we are case insensitive
65     foreach $file (sort {uc($a) cmp uc($b)} @namelist) {
66         if (-d $path.$file) {
67            $name = $file;
68         }
69     }
70
71     # If we have one use it otherwise report the error
72     # Note that we are only interested in the last one
73     # since the sort should have taken care of getting
74     # the latest
75     if (defined($name)) {
76         return ($name);
77     }
78     else {
79         return (0);
80     }
81 }
82
83 # function to replace the openssl directory name with the latest one
84 sub updatefile {
85         my($filename, $substr, $line);
86         my(@Lines);
87
88         $filename = $_[0];
89         $substr   = $_[1];
90
91         open (RFILE, $filename) || die "Can't open file $filename: $!";
92         @Lines = <RFILE>;
93         close (RFILE);
94
95         # Replace the string
96         foreach $line (@Lines) {
97                 $line =~ s/openssl-[0-9]+\.[0-9]+\.[0-9]+[a-z]{0,1}/$substr/gi;
98         }
99         #update the file
100         open (RFILE, ">$filename") || die "Can't open file $filename: $!";
101         foreach $line (@Lines) {
102                print RFILE $line;
103         }
104         close(RFILE);
105 }
106