33require 'open-uri'
44require 'rubygems/package'
55require 'zlib'
6+ require 'zip'
67require 'fileutils'
7-
8+ require 'down'
89
910# +----------------------------------------------------------------------+
1011# | Licensed Materials - Property of IBM |
@@ -42,6 +43,7 @@ def suppress_warnings
4243end
4344
4445DOWNLOADLINK = ''
46+ ZIP = false
4547
4648if ( RUBY_PLATFORM =~ /aix/i )
4749 #AIX
@@ -94,6 +96,15 @@ def suppress_warnings
9496 else
9597 puts "Mac OS 32 bit not supported. Please use an x64 architecture."
9698 end
99+ elsif ( RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/ )
100+ ZIP = true
101+ if ( is64Bit )
102+ puts "Detected platform - windows 64"
103+ DOWNLOADLINK = "https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/ntx64_odbc_cli.zip"
104+ else
105+ puts "Detected platform - windows 32"
106+ DOWNLOADLINK = "https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/nt32_odbc_cli.zip"
107+ end
97108end
98109
99110def downloadCLIPackage ( destination , link = nil )
@@ -103,22 +114,27 @@ def downloadCLIPackage(destination, link = nil)
103114 downloadLink = link
104115 end
105116
106- uri = URI . parse ( downloadLink )
107- filename = "#{ destination } /clidriver.tar.gz"
108-
109- headers = {
110- 'Accept-Encoding' => 'identity' ,
111- }
117+ if ZIP
118+ filename = "#{ destination } /clidriver.zip"
119+ else
120+ filename = "#{ destination } /clidriver.tar.gz"
121+ end
122+
123+ Down . download ( downloadLink , destination : filename )
112124
113- request = Net ::HTTP ::Get . new ( uri . request_uri , headers )
114- http = Net ::HTTP . new ( uri . host , uri . port )
115- response = http . request ( request )
125+ filename
126+ end
116127
117- f = open ( filename , 'wb' )
118- f . write ( response . body )
119- f . close ( )
128+ def extract_zip ( file , destination )
129+ FileUtils . mkdir_p ( destination )
120130
121- filename
131+ Zip ::File . open ( file ) do |zip_file |
132+ zip_file . each do |f |
133+ fpath = File . join ( destination , f . name )
134+ FileUtils . mkdir_p ( File . dirname ( fpath ) )
135+ zip_file . extract ( f , fpath ) unless File . exist? ( fpath )
136+ end
137+ end
122138end
123139
124140def untarCLIPackage ( archive , destination )
@@ -157,8 +173,12 @@ def untarCLIPackage(archive,destination)
157173 puts "Environment variable IBM_DB_HOME is not set. Downloading and setting up the DB2 client driver\n "
158174 destination = "#{ File . expand_path ( File . dirname ( File . dirname ( __FILE__ ) ) ) } /../lib"
159175
160- archive = downloadCLIPackage ( destination )
161- untarCLIPackage ( archive , destination )
176+ archive = downloadCLIPackage ( destination )
177+ if ( ZIP )
178+ extract_zip ( archive , destination )
179+ else
180+ untarCLIPackage ( archive , destination )
181+ end
162182
163183 IBM_DB_HOME = "#{ destination } /clidriver"
164184
@@ -262,7 +282,7 @@ def libpathflag(libpath)
262282 end
263283 end
264284 else
265- if ( RUBY_VERSION =~ /2./ || RUBY_VERSION =~ /3./ )
285+ if ( RUBY_VERSION =~ /2./ || RUBY_VERSION =~ /3./ )
266286 ldflags = case RbConfig ::CONFIG [ "arch" ]
267287 when /solaris2/
268288 libpath [ 0 ..-2 ] . map { |path | " -R#{ path } " } . join
0 commit comments