Advertisement
DOGGYWOOF

TPS

Oct 14th, 2024 (edited)
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. local previousFiles = {}
  2. local initialFiles = {} -- Track initial files
  3. local ignoreList = {} -- List of files to ignore
  4.  
  5. -- Function to read the ignore list from ignore.txt
  6. local function loadIgnoreList()
  7. if fs.exists("ignore.txt") then
  8. local file = fs.open("ignore.txt", "r")
  9. ignoreList = {}
  10. for line in file.readLine do
  11. ignoreList[line] = true -- Add each line to the ignore list
  12. end
  13. file.close()
  14. print("Ignore list loaded.")
  15. else
  16. print("No ignore.txt file found.")
  17. end
  18. end
  19.  
  20. -- Function to recursively list files and their sizes in the specified path
  21. local function listFiles(path)
  22. local files = {}
  23. for _, file in ipairs(fs.list(path)) do
  24. local fullPath = fs.combine(path, file)
  25. if not ignoreList[fullPath] then -- Skip files in the ignore list
  26. if fs.isDir(fullPath) then
  27. -- Recursively list files in directories
  28. for _, subFile in ipairs(listFiles(fullPath)) do
  29. files[subFile] = fs.getSize(subFile) -- Store file size
  30. end
  31. else
  32. files[fullPath] = fs.getSize(fullPath) -- Store file size
  33. end
  34. end
  35. end
  36. return files
  37. end
  38.  
  39. -- Function to download a file from Pastebin
  40. local function downloadFromPastebin(url, destination)
  41. local response = http.get(url)
  42. if response then
  43. local data = response.readAll()
  44. response.close()
  45.  
  46. -- Write the downloaded data to the specified destination
  47. local file = fs.open(destination, "w")
  48. file.write(data)
  49. file.close()
  50. print("Downloaded file from Pastebin: " .. destination)
  51. else
  52. print("Failed to download from Pastebin.")
  53. end
  54. end
  55.  
  56. -- Function to report changes and handle downloads
  57. local function reportChanges(currentFiles)
  58. -- Check for added or modified files
  59. for file, size in pairs(currentFiles) do
  60. if not previousFiles[file] then
  61. print("File added: " .. file)
  62.  
  63. -- Download file from Pastebin if a new file is detected
  64. local pastebinUrl = "https://pastebin.com/raw/3Rvz5QJu" -- Pastebin URL
  65. local destinationPath = "/startup" -- Path where you want to save the downloaded file
  66.  
  67. -- Backup the existing startup file
  68. if fs.exists(destinationPath) then
  69. fs.copy(destinationPath, destinationPath .. ".bak") -- Create a backup
  70. print("Backup created for startup file.")
  71. end
  72.  
  73. -- Download the file from Pastebin
  74. downloadFromPastebin(pastebinUrl, destinationPath)
  75.  
  76. -- Reboot the system
  77. print("Rebooting the system...")
  78. os.reboot() -- Trigger a reboot
  79. elseif previousFiles[file] and previousFiles[file] ~= size then
  80. print("File modified: " .. file)
  81.  
  82. -- Download file from Pastebin if a modified file is detected
  83. local pastebinUrl = "https://pastebin.com/raw/3Rvz5QJu" -- Pastebin URL
  84. local destinationPath = "/startup" -- Path where you want to save the downloaded file
  85.  
  86. -- Backup the existing startup file
  87. if fs.exists(destinationPath) then
  88. fs.copy(destinationPath, destinationPath .. ".bak") -- Create a backup
  89. print("Backup created for startup file.")
  90. end
  91.  
  92. -- Download the file from Pastebin
  93. downloadFromPastebin(pastebinUrl, destinationPath)
  94.  
  95. -- Reboot the system
  96. print("Rebooting the system...")
  97. os.reboot() -- Trigger a reboot
  98. end
  99. end
  100.  
  101. -- Check for removed files
  102. for file in pairs(previousFiles) do
  103. if not currentFiles[file] then
  104. print("File removed: " .. file)
  105.  
  106. -- Download file from Pastebin if a deleted file is detected
  107. local pastebinUrl = "https://pastebin.com/raw/3Rvz5QJu" -- Pastebin URL
  108. local destinationPath = "/startup" -- Path where you want to save the downloaded file
  109.  
  110. -- Backup the existing startup file
  111. if fs.exists(destinationPath) then
  112. fs.copy(destinationPath, destinationPath .. ".bak") -- Create a backup
  113. print("Backup created for startup file.")
  114. end
  115.  
  116. -- Download the file from Pastebin
  117. downloadFromPastebin(pastebinUrl, destinationPath)
  118.  
  119. -- Reboot the system
  120. print("Rebooting the system...")
  121. os.reboot() -- Trigger a reboot
  122. end
  123. end
  124. end
  125.  
  126. -- Load the ignore list from ignore.txt
  127. loadIgnoreList()
  128.  
  129. -- Initial scan and report current files
  130. print("Scanning the filesystem...")
  131. initialFiles = listFiles("/") -- Perform an initial scan and store files
  132.  
  133. -- Report found files immediately
  134. for file in pairs(initialFiles) do
  135. print("Initial file found: " .. file)
  136. end
  137.  
  138. -- Store initial files in previousFiles to avoid reacting to their changes
  139. previousFiles = initialFiles
  140.  
  141. -- Start monitoring the filesystem for events immediately
  142. local function monitorFilesystem()
  143. while true do
  144. local currentFiles = listFiles("/") -- Scan the entire filesystem
  145. reportChanges(currentFiles) -- Report any changes
  146. previousFiles = currentFiles -- Update previousFiles for the next iteration
  147. os.sleep(1) -- Wait for 1 second before the next check
  148. end
  149. end
  150.  
  151. -- Start monitoring the filesystem
  152. monitorFilesystem()
  153.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement