108 lines
2.6 KiB
Lua
108 lines
2.6 KiB
Lua
--[[
|
|
Stargate Control System - Installer
|
|
Downloads and installs all necessary files from the git repository
|
|
]]
|
|
|
|
local baseUrl = "https://git.munebase.dev/Munelit/StargateControl/raw/branch/master/"
|
|
|
|
local files = {
|
|
-- Core files (always download)
|
|
"startup.lua",
|
|
"addresses.lua",
|
|
"utils.lua",
|
|
"display.lua",
|
|
"events.lua",
|
|
"handlers.lua",
|
|
|
|
-- Config file (only download if doesn't exist)
|
|
config = "config.lua"
|
|
}
|
|
|
|
local function downloadFile(filename, url)
|
|
print("Downloading " .. filename .. "...")
|
|
|
|
-- Delete existing file first (to ensure clean update)
|
|
if fs.exists(filename) then
|
|
fs.delete(filename)
|
|
end
|
|
|
|
local response = http.get(url)
|
|
|
|
if response then
|
|
local content = response.readAll()
|
|
response.close()
|
|
|
|
local file = fs.open(filename, "w")
|
|
if file then
|
|
file.write(content)
|
|
file.close()
|
|
print(" [OK] " .. filename)
|
|
return true
|
|
else
|
|
print(" [FAIL] Could not write " .. filename)
|
|
return false
|
|
end
|
|
else
|
|
print(" [FAIL] Could not download " .. filename)
|
|
return false
|
|
end
|
|
end
|
|
|
|
print("========================================")
|
|
print(" Stargate Control System Installer")
|
|
print("========================================")
|
|
print("")
|
|
|
|
-- Check if HTTP is enabled
|
|
if not http then
|
|
print("ERROR: HTTP is not enabled!")
|
|
print("Please enable it in the ComputerCraft config.")
|
|
return
|
|
end
|
|
|
|
local success = 0
|
|
local failed = 0
|
|
|
|
-- Download core files
|
|
for _, filename in ipairs(files) do
|
|
local url = baseUrl .. filename
|
|
if downloadFile(filename, url) then
|
|
success = success + 1
|
|
else
|
|
failed = failed + 1
|
|
end
|
|
end
|
|
|
|
-- Download config file only if it doesn't exist
|
|
if fs.exists("config.lua") then
|
|
print("Config file already exists - skipping")
|
|
print(" [SKIP] config.lua")
|
|
else
|
|
local url = baseUrl .. "config.lua"
|
|
if downloadFile("config.lua", url) then
|
|
success = success + 1
|
|
else
|
|
failed = failed + 1
|
|
end
|
|
end
|
|
|
|
print("")
|
|
print("========================================")
|
|
print("Installation complete!")
|
|
print(" Success: " .. success)
|
|
print(" Failed: " .. failed)
|
|
print("========================================")
|
|
print("")
|
|
|
|
if failed > 0 then
|
|
print("WARNING: Some files failed to download.")
|
|
print("Please check your internet connection and try again.")
|
|
else
|
|
print("All files downloaded successfully!")
|
|
print("")
|
|
print("To start the program, run: startup")
|
|
print("")
|
|
print("Note: You may need to configure config.lua")
|
|
print("with your specific settings before running.")
|
|
end
|