This repository was archived by the owner on Jan 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpastebin_installer.lua
More file actions
60 lines (48 loc) · 1.43 KB
/
pastebin_installer.lua
File metadata and controls
60 lines (48 loc) · 1.43 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
--[[
_ _ _ ____ ___ ____ _ _ ____ ____
| |\ | [__ | |__| | | |___ |__/
| | \| ___] | | | |___ |___ |___ | \
Github Repository: https://github.com/Commandcracker/YouCube
License: GPL-3.0
]]
-- OpenPastebinInstaller v1.0.0 (based on wget)
local url = "https://raw.githubusercontent.com/Commandcracker/YouCube/main/installer.lua"
if not http then
printError("OpenPastebinInstaller requires the http API")
printError("Set http.enabled to true in ComputerCraft config")
return
end
local function getFilename(sUrl)
sUrl = sUrl:gsub("[#?].*", ""):gsub("/+$", "")
return sUrl:match("/([^/]+)$")
end
local function get(sUrl)
-- Check if the URL is valid
local ok, err = http.checkURL(url)
if not ok then
printError("\"" .. sUrl .. "\" ", err or "Invalid URL.")
return
end
local response, http_err = http.get(sUrl, nil, true)
if not response then
printError("Failed to download \"" .. sUrl .. "\" (" .. http_err .. ")")
return nil
end
term.setTextColour(colors.lime)
print("Runnig " .. getFilename(url))
term.setTextColour(colors.white)
local sResponse = response.readAll()
response.close()
return sResponse or ""
end
local res = get(url)
if not res then return end
local func, err = load(res, getFilename(url), "t", _ENV)
if not func then
printError(err)
return
end
local ok, err = pcall(func)
if not ok then
printError(err)
end