diff --git a/bootstrap.lua b/bootstrap.lua new file mode 100644 index 0000000..3b65aa7 --- /dev/null +++ b/bootstrap.lua @@ -0,0 +1,47 @@ +-- Easy installer. Bootstrapped by http://pastebin.com/p8PJVxC4 + +local base_url, dest = select(1,...) +dest = dest or 'computercraft-github' + +print("Downloading from %s":format(base_url)) + +local FILES = { + 'apis/dkjson', + 'apis/github', + 'programs/github', + 'github' +} + +local function request(url_path) + local request = http.get(base_url..'/'..url_path) + local status = request.getResponseCode() + local response = request.readAll() + request.close() + return status, response +end + +local function makeFile(file_path, data) + local file = fs.open(dest..'/'..file_path,'w') + file.write(data) + file.close() +end + +-- download github +for key, path in pairs(FILES) do + local try = 0 + repeat + local status, response + if try >= 3 then + printError(('Unable to download %s - status of %s'):format(path, status)) + printError(response) + fs.delete(dest) + return + end + status, response = request(path) + try = try + 1 + until status ~= 200 +end + +print('Downloaded') +shell.setDir(dest) +loadfile('install.lua', getfenv())() diff --git a/github b/github deleted file mode 100644 index 18257bf..0000000 --- a/github +++ /dev/null @@ -1,3 +0,0 @@ -f = loadfile('github.rom/programs/github') -setfenv(f, getfenv()) -f(...) diff --git a/install b/install new file mode 100644 index 0000000..55c6dfd --- /dev/null +++ b/install @@ -0,0 +1,28 @@ +-- Install the program by rewriting dofiles, and creating a link to the program + +local dest_dir = shell.resolve(select(..., 1) or '_build') + +print("Installing to %s...":format(dest_dir)) + +local copyAndFix(src_file, src_file) + local r = fs.open(src_file, 'r') + local data = r.readAll() + r.close() + local w = fs.open(dest, 'w') + data = data:gsub('dofile%("', 'dofile("'..dest_dir..'/') + w.write(data) + w.close() +end + +for _, folder in ipairs({'api', 'programs'}) + for _, file in pairs(fs.list(folder)) do + copyAndFix(folder..'/'..file, dest_dir..'/'..folder..'/'..file) + end +end + +for _, prog in pairs(fs.list('programs')) do + local f = fs.open('/'..prog, 'w') + f.write([[loadfile('%s', getfenv())(...)]]:format(dest_dir..'/programs/'..prog)) +end +print("github by Eric Wieser installed!") +dofile('github') diff --git a/install.lua b/install.lua deleted file mode 100644 index 9bd13cc..0000000 --- a/install.lua +++ /dev/null @@ -1,69 +0,0 @@ --- Easy installer. Bootstrapped by http://pastebin.com/p8PJVxC4 - -local repo, tree = select(1,...) -if not tree then - -- assume tree as the preferred argument. - tree = repo or 'master' -end -if not repo then - repo = 'eric-wieser/computercraft-github' -end - -local REPO_BASE = ('https://raw.githubusercontent.com/%s/%s/'):format(repo, tree) - -local FILES = { - 'apis/dkjson', - 'apis/github', - 'programs/github', - 'github' -} - -local function request(url_path) - local request = http.get(REPO_BASE..url_path) - local status = request.getResponseCode() - local response = request.readAll() - request.close() - return status, response -end - -local function makeFile(file_path, data) - local file = fs.open('github.rom/'..file_path,'w') - file.write(data) - file.close() -end - -local function rewriteDofiles() - for _, file in pairs(FILES) do - local filename = ('github.rom/%s'):format(file) - local r = fs.open(filename, 'r') - local data = r.readAll() - r.close() - local w = fs.open(filename, 'w') - data = data:gsub('dofile%("', 'dofile("github.rom/') - w.write(data) - w.close() - end -end - --- install github -for key, path in pairs(FILES) do - local try = 0 - local status, response = request(path) - while status ~= 200 and try <= 3 do - status, response = request(path) - try = try + 1 - end - if status then - makeFile(path, response) - else - printError(('Unable to download %s'):format(path)) - fs.delete('github.rom') - fs.delete('github') - break - end -end - -rewriteDofiles() -fs.move('github.rom/github', 'github') -print("github by Eric Wieser installed!") -dofile('github') diff --git a/readme.md b/readme.md index 36e5fe3..767ccb3 100644 --- a/readme.md +++ b/readme.md @@ -7,10 +7,18 @@ Installation ------------ The easiest way to install this project on your computercraft computer is by running: - pastebin run p8PJVxC4 [|] + pastebin run zDAQHQdz [|] The branch or tag argument is optional, and defaults to 'master'. +### Updates + +To update an existing installation, do: + + > github clone eric-wieser/computercraft-github . + ... + > install + Usage ----- @@ -23,15 +31,16 @@ The destination folder is optional, and defaults to the current folder name. Wat > github clone eric-wieser/computercraft-github ccgit Discovering files... Downloading: - github readme.md apis/dkjson apis/github programs/github + install + bootstrap.lua [============================================] 100% > ls ccgit apis programs - github readme.md + readme.md bootstrap.lua ---