autoupdater.lua

74 lines · 1.9 KB

Open raw

eHydra Auto-Updater System

Usage: autoupdater <github_raw_url> <local_filename>

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/eHydra_wip/autoupdater.lua
1-- eHydra Auto-Updater System
2-- Downloads and installs programs from GitHub raw links
3-- Usage: autoupdater <github_raw_url> <local_filename>
4
5local args = {...}
6
7if #args < 2 then
8 print("Usage: autoupdater <github_raw_url> <local_filename> [folder]")
9 print("Example: autoupdater https://raw.githubusercontent.com/user/repo/main/file.lua my-program eHydra")
10 print("Example: autoupdater https://raw.githubusercontent.com/user/repo/main/file.lua quarry quarry")
11 return
12end
13
14local url = args[1]
15local filename = args[2]
16local folder = args[3] or "eHydra" -- Default to eHydra folder if not specified
17local fileExtension = filename == "README" and ".md" or ".lua"
18local programsPath = "programs/" .. folder .. "/" .. filename .. fileExtension
19
20-- Ensure programs directory and folder exist
21if not fs.exists("programs") then
22 fs.makeDir("programs")
23end
24if not fs.exists("programs/" .. folder) then
25 fs.makeDir("programs/" .. folder)
26end
27
28print("eHydra Auto-Updater v1.0")
29print("========================")
30print("URL: " .. url)
31print("Target: " .. programsPath)
32print()
33
34-- Delete existing file if it exists
35if fs.exists(programsPath) then
36 print("Removing existing file...")
37 fs.delete(programsPath)
38end
39
40-- Download the file
41print("Downloading...")
42local response = http.get(url)
43
44if not response then
45 print("Error: Failed to download from " .. url)
46 print("Check your internet connection and URL")
47 return
48end
49
50print("Download successful!")
51
52-- Write the file
53local file = fs.open(programsPath, "w")
54if not file then
55 print("Error: Could not create file " .. programsPath)
56 response.close()
57 return
58end
59
60file.write(response.readAll())
61file.close()
62response.close()
63
64print("File saved to: " .. programsPath)
65print("Installation complete!")
66
67-- Make file executable if it's a startup file
68if filename == "startup" then
69 print("Setting up startup file...")
70end
71
72print()
73print("You can now run: " .. filename)
74