-- pastebin ID: 4nM1G6YK
-- URL: https://pastebin.com/4nM1G6YK
-- Update script for downloading latest versions from pastebin
-- Usage: update
-- Configuration: Add your pastebin IDs and corresponding filenames here
local scripts = {
-- Format: ["pastebin_id"] = "filename",
-- Your actual pastebin IDs:
["Qky674zS"] = "central_server",
["LXSNkj5r"] = "mine",
["QbSGDWvG"] = "turtle_server",
["kfHc79KV"] = "remotectl",
["uqfTY1e5"] = "platform",
["4nM1G6YK"] = "update",
-- Add more scripts here as needed:
}
-- Function to check if a file exists
local function fileExists(filename)
return fs.exists(filename)
end
-- Function to backup a file
local function backupFile(filename)
if fileExists(filename) then
local backupName = filename .. ".backup"
if fileExists(backupName) then
fs.delete(backupName)
end
fs.copy(filename, backupName)
print(" Created backup: " .. backupName)
return true
end
return false
end
-- Function to download a script from pastebin
local function downloadScript(pastebinId, filename, createBackup)
print("Updating " .. filename .. "...")
-- Create backup if requested and file exists
if createBackup then
backupFile(filename)
end
-- Remove existing file if it exists
if fileExists(filename) then
print(" Removing existing " .. filename)
fs.delete(filename)
end
-- Download new version
print(" Downloading from pastebin ID: " .. pastebinId)
local success = shell.run("pastebin", "get", pastebinId, filename)
if success then
print(" Successfully updated " .. filename)
return true
else
print(" Failed to download " .. filename)
-- Restore backup if download failed and backup exists
local backupName = filename .. ".backup"
if createBackup and fileExists(backupName) then
print(" Restoring backup...")
fs.copy(backupName, filename)
end
return false
end
end
-- Main update function
local function updateAll(createBackups)
print("Starting script update process...")
if createBackups then
print("Backup mode: ON")
end
print("=" .. string.rep("=", 50))
local totalScripts = 0
local successCount = 0
local failCount = 0
-- Count total scripts
for _ in pairs(scripts) do
totalScripts = totalScripts + 1
end
if totalScripts == 0 then
print("No scripts configured for update.")
print("Please edit the 'scripts' table in update.lua to add your pastebin IDs and filenames.")
return
end
-- Update each script
for pastebinId, filename in pairs(scripts) do
if downloadScript(pastebinId, filename, createBackups) then
successCount = successCount + 1
else
failCount = failCount + 1
end
print() -- Empty line for readability
end
-- Summary
print("=" .. string.rep("=", 50))
print("Update complete!")
print("Total scripts: " .. totalScripts)
print("Successfully updated: " .. successCount)
print("Failed: " .. failCount)
if failCount > 0 then
print("\nSome updates failed. Please check:")
print("- Internet connection")
print("- Pastebin IDs are correct")
print("- Pastebin service is available")
end
if createBackups and successCount > 0 then
print("\nBackup files created with .backup extension")
print("You can remove them with: update cleanup")
end
end
-- Function to list configured scripts
local function listScripts()
print("Configured scripts:")
print("=" .. string.rep("=", 50))
if next(scripts) == nil then
print("No scripts configured.")
print("Edit update.lua to add your pastebin IDs and filenames.")
else
for pastebinId, filename in pairs(scripts) do
local status = fileExists(filename) and "EXISTS" or "MISSING"
print(string.format("%-20s -> %-10s [%s]", filename, pastebinId, status))
end
end
end
-- Function to clean up backup files
local function cleanup()
print("Cleaning up backup files...")
local cleanedCount = 0
for _, filename in pairs(scripts) do
local backupName = filename .. ".backup"
if fileExists(backupName) then
fs.delete(backupName)
print("Removed: " .. backupName)
cleanedCount = cleanedCount + 1
end
end
print("Cleaned up " .. cleanedCount .. " backup files.")
end
-- Function to add a new script to the update list
local function addScript(pastebinId, filename)
if not pastebinId or not filename then
print("Usage: update add <pastebin_id> <filename>")
return
end
-- This is a simple way to show how to add scripts
-- In practice, you'd want to modify the file or use a separate config file
print("To add this script to the update list, edit update.lua and add:")
print('["' .. pastebinId .. '"] = "' .. filename .. '",')
print("to the scripts table.")
end
-- Function to show help
local function showHelp()
print("Update Script Help")
print("=" .. string.rep("=", 50))
print("update - Update all scripts (no backups)")
print("update backup - Update all scripts with backups")
print("update list - List configured scripts and status")
print("update cleanup - Remove all .backup files")
print("update add <id> <file> - Show how to add a script")
print("update help - Show this help")
print("")
print("Configuration:")
print("Edit the 'scripts' table in update.lua to add your pastebin IDs and filenames")
end
-- Command line argument handling
local args = {...}
local command = args[1] or "update"
if command == "update" or command == "" then
updateAll(false)
elseif command == "backup" then
updateAll(true)
elseif command == "add" then
addScript(args[2], args[3])
elseif command == "list" then
listScripts()
elseif command == "cleanup" then
cleanup()
elseif command == "help" then
showHelp()
else
print("Unknown command: " .. command)
print("Use 'update help' for available commands.")
end
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|0 👍
/0 👎
0 B
|👍
/👎
0 B
|0 👍
/0 👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|0 👍
/0 👎