Advertisement
posicat

/startup

Sep 10th, 2024 (edited)
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. --File: /startup
  2. --Install : pastebin get cXTMm7G1 startup
  3.  
  4. function downloadFromPastebin(pastebinCode, filename)
  5. local url = "https://pastebin.com/raw/" .. pastebinCode -- Construct the URL
  6. local response, err = http.get(url) -- Perform the HTTP GET request
  7.  
  8. if response then
  9. local file = fs.open(filename, "w") -- Open a file for writing
  10. file.write(response.readAll()) -- Write the response to the file
  11. file.close() -- Close the file
  12. response.close() -- Close the HTTP response
  13. print(pastebinCode .. " -> " .. filename)
  14. else
  15. error("Pastebin download " .. pasetebinCode .. " error: " .. err)
  16. end
  17. end
  18.  
  19. -- Function to create a directory
  20. function createDirectory(dirName)
  21. if not fs.exists(dirName) then -- Check if the directory already exists
  22. fs.makeDir(dirName) -- Create the directory
  23. print("Directory created: " .. dirName)
  24. else
  25. print("Directory already exists: " .. dirName)
  26. end
  27. end
  28.  
  29. -- Main program starts here
  30. print("Downloading programs from Pastebin...")
  31. fs.makeDir("cattech" )
  32. downloadFromPastebin("gBBQJrAH", "/cattech/file.lua")
  33. dofile("/cattech/file.lua")
  34. downloadNamedFileFromPastebin("0xjcxant")
  35.  
  36. dofile("/cattech/updateAll.lua")
  37.  
  38. -- Define an array where each element is a pair: {pattern, program}
  39. local patternPrograms = {
  40. --{"MiningTurtle%d+", "mining_program.lua"}, -- Matches "MiningTurtle" followed by digits
  41. {"WorldServer", "/worldServer"},
  42. {"testing", "/testCode"},
  43. }
  44.  
  45. local initialFuel = turtle.getFuelLevel()
  46. print("Starting at " .. initialFuel .. " fuel")
  47.  
  48. local turtleName = os.getComputerLabel()
  49.  
  50. if not turtleName then
  51. print("Turtle has no name, no auto start.")
  52. return
  53. else
  54. for _, pair in ipairs(patternPrograms) do
  55. local pattern, program = pair[1], pair[2]
  56. -- Check if the turtle's name matches the pattern
  57. if string.match(turtleName, pattern) then
  58. -- Check if the program exists
  59. if fs.exists(program) then
  60. print("Pattern matched: " .. pattern .. ". Starting program: " .. program)
  61. shell.run(program)
  62. return
  63. else
  64. print("Error: Program " .. program .. " not found.")
  65. return
  66. end
  67. end
  68. end
  69. print("Turtle name " .. turtleName .. " no autostart")
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement