Skip to content

Commit f3b9f7e

Browse files
committed
Add upgrade param to install_cef
currently: - prints new hash and version - unpacks new version
1 parent 5961a62 commit f3b9f7e

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

utils/buildactions/install_cef.lua

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,63 @@ 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+
1830
newaction {
1931
trigger = "install_cef",
2032
description = "Downloads and installs CEF",
2133

22-
execute = function()
23-
-- Only execute on Windows
24-
if os.host() ~= "windows" then return end
34+
execute = function(...)
35+
local upgrade = #_ARGS == 1 and _ARGS[1] == "upgrade"
36+
if upgrade then
37+
print("Checking opensource.spotify.com for an update...")
38+
resource, result_str, result_code = http.get("http://opensource.spotify.com/cefbuilds/index.html")
39+
if result_str ~= "OK" or result_code ~= 200 then
40+
errormsg(("Could not get page with status code %s: "):format(response_code), result_str)
41+
return
42+
end
43+
44+
local _, index = resource:find('Windows 32%-bit Builds.-data%-version="')
45+
if not index then
46+
errormsg("Could not find version string index.")
47+
return
48+
end
49+
50+
local version = resource:match("(.-)\">", index+1)
51+
if not version then
52+
errormsg("Could not get version string from index.")
53+
end
54+
55+
if version == CEF_VERSION then
56+
print(("CEF is already up to date (%s)"):format(version))
57+
return
58+
end
59+
60+
io.write(("Does version '%s' look OK to you? (Y/n) "):format(version))
61+
local input = io.read():lower()
62+
if not (input == "y" or input == "yes") then
63+
errormsg("Aborting due to user request.")
64+
return
65+
end
66+
67+
CEF_VERSION = version
68+
CEF_HASH = ""
69+
end
70+
71+
-- Only execute on Windows in normal scenarios
72+
if os.host() ~= "windows" and not upgrade then
73+
return
74+
end
2575

2676
-- Check file hash
2777
local archive_path = CEF_PATH.."temp.tar.bz2"
@@ -33,12 +83,19 @@ newaction {
3383
-- Download CEF
3484
print("Downloading CEF...")
3585
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()
86+
if result_str ~= "OK" or response_code ~= 200 then
87+
errormsg(("Could not download CEF with status code %s: "):format(response_code), result_str)
88+
return
89+
end
90+
91+
if upgrade then
92+
local downloaded_hash = os.sha256_file(archive_path)
93+
print("New CEF hash is:", downloaded_hash)
94+
return
95+
end
96+
97+
-- Seriously abort now if we're not using Windows
98+
if os.host() ~= "windows" then
4299
return
43100
end
44101

0 commit comments

Comments
 (0)