Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions bootstrap.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- Easy installer. Bootstrapped by http://pastebin.com/p8PJVxC4

local base_url, dest = select(1,...)
dest = dest or 'computercraft-github'
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps cc-git-src would be better here?

Copy link
Contributor

@aaronmallen aaronmallen Oct 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you're essentially creating here is a custom rom... I think the best default would be github.rom.


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)
Copy link
Contributor

@aaronmallen aaronmallen Oct 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work as expected. For some reason if request fails CC is making request = nil. We should mimic what we did in the getAPI method:

local request = http.get(base_url..'/'..url_path)
local success = false
local response = nil
if request then
  success = request.getResponseCode() == 200
  response = request.readAll()
  request.close()
end
return success, response

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use my recommended change above this would need to be

until status

end

print('Downloaded')
shell.setDir(dest)
loadfile('install.lua', getfenv())()
3 changes: 0 additions & 3 deletions github

This file was deleted.

28 changes: 28 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -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')
Copy link
Owner Author

@eric-wieser eric-wieser Aug 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps /github.rom is a better location here, because then you can delete the source directory without also killing the installation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean by killing the installation? You can delete a program's file while it's running and CC will continue to run the program as temp


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'})
Copy link
Contributor

@aaronmallen aaronmallen Oct 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better served as a table like what we do with FILES instead of hardcoded here.

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')
69 changes: 0 additions & 69 deletions install.lua

This file was deleted.

15 changes: 12 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ Installation
------------
The easiest way to install this project on your computercraft computer is by running:

pastebin run p8PJVxC4 [<branch>|<tag>]
pastebin run zDAQHQdz [<branch>|<tag>]

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
-----

Expand All @@ -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

---

Expand Down