Browse Source

Finally fixed get-all

master
BuildTools 1 year ago
parent
commit
466f530a5a
  1. 53
      get-all.lua

53
get-all.lua

@ -11,9 +11,13 @@ if args[1] == nil then
return
end
-- Finish this off
local function strip(s, p)
return string.gsub(s, string.format("(^(%s+))|((%s+)$)", p, p))
-- Stolen from Lua users because I'm bad with RegEx
function trim(s, p)
-- Set to whitespace trim otherwise
if p == nil then
p = "%s"
end
return (s:gsub(string.format("^%s*(.-)%s*$", p, p), "%1"))
end
local function split(s, sep)
@ -28,6 +32,17 @@ local function split(s, sep)
return t
end
-- Slice table
function slice(tbl, first, last, step)
local sliced = {}
for i = first or 1, last or #tbl, step or 1 do
sliced[#sliced+1] = tbl[i]
end
return sliced
end
local function fixURL(url)
if not string.match(url, "/$") and not string.match(url, "\\.") then
url = url.."/"
@ -54,33 +69,43 @@ local function makeRequest(url)
return url, result
end
local function getFiles(url, result)
local function getFiles(url, result, workDir)
-- Set first initial working directory to current directory
if workDir == nil then
workDir = shell.getWorkingDirectory()
end
-- Loop through results
for i in string.gmatch(result, "href=\".-\"") do
local dir = split(i, "\"")[2]
local cwd = ""
if string.match(dir, ".lua$") then
local subdir = table.concat(slice(split(url), 4), "/")
print(subdir)
shell.setWorkingDirectory(workDir.."/"..subdir)
shell.execute("wget -f "..url..dir)
goto continue
end
cwd = workDir.."/"..trim(dir,"/")
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)
if fs.exists(cwd) and not fs.isDirectory(cwd) then
fs.remove(cwd)
end
-- Make missing dir
if not fs.exists(dir) then
fs.makeDirectory(dir)
if not fs.exists(cwd) then
fs.makeDirectory(cwd)
end
-- Recurse
shell.setWorkingDirectory(dir)
print(shell.getWorkingDirectory())
shell.setWorkingDirectory(cwd)
getFiles(makeRequest(url..dir))
end
::continue::
@ -90,6 +115,6 @@ end
-- Grab all files on the server
local path = shell.getWorkingDirectory()
getFiles(makeRequest(fixURL(args[1])))
fs.setDirectory(path)
shell.setWorkingDirectory(path)
-- wget -f http://mc.bashed.rocks:13699/get-all.lua
Loading…
Cancel
Save