Skip to content

Commit e9d4309

Browse files
committed
Add refresh-keys, switch key-server to keyserver.ubuntu.com
1 parent 878c7d5 commit e9d4309

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

common.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module Common
3030
TAG = 'msys2-gcc-pkgs' # GitHub release tag
3131
MSYS2_ROOT = 'C:/msys64'
3232
PACMAN = 'C:/msys64/usr/bin/pacman.exe'
33+
BASH = 'C:/msys64/usr/bin/bash.exe'
3334

3435
def gh_api_graphql(http, query)
3536
body = {}
@@ -241,6 +242,35 @@ def update_release_notes(old_body, name, time)
241242
}
242243
end
243244

245+
def gpg_conf_key_server(old_uri, new_uri)
246+
fn = "#{MSYS2_ROOT}/etc/pacman.d/gnupg/gpg.conf"
247+
str = File.binread fn
248+
if str.include? old_uri
249+
str.sub! old_uri, new_uri
250+
File.binwrite fn, str
251+
STDOUT.syswrite "\ngpg.conf - changed '#{old_uri}' to '#{new_uri}'"
252+
end
253+
end
254+
255+
def refresh_keys
256+
STDOUT.syswrite "\n#{YEL}#{LINE} Refresh keys#{RST}\n"
257+
gpg_conf_key_server 'pool.sks-keyservers.net', 'keyserver.ubuntu.com'
258+
259+
str = ''
260+
cmd = "#{BASH} -c \"pacman-key --refresh-keys\""
261+
262+
IO.popen(cmd, err: [:child, :out]) { |io| str = io.read }
263+
264+
system 'taskkill /f /fi "MODULES eq msys-2.0.dll"'
265+
266+
if str.match?(/new signatures:|signatures cleaned:/)
267+
STDOUT.syswrite str
268+
true
269+
else
270+
nil
271+
end
272+
end
273+
244274
def pacman_syuu
245275
usr_bin = "#{MSYS2_ROOT}/usr/bin"
246276

@@ -253,6 +283,8 @@ def pacman_syuu
253283
exec_check 'Updating all installed packages (2nd pass)', "#{PACMAN} -Syuu --noconfirm"
254284

255285
system 'taskkill /f /fi "MODULES eq msys-2.0.dll"'
286+
287+
refresh_keys
256288
end
257289

258290
# logs message and runs cmd, checking for error

create_msys2_pkg.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ class << self
2222
LOCAL = 'var/lib/pacman/local'
2323

2424
def update_msys2
25-
pacman_syuu
25+
updated_keys = pacman_syuu
2626

2727
pkgs = 'autoconf-wrapper autogen automake-wrapper bison diffutils libtool m4 make patch re2c texinfo texinfo-tex compression'
2828
exec_check "Install MSYS2 packages#{RST}\n#{YEL}#{pkgs}",
2929
"#{PACMAN} -S --noconfirm --needed --noprogressbar #{pkgs}"
30+
updated_keys
3031
end
3132

3233
def remove_non_msys2
@@ -72,15 +73,17 @@ def clean_database(pre)
7273
def run
7374
current_pkgs = %x[#{PACMAN} -Q].split("\n").reject { |l| l.start_with? 'mingw-w64-' }
7475

75-
update_msys2
76+
updated_keys = update_msys2
7677

7778
updated_pkgs = %x[#{PACMAN} -Q].split("\n").reject { |l| l.start_with? 'mingw-w64-' }
7879

7980
time = Time.now.utc.strftime '%Y-%m-%d %H:%M:%S UTC'
8081

8182
log_array_2_column updated_pkgs, 48, "Installed MSYS2 Packages"
8283

83-
if current_pkgs == updated_pkgs
84+
gpg_files = Dir["#{MSYS2_ROOT}/etc/pacman.d/gnupg/*"].count { |fn| File.file? fn }
85+
86+
if current_pkgs == updated_pkgs && !updated_keys
8487
STDOUT.syswrite "\n** No update to MSYS2 tools needed **\n\n"
8588
exit 0
8689
else

0 commit comments

Comments
 (0)