66# Windows runner's hard drive, smaller zip files speed up the installation.
77# Hence, many of the 'doc' related files in the 'share' folder are removed.
88
9+ # OpenSSL - There are comments and code lines that are commented out. The archives
10+ # may need to have one version of OpenSSL fully installed, and if that version
11+ # differs from the current MSYS2 version, the OpenSSL files needed to run (not build)
12+ # the MSYS2 utilities need to remain. They should be from the most recent version
13+ # that MSYS2 uses.
14+ #
15+ # This means there are files that are not associated with an installed package,
16+ # so the code gets more complex, and some code is just needed for the transition.
17+
918require 'fileutils'
1019require_relative 'common'
1120
@@ -19,20 +28,30 @@ class << self
1928 SYNC = 'var/lib/pacman/sync'
2029 LOCAL = 'var/lib/pacman/local'
2130
31+ PKG_NAME = ARGV [ 0 ] . downcase
32+
2233 PKG_DIR , PKG_PRE =
23- case ARGV [ 0 ] . downcase [ / [^-]+/]
24- when 'ucrt64' , 'ucrt64-3.0'
34+ case PKG_NAME [ / \A [^-]+/]
35+ when 'ucrt64'
2536 [ 'ucrt64' , 'mingw-w64-ucrt-x86_64-' ]
26- when 'mingw64' , 'mingw64-3.0'
37+ when 'mingw64'
2738 [ 'mingw64' , 'mingw-w64-x86_64-' ]
28- when 'mingw32' , 'mingw32-3.0'
39+ when 'mingw32'
2940 [ 'mingw32' , 'mingw-w64-i686-' ]
3041 else
3142 STDOUT . syswrite "Invalid package type, must be ucrt64, mingw64, or mingw32\n "
3243 exit 1
3344 end
45+
46+ MSYS2_PKG = "#{ MSYS2_ROOT } /#{ PKG_DIR } "
47+
48+ SSL_3_SAVE_FILES = %w[
49+ bin/libcrypto-3-x64.dll
50+ bin/libssl-3-x64.dll
51+ etc/ssl/openssl.cnf
52+ ]
3453
35- PKG_NAME = ARGV [ 0 ] . downcase
54+ SSL_1_DLLS = %w[ bin/libcrypto-1_1-x64.dll bin/libssl-1_1-x64.dll ]
3655
3756 def add_ri2_key
3857 # appveyor ri2 package signing key
@@ -42,6 +61,26 @@ def add_ri2_key
4261 exec_check "Sign RI2 Key" , "bash.exe -c \" pacman-key --lsign-key #{ key } \" "
4362 end
4463
64+ def openssl_downgrade
65+ pkg_name = "openssl-1.1.1.s-1-any.pkg.tar.zst"
66+ pkg = "https://github.com/ruby/setup-msys2-gcc/releases/download/msys2-packages/#{ PKG_PRE } #{ pkg_name } "
67+ pkg_sig = "#{ pkg } .sig"
68+
69+ # save previous dll files so we can copy back into folder
70+ SSL_3_SAVE_FILES . each { |fn | FileUtils . cp "#{ MSYS2_PKG } /#{ fn } " , "." }
71+
72+ download pkg , "./#{ PKG_PRE } #{ pkg_name } "
73+ download pkg_sig , "./#{ PKG_PRE } #{ pkg_name } .sig"
74+
75+ # install package
76+ exec_check "Install OpenSSL Downgrade" , "pacman.exe -Udd --noconfirm --noprogressbar #{ PKG_PRE } #{ pkg_name } "
77+
78+ # copy previous dlls back into MSYS2 folder
79+ SSL_3_SAVE_FILES . each { |fn | FileUtils . cp_r File . basename ( fn ) , "#{ MSYS2_PKG } /#{ fn } " }
80+ openssl_copy_cert_files
81+ end
82+
83+ # as of Jan-2023, not used, save for future use
4584 def openssl_upgrade
4685 add_ri2_key
4786
@@ -68,20 +107,37 @@ def openssl_upgrade
68107 end
69108 end
70109
110+ # Below files are part of the 'ca-certificates' package, they are not
111+ # included in the openssl package
112+ # This is needed due to MSYS2 OpenSSL 1.1.1 using 'ssl', and the 3.0 version
113+ # using 'etc/ssl'.
114+ def openssl_copy_cert_files
115+ new_dir = "#{ MSYS2_PKG } /ssl"
116+ old_dir = "#{ MSYS2_PKG } /etc/ssl"
117+ unless Dir . exist? "#{ new_dir } /certs"
118+ FileUtils . mkdir_p "#{ new_dir } /certs"
119+ end
120+ %w[ cert.pem certs/ca-bundle.crt certs/ca-bundle.trust.crt ] . each do |fn |
121+ if File . exist? ( "#{ old_dir } /#{ fn } " ) && !File . exist? ( "#{ new_dir } /#{ fn } " )
122+ FileUtils . cp "#{ old_dir } /#{ fn } " , "#{ new_dir } /#{ fn } "
123+ end
124+ end
125+ end
126+
71127 def install_gcc
72-
73128 args = '--noconfirm --noprogressbar --needed'
74129 # zlib required by gcc, gdbm for older Rubies
75130 base_gcc = %w[ make pkgconf libmangle-git tools-git gcc ]
76131 base_ruby = PKG_NAME . end_with? ( '-3.0' ) ?
77- %w[ gdbm gmp libffi libyaml ragel readline ] :
132+ %w[ gdbm gmp libffi libyaml openssl ragel readline ] :
78133 %w[ gdbm gmp libffi libyaml openssl ragel readline ]
79134
80135 pkgs = ( base_gcc + base_ruby ) . unshift ( '' ) . join " #{ PKG_PRE } "
81136
82- # may not be needed, but...
137+ # May not be needed, but...
138+ # Note that OpenSSL may need to be ignored
83139 if PKG_NAME . end_with? ( '-3.0' )
84- pacman_syuu "mingw-w64-ucrt-x86_64-openssl"
140+ pacman_syuu
85141 else
86142 pacman_syuu
87143 end
@@ -91,7 +147,11 @@ def install_gcc
91147 "#{ PACMAN } -S #{ args } #{ pkgs } "
92148
93149 if PKG_NAME . end_with? '-3.0'
94- openssl_upgrade
150+ SSL_1_DLLS . each do |fn |
151+ FileUtils . remove_file ( "#{ MSYS2_PKG } /#{ fn } " ) if File . exist? ( "#{ MSYS2_PKG } /#{ fn } " )
152+ end
153+ else
154+ openssl_downgrade
95155 end
96156 end
97157
@@ -170,7 +230,7 @@ def run
170230 log_array_2_column updated_pkgs . map { |el | el . sub PKG_PRE , '' } , 48 ,
171231 "Installed #{ PKG_PRE [ 0 ..-2 ] } Packages"
172232
173- if current_pkgs == updated_pkgs
233+ if ( current_pkgs == updated_pkgs ) && ! ENV . key? ( 'FORCE_UPDATE' )
174234 STDOUT . syswrite "\n ** No update to #{ PKG_DIR } gcc tools needed **\n \n "
175235 exit 0
176236 else
0 commit comments