-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstaller.lua
57 lines (47 loc) · 1.71 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
local NEED_DOWNLOAD = {
["config"] = "https://ocae.smileyik.eu.org/oc/config.lua",
["cpu"] = "https://ocae.smileyik.eu.org/oc/cpu.lua",
["http-method"] = "https://ocae.smileyik.eu.org/oc/http-method.lua",
["json"] = "https://ocae.smileyik.eu.org/oc/json.lua",
["main"] = "https://ocae.smileyik.eu.org/oc/main.lua"
}
local function checkInternetCard()
-- check internet card
local component = require("component")
if component == nil or component.internet == nil then
return
end
end
if not pcall(checkInternetCard) then
print("you need an internet card to continue!")
return
end
local pwd = os.getenv().PWD
local targetDirectory = "oc-ae"
local args = { ... }
for i in pairs(args) do
if args[i] == "--target-directory" or args[i] == "-td" then
i = i + 1
if args[i] ~= nil and type(args[i]) == "string" then
targetDirectory = args[i]
end
end
end
if string.find(targetDirectory, "/") ~= 1 then
targetDirectory = pwd .. "/" .. targetDirectory
end
print("The program will install to " .. targetDirectory)
local createdDirs = {}
for filePath, url in pairs(NEED_DOWNLOAD) do
local targetFile = targetDirectory .. "/" .. filePath .. ".lua"
local i = string.len(targetFile) - string.find(string.reverse(targetFile), "/")
local parentDir = string.sub(targetFile, 1, i)
if nil == createdDirs[parentDir] then
os.execute("mkdir " .. parentDir)
createdDirs[parentDir] = true
end
os.execute("wget " .. url .. " " .. targetFile)
end
print("create a quick link to /home directory")
os.execute("echo \"os.execute(\\\"cd '" .. targetDirectory .. "' && ./main.lua\\\")\" > /home/oc-ae.lua")
print("install finished")