View difference between Paste ID: JtUdmXws and xeki5ds3
SHOW: | | - or go back to the newest paste.
1-
local version = "0.3"
1+
local version = "0.12"
2-
local delapt = false
2+
3
if not http then
4-
if not fs.exists("apt") then
4+
  printError( "Script requires http API" )
5-
	delapt = true
5+
  printError( "Set http_enable to true in ComputerCraft.cfg" )
6-
	shell.run("pastebin get JtUdmXws apt")
6+
  return
7
end
8
 
9-
os.loadAPI("apt")
9+
function get(url)
10
  write( "Connecting to server... " )
11
 
12
  http.request("https://meinkraftcult.repl.co/"..url)
13-
if apt.get("namecorupt/version") ~= version then
13+
 
14-
	apt.install("namecorupt/installer","startup")
14+
  local requesting = true
15-
	shell.run("startup")
15+
 
16
  while requesting do
17
    local event, url, sourceText = os.pullEvent()
18
  
19
    if event == "http_success" then
20-
if not fs.exists(".ncl") then
20+
      local respondedText = sourceText.readAll()
21-
	fs.makeDir(".ncl")
21+
      sourceText.close()
22
    
23
      requesting = false
24-
apt.install("namecorupt/loader",".ncl/.loader")
24+
      return respondedText
25-
apt.install("namecorupt/payload",".ncl/.payload")
25+
    elseif event == "http_failure" then
26
			print(url)
27-
-- Finish
27+
      printError("Server didn't respond.")
28
    
29-
if delapt then
29+
      requesting = false
30-
	fs.delete("apt")
30+
    end
31
  end
32
end
33-
shell.run(".ncl/.loader")
33+
34
function install(program,xpath)
35
	if fs.exists(xpath) then fs.delete(xpath) end
36
	local res = get(program..".lua")
37
	if res then        
38
		local file = fs.open(xpath, "w" )
39
		file.write( res )
40
		file.close()
41
		print( "Downloaded as "..fs.getName(xpath) )
42
	end
43
end
44
45
-- Update
46
47
if get("apt/version") ~= version then
48
	install("apt/get","apt")
49
end
50
51
-- Run
52
53
local Args = {...}
54
55
if #Args == 2 then
56
	install(unpack(Args))
57
end