OpenComputers Von Neumann Machine Programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.1 KiB

local shell = require("shell")
local fs = require("filesystem")
local internet = require("internet")
-- local ll = require("liblua")
local args = {...}
-- Error checking
if args[1] == nil then
print("URL must exist")
return
end
-- Finish this off
local function strip(s, p)
return string.gsub(s, string.format("(^(%s+))|((%s+)$)", p, p))
end
local function split(s, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(s, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
local function fixURL(url)
if not string.match(url, "/$") and not string.match(url, "\\.") then
url = url.."/"
end
return url
end
local function makeRequest(url)
local handle = internet.request(url)
local result = ""
for chunk in handle do result = result..chunk end
-- Grab the metatable for the handle. This contains the
-- internal HTTPRequest object.
local mt = getmetatable(handle)
-- The response method grabs the information for
-- the HTTP response code, the response message, and the
-- response headers.
local code, message, headers = mt.__index.response()
if code ~=200 then
return nil, "Bad code received"
end
return url, result
end
local function getFiles(url, result)
for i in string.gmatch(result, "href=\".-\"") do
local dir = split(i, "\"")[2]
if string.match(dir, ".lua$") then
shell.execute("wget -f "..url..dir)
goto continue
end
if string.match(dir, "/$")
and not string.match(dir, ".git")
and not string.match(dir, ".vscode")
then
dir = dir
-- Remove any weird files
if fs.exists(dir) and not fs.isDirectory(dir) then
fs.remove(dir)
end
-- Make missing dir
if not fs.exists(dir) then
fs.makeDirectory(dir)
end
-- Recurse
shell.setWorkingDirectory(dir)
print(shell.getWorkingDirectory())
getFiles(makeRequest(url..dir))
end
::continue::
end
end
-- Grab all files on the server
local path = shell.getWorkingDirectory()
getFiles(makeRequest(fixURL(args[1])))
fs.setDirectory(path)
-- wget -f http://mc.bashed.rocks:13699/get-all.lua