Repository navigation
Expand file tree
/
Copy pathdotnet.lua
More file actions
121 lines (107 loc) · 3.36 KB
/
Copy pathdotnet.lua
File metadata and controls
121 lines (107 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
-- dotnet: live HTML crawl of the .NET download pages and their per-release detail pages
-- (ported from vcollector official/dotnet.go).
local C = dofile(__vmr_plugin_dir .. "/_vmr_common.lua")
plugin_name = "dotnet"
sdk_name = "dotnet"
plugin_version = "0.1"
homepage = "https://dotnet.microsoft.com/"
ic = C.installer({
flag_files = {
windows = { "shared", "sdk", "host" },
darwin = { "shared", "sdk", "host" },
linux = { "shared", "sdk", "host" },
},
additional_envs = {
{ name = "DOTNET_ROOT", value = {}, version = "" },
},
})
local DOWNLOAD_URL = "https://dotnet.microsoft.com/download/dotnet"
local HOST = "https://dotnet.microsoft.com"
local EXCLUDE_LIST = { "alpine", "installer", "winget", "arm32", "install", "scripts" }
local function filter_url(vurl)
if vurl == "" then
return false
end
for _, item in ipairs(EXCLUDE_LIST) do
if vmrContains(vurl, item) then
return false
end
end
return true
end
local function parse_arch(vurl)
if vmrContains(vurl, "arm64") then
return "arm64"
end
if vmrContains(vurl, "-x64") then
return "amd64"
end
return ""
end
local function parse_os(vurl)
if vmrContains(vurl, "linux") then
return "linux"
end
if vmrContains(vurl, "-win-") then
return "windows"
end
if vmrContains(vurl, "osx") then
return "darwin"
end
return ""
end
local function fetch_version(vl, vurl, vstr)
local resp = vmrGetResponse(vurl, 180, {})
local link = vmrAttr(vmrInitSelection(resp, "a#directLink"), "href")
local sha = vmrAttr(vmrInitSelection(resp, "input#checksum"), "value")
local arch = parse_arch(link)
local os_name = parse_os(link)
if arch == "" or os_name == "" then
return
end
vmrAddItem(vl, vstr, {
url = link,
arch = arch,
os = os_name,
sum = sha,
sum_type = (sha ~= "") and "sha512" or "",
size = 0,
installer = vmrInstallerUnarchiver,
lts = "",
extra = "",
})
end
function crawl()
local vl = vmrNewVersionList()
local resp = vmrGetResponse(DOWNLOAD_URL, 180, {})
local version_urls = {}
vmrEach(vmrInitSelection(resp, "div#supported-versions-table table a"), function(_, anchor)
local vurl = vmrAttr(anchor, "href")
if vurl ~= "" then
if not vmrContains(vurl, HOST) then
vurl = vmrUrlJoin(HOST, vurl)
end
table.insert(version_urls, vurl)
end
end)
for _, vurl in ipairs(version_urls) do
local page = vmrGetResponse(vurl, 180, {})
vmrEach(vmrInitSelection(page, "div.download-panel div table"), function(_, table_sel)
local info = vmrAttr(vmrFind(table_sel, "caption"), "id")
local parts, n = vmrSplit(info, "-sdk-")
if n >= 2 then
local vstr = parts[n]
vmrEach(vmrFind(table_sel, "a"), function(_, anchor)
local link = vmrAttr(anchor, "href")
if filter_url(link) then
if not vmrContains(link, HOST) then
link = vmrUrlJoin(HOST, link)
end
fetch_version(vl, link, vstr)
end
end)
end
end)
end
return vl
end