View difference between Paste ID: p9ZkrH1i and 8U6Bh75s
SHOW: | | - or go back to the newest paste.
1-
if not (string.sub(os.version(),1,8)=="TurtleOS") then
1+
-- folder where to put the APIs
2-
  print("Diese API ist nur fuer Turtles gedacht!")
2+
local apiFolder = "npeAPIs"
3-
  return
3+
4
-- list of files
5
local fileInfos= {
6-
local startupFile = "turtle.startup"
6+
  -- APIs
7-
local apiFolder = "customAPI"
7+
  {
8-
local apiFile = "turtle.advanced"
8+
    name = "updater.lua",
9-
local apiPath = fs.combine(apiFolder,apiFile)
9+
    pbcode = "HF7vwabd",
10
    isApi = true,
11
    startupParams = "--noupdatecheck",
12
    needsTurtle = false
13
  },
14
  {
15
    name = "betterturtle.lua",
16
    pbcode = "6XL8EYXe",
17
    isApi = true,
18
    needsTurtle = true
19
  },
20
  -- programs
21
  {
22
    name = "quarry.lua",
23-
-- break if the api file is allready existing
23+
    pbcode = "HqXCPzCg",
24-
if fs.exists(apiPath) then
24+
    needsTurtle = true
25-
  print("\""..apiPath.."\" existiert")
25+
  },
26-
  print("  schon auf dem System!")
26+
  {
27-
  return
27+
    name = "quarry-minion.lua",
28
    pbcode = "5pFNPRZv",
29
    needsTurtle = true
30-
local oldStartup = getFileContent("startup")
30+
  },
31-
local newStartup = getFileContent("disk/"..startupFile)
31+
  {
32
    name = "ignorelist-generator.lua",
33-
-- break if defined startup file is not existant
33+
    pbcode = "fw5C7u8t",
34-
if not newStartup then
34+
    needsTurtle = true
35-
  print("\"disk/"..startupFile.."\" konnte")
35+
  },
36-
  print("  nicht gelesen werden!")
36+
  {
37-
  return
37+
    name = "oredict-sorter.lua",
38
    pbcode = "94eCzump",
39
    needsTurtle = true
40-
-- break if api file could not be found
40+
  },
41-
if not fs.exists("disk/"..apiFile) then
41+
  {
42-
  print("\"disk/"..apiFile.."\" existiert nicht!")
42+
    name = "testcode.lua",
43-
  return
43+
    pbcode = "dP7Rm6p7"
44
  },
45
  -- files
46-
-- try copying api file
46+
  {
47
    name = "ignore.list",
48
    pbcode = "ymBVBbt1"
49
  },
50-
fs.copy("disk/"..apiFile, apiPath)
50+
  {
51
    name = "oredict.config",
52-
-- check if startup exists on system
52+
    pbcode = "iPPApNHk"
53-
if not oldStartup then
53+
  },
54-
  -- if not, simply copy the startup file
54+
}
55-
  fs.copy("disk/"..startupFile, "startup")
55+
56-
else
56+
local function status(text, color, delay)
57-
  -- if it does, merge the new one in at the front
57+
  term.clear()
58
  term.setCursorPos(1,1)
59-
  file.writeLine("--- LOAD API ---")
59+
  if term.isColor() then
60-
  file.writeLine(newStartup)
60+
    term.setTextColor(colors.yellow)
61-
  file.writeLine()
61+
62-
  file.writeLine("--- BEGIN OF STARTUP ---")
62+
  print(" NPE Installation Tool ")
63-
  file.writeLine(oldStartup)
63+
  print("-----------------------")
64
  print()
65
  if term.isColor() then
66
    term.setTextColor(colors.white)
67
  end
68-
textutils.slowPrint("Installation vollstaendig!")
68+
  term.write("--> ")
69
  if term.isColor() then
70
    if color == nil then
71
      color = colors.white
72
    end
73
    term.setTextColor(color)
74
  end
75
  print(text)
76
  if term.isColor() then
77
    term.setTextColor(colors.white)
78
  end
79
  
80
  if delay then
81
    sleep(delay)
82
  end
83
end
84
85
86
local function getFileContent( path )
87
  local result
88
  if fs.exists(path) then
89
    local file = fs.open(path, "r")
90
    result = file.readAll()
91
    file.close()
92
  end
93
  return result
94
end
95
96
97
local function key()
98
  local event, c = os.pullEvent("char")
99
  return c
100
end
101
102
103
-- main program part
104
local startupLines = nil
105
local wait = 0.5
106
107
108
if not fs.exists(apiFolder) then
109
  fs.makeDir(apiFolder)
110
end
111
112
for _,fileInfo in ipairs(fileInfos) do
113
  local filePath = fileInfo.isApi and fs.combine(apiFolder, fileInfo.name)
114
                   or fileInfo.name
115
116
  if fileInfo.needsTurtle and (not turtle) then
117
    status("Skipping \""..fileInfo.name.."\" (Turtle)", colors.orange, wait)
118
  elseif fs.exists(filePath) then
119
    -- ignore if the file already exists
120
    status("Skip: \""..fileInfo.name.."\" already exists", colors.orange, wait)
121
  else
122
    local install = true
123
    -- always install APIs
124
    if not fileInfo.isApi then
125
      local c = nil
126
      repeat
127
        status("Install "..fileInfo.name.."? -> y/n")
128
        c = key()
129
        install = c == "y"
130
      until (c == "y" or c == "n")
131
    end
132
133
    if install then
134
      status("Installing file: \""..fileInfo.name.."\"", colors.lightBlue, wait)
135
136
      shell.run("pastebin", "get", fileInfo.pbcode, filePath)
137
138
      if fileInfo.isApi then
139
        if (startupLines == nil) then
140
          startupLines = { "--- LOAD APIs ---" }
141
        end
142
143
        local startupline = "shell.run(\""..filePath
144
        if fileInfo.startupParams then
145
          startupline = startupline.."\", \""..fileInfo.startupParams
146
        end
147
        startupline = startupline.."\")"
148
        startupLines[#startupLines+1] = startupline
149
      end
150
151
      status("File installed!", colors.lime, wait)
152
    end
153
  end
154
end
155
156
157
-- merge the new startup lines in at the front of old startup file (or create a new one)
158
if startupLines then
159
  local oldStartup = getFileContent("startup")
160
  if oldStartup then
161
    status("Modifying startup file...", colors.lightBlue, wait)
162
  else
163
    status("Creating startup file...", colors.lightBlue, wait)
164
  end
165
166
  local file = fs.open("startup", "w")
167
  for i=1,#startupLines do
168
    file.writeLine(startupLines[i])
169
  end
170
  if oldStartup then
171
    file.writeLine()
172
    file.writeLine("--- BEGIN OF STARTUP ---")
173
    file.writeLine(oldStartup)
174
  end
175
  file.close()
176
end
177
178
-- print success message
179
status("Installation complete!", colors.lime, wait)
180
181
shell.run("reboot")