Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 499d311

Browse files
committed
Separate downloading and installation
1 parent d688675 commit 499d311

File tree

4 files changed

+71
-72
lines changed

4 files changed

+71
-72
lines changed

bootstrap.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- Easy installer. Bootstrapped by http://pastebin.com/p8PJVxC4
2+
3+
local base_url, dest = select(1,...)
4+
dest = dest or 'computercraft-github'
5+
6+
local FILES = {
7+
'apis/dkjson',
8+
'apis/github',
9+
'programs/github',
10+
'github'
11+
}
12+
13+
local function request(url_path)
14+
local request = http.get(base_url..'/'..url_path)
15+
local status = request.getResponseCode()
16+
local response = request.readAll()
17+
request.close()
18+
return status, response
19+
end
20+
21+
local function makeFile(file_path, data)
22+
local file = fs.open(dest..'/'..file_path,'w')
23+
file.write(data)
24+
file.close()
25+
end
26+
27+
-- download github
28+
for key, path in pairs(FILES) do
29+
local try = 0
30+
repeat
31+
if try >= 3 then
32+
printError(('Unable to download %s'):format(path))
33+
fs.delete(dest)
34+
return
35+
end
36+
local status, response = request(path)
37+
try = try + 1
38+
until status ~= 200
39+
end
40+
41+
print('Downloaded')
42+
shell.setDir(dest)
43+
loadfile('install.lua', getfenv())()

github

Lines changed: 0 additions & 3 deletions
This file was deleted.

install

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Install the program by rewriting dofiles, and creating a link to the program
2+
3+
print("Installing...")
4+
5+
local dest_dir = select(..., 1) or '_build'
6+
7+
local copyAndFix(src_file, src_file)
8+
local r = fs.open(src_file, 'r')
9+
local data = r.readAll()
10+
r.close()
11+
local w = fs.open(dest, 'w')
12+
data = data:gsub('dofile%("', 'dofile("'..dest_dir..'/')
13+
w.write(data)
14+
w.close()
15+
end
16+
17+
for _, folder in ipairs({'api', 'programs'})
18+
for _, file in pairs(fs.list(folder)) do
19+
copyAndFix(folder..'/'..file, dest_dir..'/'..folder..'/'..file)
20+
end
21+
end
22+
23+
for _, prog in pairs(fs.list('programs')) do
24+
local f = fs.open('/'..prog, 'w')
25+
f.write([[loadfile('%s', getfenv())()]]:format(shell.resolve(dest_dir..'/programs/'..prog)))
26+
end
27+
print("github by Eric Wieser installed!")
28+
dofile('github')

install.lua

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)