Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --File: /startup
- --Install : pastebin get cXTMm7G1 startup
- function downloadFromPastebin(pastebinCode, filename)
- local url = "https://pastebin.com/raw/" .. pastebinCode -- Construct the URL
- local response, err = http.get(url) -- Perform the HTTP GET request
- if response then
- local file = fs.open(filename, "w") -- Open a file for writing
- file.write(response.readAll()) -- Write the response to the file
- file.close() -- Close the file
- response.close() -- Close the HTTP response
- print(pastebinCode .. " -> " .. filename)
- else
- error("Pastebin download " .. pasetebinCode .. " error: " .. err)
- end
- end
- -- Function to create a directory
- function createDirectory(dirName)
- if not fs.exists(dirName) then -- Check if the directory already exists
- fs.makeDir(dirName) -- Create the directory
- print("Directory created: " .. dirName)
- else
- print("Directory already exists: " .. dirName)
- end
- end
- -- Main program starts here
- print("Downloading programs from Pastebin...")
- fs.makeDir("cattech" )
- downloadFromPastebin("gBBQJrAH", "/cattech/file.lua")
- dofile("/cattech/file.lua")
- downloadNamedFileFromPastebin("0xjcxant")
- dofile("/cattech/updateAll.lua")
- -- Define an array where each element is a pair: {pattern, program}
- local patternPrograms = {
- --{"MiningTurtle%d+", "mining_program.lua"}, -- Matches "MiningTurtle" followed by digits
- {"WorldServer", "/worldServer"},
- {"testing", "/testCode"},
- }
- local initialFuel = turtle.getFuelLevel()
- print("Starting at " .. initialFuel .. " fuel")
- local turtleName = os.getComputerLabel()
- if not turtleName then
- print("Turtle has no name, no auto start.")
- return
- else
- for _, pair in ipairs(patternPrograms) do
- local pattern, program = pair[1], pair[2]
- -- Check if the turtle's name matches the pattern
- if string.match(turtleName, pattern) then
- -- Check if the program exists
- if fs.exists(program) then
- print("Pattern matched: " .. pattern .. ". Starting program: " .. program)
- shell.run(program)
- return
- else
- print("Error: Program " .. program .. " not found.")
- return
- end
- end
- end
- print("Turtle name " .. turtleName .. " no autostart")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement