-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.lua
91 lines (78 loc) · 2.67 KB
/
installer.lua
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
-- AO Package Manager for easy installation of packages in ao processes
-- This blueprint fetches the latest APM client from the APM registry and installs it
-------------------------------------------------------------------------
-- ___ .______ .___ ___. __ __ __ ___
-- / \ | _ \ | \/ | | | | | | | / \
-- / ^ \ | |_) | | \ / | | | | | | | / ^ \
-- / /_\ \ | ___/ | |\/| | | | | | | | / /_\ \
-- / _____ \ | | | | | | __| `----.| `--' | / _____ \
-- /__/ \__\ | _| |__| |__| (__)_______| \______/ /__/ \__\
--
---------------------------------------------------------------------------
-- APM Registry source code: https://github.com/betteridea-dev/ao-package-manager
-- CLI tool for managing packages: https://www.npmjs.com/package/apm-tool
-- Web UI for browsing & publishing packages: https://apm.betteridea.dev
-- Built with ❤️ by BetterIDEa
local apm_id = "DKF8oXtPvh3q8s0fJFIeHFyHNM6oKrwMCUrPxEMroak"
function Hexencode(str)
return (str:gsub(".", function(char) return string.format("%02x", char:byte()) end))
end
function Hexdecode(hex)
return (hex:gsub("%x%x", function(digits) return string.char(tonumber(digits, 16)) end))
end
-- common error handler
function HandleRun(func, msg)
local ok, err = pcall(func, msg)
if not ok then
local clean_err = err:match(":%d+: (.+)") or err
print(msg.Action .. " - " .. err)
-- if not msg.Target == ao.id then
ao.send({
Target = msg.From,
Data = clean_err,
Result = "error"
})
-- end
end
end
local function InstallResponseHandler(msg)
local from = msg.From
if not from == apm_id then
print("Attempt to update from illegal source")
return
end
if not msg.Result == "success" then
print("Update failed: " .. msg.Data)
return
end
local source = msg.Data
local version = msg.Version
if source then
source = Hexdecode(source)
end
local func, err = load(string.format([[
local function _load()
%s
end
-- apm = _load()
_load()
]], source))
if not func then
error("Error compiling load function: " .. err)
end
func()
apm._version = version
-- print("✅ Installed APM v:" .. version)
end
Handlers.once(
"APM.UpdateResponse",
Handlers.utils.hasMatchingTag("Action", "APM.UpdateResponse"),
function(msg)
HandleRun(InstallResponseHandler, msg)
end
)
Send({
Target = apm_id,
Action = "APM.Update"
})
print("📦 Loading APM...")