1#!/usr/bin/perl 2# 3# Copyright (C) 2006, 2007, 2009, 2010, 2012 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 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 "../bin/named/win32/named.mak", 32 "../bin/named/win32/named.dsp"); 33 34# Locate the openssl directory 35$substr = getdirectory(); 36if ($substr eq 0) { 37 print "No directory found\n"; 38} 39else { 40 print "Found $substr directory\n"; 41} 42#Update the list of files 43if ($substr ne 0) { 44 $ind = 0; 45 foreach $file (@filelist) { 46 print "Updating file $file\n"; 47 updatefile($file, $substr); 48 $ind++; 49 } 50} 51 52# Function to find the 53sub getdirectory { 54 my(@namelist); 55 my($file, $name); 56 my($cnt); 57 opendir(DIR,$path) || die "No Directory: $!"; 58 @namelist = grep (/^openssl-[0-9]+\.[0-9]+\.[0-9]+[a-z]{0,1}$/i, readdir(DIR)); 59 closedir(DIR); 60 61 # Make sure we have something 62 if (scalar(@namelist) == 0) { 63 return (0); 64 } 65 # Now see if we have a directory or just a file. 66 # Make sure we are case insensitive 67 foreach $file (sort {uc($a) cmp uc($b)} @namelist) { 68 if (-d $path.$file) { 69 $name = $file; 70 } 71 } 72 73 # If we have one use it otherwise report the error 74 # Note that we are only interested in the last one 75 # since the sort should have taken care of getting 76 # the latest 77 if (defined($name)) { 78 return ($name); 79 } 80 else { 81 return (0); 82 } 83} 84 85# function to replace the openssl directory name with the latest one 86sub updatefile { 87 my($filename, $substr, $line); 88 my(@Lines); 89 90 $filename = $_[0]; 91 $substr = $_[1]; 92 93 open (RFILE, $filename) || die "Can't open file $filename: $!"; 94 @Lines = <RFILE>; 95 close (RFILE); 96 97 # Replace the string 98 foreach $line (@Lines) { 99 $line =~ s/openssl-[0-9]+\.[0-9]+\.[0-9]+[a-z]{0,1}/$substr/gi; 100 } 101 #update the file 102 open (RFILE, ">$filename") || die "Can't open file $filename: $!"; 103 foreach $line (@Lines) { 104 print RFILE $line; 105 } 106 close(RFILE); 107} 108 109