-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathsetup.lua
95 lines (84 loc) · 3.4 KB
/
setup.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
92
93
94
95
-- Paste this into OpenComputer terminal to download and set up NIDAS
-- wget https://raw.githubusercontent.com/S4mpsa/NIDAS/master/setup.lua -f
local shell = require("shell")
local filesystem = require("filesystem")
local computer = require("computer")
local component = require("component")
local gpu = component.gpu
local width, height = gpu.getResolution()
local colorA = 0x00A6FF
local colorB = 0xFF00FF
gpu.fill(1, 1, width, height, " ")
gpu.setForeground(0x181818)
gpu.fill(width / 2 - 11, height / 2 - 3, 23, 6, "▄")
gpu.fill(width / 2 - 10, height / 2 - 2, 21, 4, " ")
gpu.setForeground(colorA)
gpu.set(width / 2 - 7, height / 2 - 2, "Updating NIDAS")
local tarMan = "https://raw.githubusercontent.com/mpmxyz/ocprograms/master/usr/man/tar.man"
local tarBin = "https://raw.githubusercontent.com/mpmxyz/ocprograms/master/home/bin/tar.lua"
shell.setWorkingDirectory("/usr/man")
shell.execute("wget -fq " .. tarMan)
shell.setWorkingDirectory("/bin")
shell.execute("wget -fq " .. tarBin)
local NIDAS
local arg = {...}
if arg[1] == "test" or arg[1] == "latest" then
NIDAS = "https://github.com/S4mpsa/NIDAS/releases/download/v-1/NIDAS.tar"
elseif arg[1] == "dev" or arg[1] == "staging" then
NIDAS = "https://github.com/S4mpsa/NIDAS/releases/download/v0/NIDAS.tar"
else
NIDAS = "https://github.com/S4mpsa/NIDAS/releases/latest/download/NIDAS.tar"
end
local successful =
pcall(
function()
local workDir = "/home/NIDAS/"
local persistent = {
"tar-exclude.txt",
".gitignore",
".github",
"README.md",
"settings",
".git",
".vscode"
}
filesystem.makeDirectory("/home/temp")
for _, thing in ipairs(persistent) do
if filesystem.exists(workDir .. thing) then
shell.execute("cp -r " .. workDir .. thing .. " /home/temp/" .. thing)
end
end
filesystem.remove(workDir)
filesystem.makeDirectory(workDir)
shell.setWorkingDirectory(workDir)
gpu.set(width / 2 - 8, height / 2 - 1, "Downloading . . .")
shell.execute("wget -fq " .. NIDAS)
gpu.set(width / 2 - 8, height / 2 - 1, " ")
gpu.set(width / 2 - 7, height / 2, "Extracting . . .")
shell.execute("tar -xf NIDAS.tar")
filesystem.remove(workDir .. "NIDAS.tar")
filesystem.copy(workDir .. ".shrc", "/home/.shrc")
filesystem.copy(workDir .. "setup.lua", "/home/setup.lua")
filesystem.makeDirectory(workDir .. "settings")
for _, thing in ipairs(persistent) do
if filesystem.exists("/home/temp/" .. thing) then
shell.execute("cp -r /home/temp/" .. thing .. " " .. workDir)
end
end
filesystem.remove("/home/temp/")
filesystem.remove("/lib/core/boot.lua")
filesystem.copy(workDir .. "nidas_boot.lua", "/lib/core/boot.lua")
filesystem.remove("/etc/profile.lua")
filesystem.copy(workDir .. "nidas_profile.lua", "/etc/profile.lua")
gpu.set(width / 2 - 7, height / 2, " ")
gpu.set(width / 2 - 7, height / 2, "Update complete. ")
gpu.setForeground(colorB)
gpu.set(width / 2 - 5, height / 2 + 1, "Rebooting ")
os.sleep(1)
computer.shutdown(true)
end
)
if (not successful) then
gpu.setForeground(0xFF0000)
gpu.set(width / 2 - 7, height / 2, "Update failed! ")
end