Created
November 10, 2024 01:15
-
-
Save XDuskAshes/c573c79de562cc32444a1f12206cd4c4 to your computer and use it in GitHub Desktop.
Script to get Luz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This is just a script I made to get Luz since I'm tired of getting it manually. Have fun. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Simple tool to snatch up JackMacWindows' Luz. | |
| -- Luz: <https://github.com/MCJack123/Luz> | |
| -- Made by XDuskAshes - <https://github.com/XDuskAshes/> | |
| -- Released under CC-0, do what you will. | |
| local luzrepo = "https://raw.githubusercontent.com/MCJack123/Luz/refs/heads/lz77-deflate-identifiers/" | |
| local luzrepotest = "https://raw.githubusercontent.com/MCJack123/Luz/refs/heads/lz77-deflate-identifiers/LICENSE" | |
| local luzrepocontent = {"LibDeflate.lua","compress.lua","decompress.lua","histogram.lua","inspect.lua","lex.lua","luz.lua","lz77.lua","maketree.lua","minify.lua","token_decode_tree.lua","token_encode_map.lua"} | |
| -- Using lz77-deflate-identifiers because that's the default. I made this a variable for your own | |
| -- per-use-case cases. Dammit, english sucks. | |
| local function doNothing() -- Do nothing. | |
| local cx, cy = term.getCursorPos() | |
| term.setCursorPos(cx,cy) | |
| end | |
| local function netTest(url) -- test a url for it's existence. if it doesn't exist, check for 8.8.8.8 and if that fails then error | |
| local request = http.get(url) | |
| if not request then | |
| request = http.get("8.8.8.8") | |
| if not request then | |
| return false, "cant reach 8.8.8.8, is your internet working?" | |
| else | |
| return false, "blocked or doesn't exist: "..url | |
| end | |
| else | |
| return true, "exists: "..url | |
| end | |
| end | |
| local function writeFile(file,content) | |
| -- check if the file already exists | |
| if fs.exists(shell.resolve(file)) then | |
| printError("[write]: exists: "..file) -- i *could* wrap in an "xpcall()" for actually good error handling, but i am frankly too lazy right now | |
| return | |
| end | |
| -- check if content is empty | |
| if content == "" or content == nil then | |
| printError("[write]: content for "..file.." invalid or nonexistent") | |
| return | |
| end | |
| if type(content) == "string" then | |
| doNothing() | |
| elseif type(content) == "table" then | |
| doNothing() | |
| else | |
| printError("[write]: invalid type for content: "..type(content)) | |
| return | |
| end | |
| local handle = fs.open(shell.resolve(file),"w") | |
| -- alright, now we write. if it's a string just write the line, if it's a table go bit-by-bit | |
| if type(content) == "string" then | |
| handle.writeLine(content) | |
| elseif type(content) == "table" then | |
| for k,v in pairs(content) do | |
| handle.writeLine(v) | |
| end | |
| else -- if it gets past the previous check | |
| printError("[write]: invalid type for content: "..type(content)) | |
| return | |
| end | |
| handle.close() | |
| -- extra check for the file | |
| if not fs.exists(shell.resolve(file)) then | |
| printError("[write]: write failed for: "..file) | |
| return | |
| end | |
| print("write success: "..file) | |
| end | |
| -- testing - uncomment as needed | |
| --[[ | |
| local tblText = {"testing","tester"} | |
| writeFile("/test.txt","this is a test") | |
| writeFile("/testtbl.txt",tblText) | |
| writeFile("/test-should-fail.txt",8) | |
| ]] | |
| local status, message = netTest(luzrepotest) | |
| if not status then | |
| error(message) | |
| else | |
| print(message) | |
| end | |
| print("enter the directory to write Luz's files to. '/' is default.") | |
| write("> ") | |
| local writeluzto = read() | |
| if writeluzto == "" or writeluzto == nil then | |
| print("defaulting to root") | |
| writeluzto = "/" | |
| else | |
| if not fs.exists(shell.resolve(writeluzto)) then | |
| printError("invalid: "..writeluzto..", defaulting to '/'") | |
| writeluzto = "/" | |
| elseif fs.exists(shell.resolve(writeluzto)) then | |
| if not fs.isDir(shell.resolve(writeluzto)) then | |
| printError("invalid: "..writeluzto..", defaulting to '/'") | |
| writeluzto = "/" | |
| end | |
| end | |
| end | |
| print("writing luz's files to "..writeluzto) | |
| print("getting luz...") | |
| for k,v in pairs(luzrepocontent) do | |
| local request, respond = netTest(luzrepo..v) | |
| if not request then | |
| error(message) | |
| else | |
| request = http.get(luzrepo..v) | |
| end | |
| writeFile(writeluzto..v,request.readAll()) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment