Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local previousFiles = {}
- local initialFiles = {} -- Track initial files
- local ignoreList = {} -- List of files to ignore
- -- Function to read the ignore list from ignore.txt
- local function loadIgnoreList()
- if fs.exists("ignore.txt") then
- local file = fs.open("ignore.txt", "r")
- ignoreList = {}
- for line in file.readLine do
- ignoreList[line] = true -- Add each line to the ignore list
- end
- file.close()
- print("Ignore list loaded.")
- else
- print("No ignore.txt file found.")
- end
- end
- -- Function to recursively list files and their sizes in the specified path
- local function listFiles(path)
- local files = {}
- for _, file in ipairs(fs.list(path)) do
- local fullPath = fs.combine(path, file)
- if not ignoreList[fullPath] then -- Skip files in the ignore list
- if fs.isDir(fullPath) then
- -- Recursively list files in directories
- for _, subFile in ipairs(listFiles(fullPath)) do
- files[subFile] = fs.getSize(subFile) -- Store file size
- end
- else
- files[fullPath] = fs.getSize(fullPath) -- Store file size
- end
- end
- end
- return files
- end
- -- Function to download a file from Pastebin
- local function downloadFromPastebin(url, destination)
- local response = http.get(url)
- if response then
- local data = response.readAll()
- response.close()
- -- Write the downloaded data to the specified destination
- local file = fs.open(destination, "w")
- file.write(data)
- file.close()
- print("Downloaded file from Pastebin: " .. destination)
- else
- print("Failed to download from Pastebin.")
- end
- end
- -- Function to report changes and handle downloads
- local function reportChanges(currentFiles)
- -- Check for added or modified files
- for file, size in pairs(currentFiles) do
- if not previousFiles[file] then
- print("File added: " .. file)
- -- Download file from Pastebin if a new file is detected
- local pastebinUrl = "https://pastebin.com/raw/3Rvz5QJu" -- Pastebin URL
- local destinationPath = "/startup" -- Path where you want to save the downloaded file
- -- Backup the existing startup file
- if fs.exists(destinationPath) then
- fs.copy(destinationPath, destinationPath .. ".bak") -- Create a backup
- print("Backup created for startup file.")
- end
- -- Download the file from Pastebin
- downloadFromPastebin(pastebinUrl, destinationPath)
- -- Reboot the system
- print("Rebooting the system...")
- os.reboot() -- Trigger a reboot
- elseif previousFiles[file] and previousFiles[file] ~= size then
- print("File modified: " .. file)
- -- Download file from Pastebin if a modified file is detected
- local pastebinUrl = "https://pastebin.com/raw/3Rvz5QJu" -- Pastebin URL
- local destinationPath = "/startup" -- Path where you want to save the downloaded file
- -- Backup the existing startup file
- if fs.exists(destinationPath) then
- fs.copy(destinationPath, destinationPath .. ".bak") -- Create a backup
- print("Backup created for startup file.")
- end
- -- Download the file from Pastebin
- downloadFromPastebin(pastebinUrl, destinationPath)
- -- Reboot the system
- print("Rebooting the system...")
- os.reboot() -- Trigger a reboot
- end
- end
- -- Check for removed files
- for file in pairs(previousFiles) do
- if not currentFiles[file] then
- print("File removed: " .. file)
- -- Download file from Pastebin if a deleted file is detected
- local pastebinUrl = "https://pastebin.com/raw/3Rvz5QJu" -- Pastebin URL
- local destinationPath = "/startup" -- Path where you want to save the downloaded file
- -- Backup the existing startup file
- if fs.exists(destinationPath) then
- fs.copy(destinationPath, destinationPath .. ".bak") -- Create a backup
- print("Backup created for startup file.")
- end
- -- Download the file from Pastebin
- downloadFromPastebin(pastebinUrl, destinationPath)
- -- Reboot the system
- print("Rebooting the system...")
- os.reboot() -- Trigger a reboot
- end
- end
- end
- -- Load the ignore list from ignore.txt
- loadIgnoreList()
- -- Initial scan and report current files
- print("Scanning the filesystem...")
- initialFiles = listFiles("/") -- Perform an initial scan and store files
- -- Report found files immediately
- for file in pairs(initialFiles) do
- print("Initial file found: " .. file)
- end
- -- Store initial files in previousFiles to avoid reacting to their changes
- previousFiles = initialFiles
- -- Start monitoring the filesystem for events immediately
- local function monitorFilesystem()
- while true do
- local currentFiles = listFiles("/") -- Scan the entire filesystem
- reportChanges(currentFiles) -- Report any changes
- previousFiles = currentFiles -- Update previousFiles for the next iteration
- os.sleep(1) -- Wait for 1 second before the next check
- end
- end
- -- Start monitoring the filesystem
- monitorFilesystem()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement