|
1 | 1 | -- hooks/pre_install.lua |
2 | 2 | function PLUGIN:PreInstall(ctx) |
3 | | - local version = ctx.version |
4 | | - local http = require("http") |
| 3 | + local version = ctx.version |
| 4 | + local http = require("http") |
5 | 5 |
|
6 | | - -- Determine platform using RUNTIME object |
7 | | - local arch_token |
8 | | - if RUNTIME.archType == "amd64" then |
9 | | - arch_token = "amd64" |
10 | | - elseif RUNTIME.archType == "arm64" then |
11 | | - arch_token = "aarch64" |
12 | | - else |
13 | | - error("Unsupported architecture: " .. RUNTIME.archType) |
14 | | - end |
15 | | - |
16 | | - local os_token |
17 | | - if RUNTIME.osType == "Windows" then |
18 | | - os_token = "windows" |
19 | | - elseif RUNTIME.osType == "Darwin" then |
20 | | - os_token = "macos" |
21 | | - elseif RUNTIME.osType == "Linux" then |
22 | | - os_token = "linux" |
23 | | - else |
24 | | - error("Unsupported operating system: " .. RUNTIME.osType) |
25 | | - end |
26 | | - |
27 | | - -- Build filename based on platform |
28 | | - local filename |
29 | | - if os_token == "linux" then |
30 | | - -- Use static build for better compatibility |
31 | | - if arch_token == "amd64" then |
32 | | - filename = "eca-native-static-linux-amd64.zip" |
| 6 | + -- Normalize architecture |
| 7 | + local arch = RUNTIME.archType:lower() |
| 8 | + local arch_token |
| 9 | + if arch == "amd64" or arch == "x86_64" then |
| 10 | + arch_token = "amd64" |
| 11 | + elseif arch == "arm64" or arch == "aarch64" then |
| 12 | + arch_token = "aarch64" |
33 | 13 | else |
34 | | - filename = "eca-native-linux-" .. arch_token .. ".zip" |
| 14 | + error("Unsupported architecture: " .. RUNTIME.archType) |
35 | 15 | end |
36 | | - else |
37 | | - filename = "eca-native-" .. os_token .. "-" .. arch_token .. ".zip" |
38 | | - end |
39 | 16 |
|
40 | | - -- Build download URL |
41 | | - local url = "https://github.com/editor-code-assistant/eca/releases/download/v" .. version .. "/" .. filename |
| 17 | + -- Normalize OS |
| 18 | + local os_l = RUNTIME.osType:lower() |
| 19 | + local os_token |
| 20 | + if os_l:find("windows") then |
| 21 | + os_token = "windows" |
| 22 | + elseif os_l:find("darwin") then |
| 23 | + os_token = "macos" |
| 24 | + elseif os_l:find("linux") then |
| 25 | + os_token = "linux" |
| 26 | + else |
| 27 | + error("Unsupported OS: " .. RUNTIME.osType) |
| 28 | + end |
42 | 29 |
|
43 | | - -- Fetch SHA256 checksum |
44 | | - local sha256 = nil |
45 | | - local checksum_url = url .. ".sha256" |
46 | | - local checksum_resp, checksum_err = http.get({ url = checksum_url }) |
| 30 | + -- Construct filename (dynamic builds) |
| 31 | + local filename = string.format("eca-native-%s-%s.zip", os_token, arch_token) |
| 32 | + local url = string.format("https://github.com/editor-code-assistant/eca/releases/download/%s/%s", version, filename) |
47 | 33 |
|
48 | | - if checksum_err == nil and checksum_resp.status_code == 200 then |
49 | | - -- Extract SHA256 from checksum file |
50 | | - sha256 = checksum_resp.body:match("^(%w+)") |
51 | | - end |
| 34 | + -- Fetch checksum |
| 35 | + local sha256 |
| 36 | + do |
| 37 | + local resp, err = http.get({url = url .. ".sha256"}) |
| 38 | + if not err and resp.status_code == 200 then |
| 39 | + sha256 = resp.body:match("^(%w+)") |
| 40 | + end |
| 41 | + end |
52 | 42 |
|
53 | | - return { |
54 | | - version = version, |
55 | | - url = url, |
56 | | - sha256 = sha256, |
57 | | - note = "Installing ECA " .. version .. " (" .. os_token .. "-" .. arch_token .. ")" |
58 | | - } |
| 43 | + return {version = version, url = url, sha256 = sha256, note = "Installing ECA " .. version} |
59 | 44 | end |
0 commit comments