From 6850d43cc86d9e9112406167a3f471592681c5fc Mon Sep 17 00:00:00 2001 From: Sunrise Date: Sun, 9 Jun 2024 02:54:18 +0800 Subject: [PATCH] Add sha256 checksum for Windows --- README.md | 4 ++-- hooks/pre_install.lua | 6 ++--- lib/util.lua | 52 ++++++++++++++++++++++++++----------------- metadata.lua | 2 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index e95adaa..fb08f92 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ export GITHUB_URL=https://mirror.ghproxy.com/https://github.com/ ## FAQ -- **Why is there a lack of updated versions?**
+- **Why is there a lack of updated versions?**
To minimize the working requirements, vfox-ruby currently uses precompiled packages from conda-forge on Linux and macOS. You could open an issue in the [ruby-feedstock](https://github.com/conda-forge/ruby-feedstock/issues) repository to remind the maintainers to provide the latest build. Once the latest version is available, the plugin will be updated soon. -- **Are there any dependencies required to use this plugin?**
+- **Are there any dependencies required to use this plugin?**
On Windows, vfox-ruby uses standalone 7-ZIP archives provided by [RubyInstaller](https://github.com/oneclick/rubyinstaller2/wiki/faq). On Linux and macOS, installing Ruby requires no dependencies other than the built-in commands. Installing TruffleRuby requires `bash`, `make`, `gcc`, `g++` and `zlib-dev`. For more details, refer to the [dependencies](https://github.com/oracle/truffleruby/blob/master/README.md#Dependencies) section. \ No newline at end of file diff --git a/hooks/pre_install.lua b/hooks/pre_install.lua index b3662e1..ce754d8 100644 --- a/hooks/pre_install.lua +++ b/hooks/pre_install.lua @@ -1,10 +1,10 @@ require("util") function PLUGIN:PreInstall(ctx) - local file, version = getDownloadInfo(ctx.version) - + local file, version, sha256 = getDownloadInfo(ctx.version) return { url = file, - version = version + version = version, + sha256 = sha256 } end \ No newline at end of file diff --git a/lib/util.lua b/lib/util.lua index 77e72b9..356e97e 100644 --- a/lib/util.lua +++ b/lib/util.lua @@ -73,7 +73,7 @@ function fetchForWindows() error("Failed to get information: " .. err .. "\nstatus_code => " .. resp.status_code) end - for version in resp.body:gmatch('7z">Ruby (%d.%d.%d+)-1 %(x64%)') do + for version in resp.body:gmatch('7z">Ruby (%d.%d.%d+)%-1 %(x64%)') do table.insert(versions, version) end sortVersions(versions) @@ -140,18 +140,28 @@ end -- pre_install.lua function getDownloadInfo(version) local file + local sha256 if version == "latest" then version = getLatestVersion() end - file = generateURL(version, RUNTIME.osType, RUNTIME.archType) + file, sha256 = generateURL(version, RUNTIME.osType, RUNTIME.archType) - return file, version + return file, version, sha256 end function getLatestVersion() local version if RUNTIME.osType == "windows" then - version = getLatestVersionFromRubyInstaller() + local resp, err = http.get({ + url = "https://rubyinstaller.org/downloads/", + }) + if err ~= nil then + error("Failed to request: " .. err) + end + if resp.status_code ~= 200 then + error("Failed to get latest version: " .. err .. "\nstatus_code => " .. resp.status_code) + end + version = resp.body:match("Ruby (%d.%d.%d+)%-1 %(x64%)") else version = unixRubyVersions[1] end @@ -159,29 +169,16 @@ function getLatestVersion() return version end -function getLatestVersionFromRubyInstaller() - local resp, err = http.get({ - url = "https://rubyinstaller.org/downloads/", - }) - if err ~= nil then - error("Failed to request: " .. err) - end - if resp.status_code ~= 200 then - error("Failed to get latest version: " .. err .. "\nstatus_code => " .. resp.status_code) - end - local version = resp.body:match("Ruby (%d.%d.%d+)-1 %(x64%)") - - return version -end - function generateURL(version, osType, archType) local file + local sha256 local githubURL = os.getenv("GITHUB_URL") or "https://github.com/" if osType == "windows" then local bit = archType == "amd64" and "64" or "86" file = githubURL:gsub("/$", "") .. "/oneclick/rubyinstaller2/releases/download/RubyInstaller-%s-1/rubyinstaller-%s-1-x%s.7z" file = file:format(version, version, bit) + sha256 = getSha256ForWindows(version, bit) elseif osType ~= "darwin" and osType ~= "linux" then print("Unsupported OS: " .. osType) os.exit(1) @@ -192,7 +189,22 @@ function generateURL(version, osType, archType) file = generateTruffleRuby(version, osType, archType) end - return file + return file, sha256 +end + +function getSha256ForWindows(version, bit) + local resp, err = http.get({ + url = "https://rubyinstaller.org/downloads/archives/", + }) + if err ~= nil then + error("Failed to request: " .. err) + end + if resp.status_code ~= 200 then + error("Failed to get sha256: " .. err .. "\nstatus_code => " .. resp.status_code) + end + local sha256 = resp.body:match("rubyinstaller%-" .. version .. "%-1%-x" .. bit .. '.7z[%s%S]-value="([0-9a-z]+)') + + return sha256 end function hasValue(table, value) diff --git a/metadata.lua b/metadata.lua index 6e86673..c8eec9a 100644 --- a/metadata.lua +++ b/metadata.lua @@ -5,7 +5,7 @@ PLUGIN = {} --- Plugin name PLUGIN.name = "ruby" --- Plugin version -PLUGIN.version = "0.3.2" +PLUGIN.version = "0.3.3" --- Plugin homepage PLUGIN.homepage = "https://github.com/yanecc/vfox-ruby" --- Plugin license, please choose a correct license according to your needs.