Skip to content

Commit ed80d57

Browse files
authored
Merge pull request #1332 from qaisjp/feature/cef-upgrade-script
Add cef upgrade script
2 parents f99bd3e + e285482 commit ed80d57

File tree

3 files changed

+117
-15
lines changed

3 files changed

+117
-15
lines changed

utils/buildactions/install_cef.lua

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,86 @@ local CEF_URL_SUFFIX = "_windows32_minimal.tar.bz2"
99

1010
-- Change here to update CEF version
1111
local CEF_VERSION = "80.0.4+g74f7b0c+chromium-80.0.3987.122"
12-
local CEF_HASH = "8FD8E24AF196F00FEAAA1553496BAE99D8196BA023D0DD0FE44EFEEE93B04DFC"
12+
local CEF_HASH = "8fd8e24af196f00feaaa1553496bae99d8196ba023d0dd0fe44efeee93b04dfc"
1313

1414
function make_cef_download_url()
1515
return CEF_URL_PREFIX..http.escapeUrlParam(CEF_VERSION)..CEF_URL_SUFFIX
1616
end
1717

18+
function errormsg(title, message)
19+
term.pushColor(term.red)
20+
io.write(title)
21+
if message then
22+
term.setTextColor(term.purple)
23+
print(" " .. message)
24+
else
25+
print()
26+
end
27+
term.popColor()
28+
end
29+
30+
function update_install_cef(version, hash)
31+
local filename = "utils/buildactions/install_cef.lua"
32+
local f = io.open(filename)
33+
local text = f:read("*all")
34+
f:close()
35+
36+
-- Replace version and hash lines
37+
local version_line = 'local CEF_VERSION = "' .. version .. '"'
38+
local hash_line = 'local CEF_HASH = "' .. hash .. '"'
39+
text = text:gsub('local CEF_VERSION = ".-"', version_line, 1)
40+
text = text:gsub('local CEF_HASH = ".-"', hash_line, 1)
41+
42+
local f = io.open(filename, "w")
43+
f:write(text)
44+
f:close()
45+
end
46+
1847
newaction {
1948
trigger = "install_cef",
2049
description = "Downloads and installs CEF",
2150

22-
execute = function()
23-
-- Only execute on Windows
24-
if os.host() ~= "windows" then return end
51+
execute = function(...)
52+
local upgrade = #_ARGS == 1 and _ARGS[1] == "upgrade"
53+
if upgrade then
54+
print("Checking opensource.spotify.com for an update...")
55+
resource, result_str, result_code = http.get("http://opensource.spotify.com/cefbuilds/index.html")
56+
if result_str ~= "OK" or result_code ~= 200 then
57+
errormsg(("Could not get page with status code %s: "):format(response_code), result_str)
58+
return
59+
end
60+
61+
local _, index = resource:find('Windows 32%-bit Builds.-data%-version="')
62+
if not index then
63+
errormsg("Could not find version string index.")
64+
return
65+
end
66+
67+
local version = resource:match("(.-)\">", index+1)
68+
if not version then
69+
errormsg("Could not get version string from index.")
70+
end
71+
72+
if version == CEF_VERSION then
73+
print(("CEF is already up to date (%s)"):format(version))
74+
return
75+
end
76+
77+
io.write(("Does version '%s' look OK to you? (Y/n) "):format(version))
78+
local input = io.read():lower()
79+
if not (input == "y" or input == "yes") then
80+
errormsg("Aborting due to user request.")
81+
return
82+
end
83+
84+
CEF_VERSION = version
85+
CEF_HASH = ""
86+
end
87+
88+
-- Only execute on Windows in normal scenarios
89+
if os.host() ~= "windows" and not upgrade then
90+
return
91+
end
2592

2693
-- Check file hash
2794
local archive_path = CEF_PATH.."temp.tar.bz2"
@@ -33,12 +100,33 @@ newaction {
33100
-- Download CEF
34101
print("Downloading CEF...")
35102
local result_str, response_code = http.download(make_cef_download_url(), archive_path)
36-
if result_str ~= "OK" and response_code ~= 200 then
37-
term.pushColor(term.red)
38-
io.write(("Could not download CEF with status code %d: "):format(response_code))
39-
term.setTextColor(term.purple)
40-
print(result_str)
41-
term.popColor()
103+
if result_str ~= "OK" or response_code ~= 200 then
104+
errormsg(("Could not download CEF with status code %s: "):format(response_code), result_str)
105+
return
106+
end
107+
108+
local downloaded_hash = os.sha256_file(archive_path)
109+
if upgrade then
110+
print("New CEF hash is:", downloaded_hash)
111+
CEF_HASH = downloaded_hash
112+
113+
io.write(("Update `install_cef.lua` file? (Y/n) "):format(version))
114+
local input = io.read():lower()
115+
if (input == "y" or input == "yes") then
116+
update_install_cef(CEF_VERSION, downloaded_hash)
117+
end
118+
end
119+
120+
if downloaded_hash == CEF_HASH then
121+
print("CEF consistency checks succeeded")
122+
else
123+
errormsg("CEF consistency checks failed.", ("Expected %s, got %s"):format(CEF_HASH, downloaded_hash))
124+
os.exit(1)
125+
return
126+
end
127+
128+
-- Seriously abort now if we're not using Windows
129+
if os.host() ~= "windows" then
42130
return
43131
end
44132

utils/buildactions/install_discord.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ local DISCORD_VENDOR = "vendor/discordgsdk"
99

1010
-- Change these to update the version
1111
local DISCORD_TAG = "v2020-11-02_21-48-56"
12-
local DISCORD_HASH = "4CCEEED0D8B41BDC67C44A6DDCCCF42288AF933E1F7284C591327178C391AA39"
12+
local DISCORD_HASH = "4cceeed0d8b41bdc67c44a6ddcccf42288af933e1f7284c591327178c391aa39"
1313

1414
newaction {
1515
trigger = "install_discord",

utils/buildactions/utils.lua

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,26 @@ function os.expanddir_wildcard(from, to)
8484
end
8585

8686
function os.sha256_file(path)
87-
if os.host() == "windows" then
88-
local s, errc = os.outputof(string.format("powershell -Command (Get-FileHash \"%s\" -Algorithm SHA256).Hash", path))
89-
return (errc == 0) and s or ""
87+
local windows = os.host() == "windows"
88+
local s, errc
89+
if windows then
90+
s, errc = os.outputof(string.format("CertUtil -hashfile \"%s\" SHA256", path))
9091
else
91-
return os.outputof(string.format("sha256sum \"%s\" | awk '{ print $1 }'", path))
92+
s, errc = os.outputof(string.format("sha256sum \"%s\" | awk '{ print $1 }'", path))
93+
end
94+
95+
-- Check for error
96+
if errc ~= 0 then
97+
print("Error os.sha256_file: ", errc)
98+
return ""
9299
end
100+
101+
-- Clean windows output
102+
if windows then
103+
s = (s:match("\n(.*)\n(.*)") or ""):gsub(" ", "")
104+
end
105+
106+
return s:lower()
93107
end
94108

95109
function os.extract_archive(archive_path, target_path, override)

0 commit comments

Comments
 (0)