-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller-craftos.lua
More file actions
141 lines (118 loc) · 4 KB
/
installer-craftos.lua
File metadata and controls
141 lines (118 loc) · 4 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
--[[
installer-craftos - ComputerCraft Package Manager installer for CraftOS
Copyright (C) 2026 Alexandre Leconte <aleconte@dwightstudio.fr>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses>.
--]]
local CCPM_BASE_URL = "https://raw.githubusercontent.com/Deleranax/ccpm/refs/heads/"
local CCPM_REPO_URL = CCPM_BASE_URL .. "dist/"
local PACKAGES_URL = CCPM_BASE_URL .. "main/packages/"
local PACKAGES_OVERRIDE = {
["ccpm.driver.http"] = "ccpm-driver-http",
["ccpm.driver.https"] = "ccpm-driver-http",
["ccpm.repository"] = "libccpm",
["ccpm.database"] = "libccpm",
["ccpm.eventutils"] = "libccpm",
["ccpm.transaction"] = "libccpm",
["ccpm.package"] = "libccpm",
["ccpm.schema"] = "libccpm",
["commons.table"] = "commons-table",
["commons.textutils"] = "commons-textutils"
}
--- Get the download URL for a module.
--- @param name string The name of the module.
--- @return string The download URL for the module.
local function get_url(name)
name = name:gsub("%/", ".")
name = name:gsub("^lib%.", "")
local parts = {}
for value in name:gmatch("([^.]+)") do
table.insert(parts, value)
end
local package = parts[1]
local path = table.concat(parts, ".")
if PACKAGES_OVERRIDE[path] then
package = PACKAGES_OVERRIDE[path]
end
return PACKAGES_URL .. package .. "/source/lib/" .. table.concat(parts, "/") .. ".lua"
end
--- Load a module from the internet.
--- @param name string The name of the module.
--- @return function|nil The loaded module or nil if the module could not be loaded.
--- @return string|nil The error message if the module could not be loaded.
local function online_require(name)
local url = get_url(name)
local response = http.get(url)
if response then
local code = response.readAll()
response.close()
local chunk = load(code, "=" .. name, "t", _ENV)
if chunk then
return chunk, nil
end
end
return nil, "no file at '" .. url .. "'"
end
-- Add online_require to package loaders
table.insert(package.loaders, online_require)
function monitor()
while true do
local event = { os.pullEvent() }
if event[1]:sub(1, 4) == "ccpm" then
print(textutils.serializeJSON(event))
end
end
end
print("Loading live CCPM dependencies")
local repo = require("ccpm.repository")
local trans = require("ccpm.transaction")
local eventutils = require("ccpm.eventutils")
parallel.waitForAny(
function()
print("Adding CCPM repository")
local err = repo.add(CCPM_REPO_URL)
if err then
printError(err)
return
end
print("Updating index and manifests")
err = repo.update()
if err then
printError(err)
return
end
print("Installing CCPM")
err = trans.begin()
if err then
return
end
err = trans.install("ccpm-craftos")
if err then
return
end
err = trans.resolve_dependencies()
if err then
return
end
err = trans.commit()
if err then
return
end
sleep(1)
print("CCPM installed successfully")
sleep(1)
term.setTextColor(colors.yellow)
print("Press any key to reboot")
os.pullEvent("key")
os.reboot()
end,
eventutils.process_transaction_events
)