View difference between Paste ID: 3W5WiVJs and X4AgTg0E
SHOW: | | - or go back to the newest paste.
1-
if not http then
1+
local url = "https://raw.github.com/LDDestroier/CraftBang/master/craftbang/"
2-
	print "It doesn't seem like you have http enabled."
2+
local files = {}
3-
	print "Enable it first, restart minecraft, then run the installer again."
3+
local filelist = {
4-
	return
4+
	'desktop.lua';
5
	'dialog.lua';
6
	'panel.lua';
7-
local url = "https://raw.github.com/Kingdaro/CraftBang/master/installer"
7+
	'session.lua';
8-
local instPath = ".cbinstaller"
8+
	'terminal.lua';
9
	'lib/arealib.lua';
10-
print "Downloading installer"
10+
	'lib/redirect.lua';
11
}
12-
local download = http.get(url)
12+
13-
if download then
13+
local function clear()
14-
	local file = fs.open(instPath, 'w')
14+
	term.clear()
15-
	file.write(download.readAll())
15+
	term.setCursorPos(1,1)
16
end
17-
	download.close()
17+
18
clear()
19-
	shell.run(instPath)
19+
local errors = false
20-
	fs.delete(instPath)
20+
for i=1, #filelist do
21
	local filename = filelist[i]
22-
	for _,v in pairs(rs.getSides()) do
22+
	local fullurl = url .. filename
23-
		disk.eject(v)
23+
	local localpath = '/craftbang/'..filename
24
25
	local download = http.get(fullurl)
26-
	write "Restart now? [Y/n] "
26+
	if download then
27
		print("Fetching "..filename)
28
		files[localpath] = download.readAll()
29-
		print "I'll let you return to your shell then."
29+
		download.close()
30-
		print "Do what you need to do."
30+
31
		print("Couldn't get '"..filename .. "'.")
32-
		textutils.slowWrite("Goodbye!")
32+
		print "Installation failed."
33-
		sleep(1)
33+
		return
34-
		os.reboot()
34+
35
end
36-
else
36+
sleep(1)
37-
	print "Couldn't get installer"
37+
38
local installed = false
39
if fs.exists('/craftbang') then
40
	clear()
41
	installed = true
42
43
	write "Overwrite current installation? [Y/n] "
44
	local input = read():lower():sub(1,1)
45
	if input == 'n' then
46
		print "Will not write files."
47
		return
48
	end
49
	fs.delete('/craftbang')
50
end
51
52
clear()
53
fs.makeDir('/craftbang')
54
fs.makeDir('/craftbang/lib')
55
for path, content in pairs(files) do
56
	print("Writing "..path)
57
	local file = fs.open(path, 'w')
58
	file.write(content)
59
	file.close()
60
end
61
print "Installation complete!"
62
sleep(1)
63
64
if not installed then
65
	clear()
66
67
	local startupContent = [[
68
	shell.run("craftbang/session.lua")
69
	]]
70
71
	write "Run CraftBang on startup? "
72
	if fs.exists('startup.lua') then
73
		print "\nYour current startup file will be renamed to 'startup-old.lua'."
74
	end
75
	write "[Y/n] "
76
77
	local input = read():lower():sub(1,1)
78
79
	if input == 'n' then
80
		print "In that case, run 'craftbang/session.lua' to start CraftBang."
81
	else
82
		if fs.exists('startup.lua') then
83
			if fs.exists('startup-old.lua') then
84
				fs.delete('startup-old.lua')
85
			end
86
			fs.move('startup.lua','startup-old.lua')
87
		end
88
89
		local startup = fs.open('startup.lua', 'w')
90
		startup.write(startupContent)
91
		startup.close()
92
		print "CraftBang will now run on startup."
93
	end
94
end