This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
tuxarn's profile picture

Computercraft repository on own webserver instead of pastebin

Started by tuxarn, 24 September 2013 - 03:09 PM
tuxarn #1
Posted 24 September 2013 - 05:09 PM
HI!
To simplify the way i put programs on my turtles on the server I'm hosting, I made this setup based on
stuff i found in threads on this forum.
Mainly this thread: http://www.computerc...__fromsearch__1

My question is regarding this script i call "update"



print("Downloading updates from the Server")
local downloadPath = 'http://www.mywebserver.org/computercraft/'
local files = http.get('http://www.mywebserver.org/list.php')
local line = files.readLine()
while line do
  local req = http.get(downloadPath..line)
  local f = fs.open(line, 'w')
  f.write(req.readAll())
  req.close()
  f.close()
  line = files.readLine()
end
files.close()
print("Update complete")



Now i want this script to download this content to a folder instead of root and i don't quite know how to modify the update script to do so.
Any help would be awesome! :)/> Thanks!
Lyqyd #2
Posted 24 September 2013 - 10:43 PM
Split into new topic.
LBPHacker #3
Posted 25 September 2013 - 12:37 AM
As you can see, the 7th line is the one which actually creates the file (not entirely true, it's line 10 actually, but we need line 7 now). There you can see
fs.open(file, "w")
That opens a file in write mode and returns a handle. The path of the file is … well, the file variable. Combine it with a directory, and there you have the file in that directory instead of root.
-- somewhere at the beginning of the program
local downloadsDir = "downloads"
The new line 7:
local f = fs.open(fs.combine(downloadsDir, file), "w")
tuxarn #4
Posted 27 September 2013 - 09:32 AM
Thanks LBPHacker it works now thanks to you! I only had to change your "file" to "line".
This really changes my workflow. I have a simple bash script that puts my newly edited files on the webserver and i only have to run my updater to get the latest versions of the programs to the turtle. I will never use the in game editor again :D/>