|
| 1 | +-- hooks/pre_install.lua |
| 2 | +function PLUGIN:PreInstall(ctx) |
| 3 | + local version = ctx.version |
| 4 | + local http = require("http") |
| 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" |
| 33 | + else |
| 34 | + filename = "eca-native-linux-" .. arch_token .. ".zip" |
| 35 | + end |
| 36 | + else |
| 37 | + filename = "eca-native-" .. os_token .. "-" .. arch_token .. ".zip" |
| 38 | + end |
| 39 | + |
| 40 | + -- Build download URL |
| 41 | + local url = "https://github.com/editor-code-assistant/eca/releases/download/v" .. version .. "/" .. filename |
| 42 | + |
| 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 }) |
| 47 | + |
| 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 |
| 52 | + |
| 53 | + return { |
| 54 | + version = version, |
| 55 | + url = url, |
| 56 | + sha256 = sha256, |
| 57 | + note = "Installing ECA " .. version .. " (" .. os_token .. "-" .. arch_token .. ")" |
| 58 | + } |
| 59 | +end |
0 commit comments