167 lines
4.1 KiB
Lua
167 lines
4.1 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/"
|
|
|
|
-- Available address book servers
|
|
local addressBooks = {
|
|
"ATM9"
|
|
-- Add more servers here as they become available
|
|
}
|
|
|
|
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
|
|
|
|
-- Select address book
|
|
print("Available address books:")
|
|
for i, book in ipairs(addressBooks) do
|
|
print(" " .. i .. ". " .. book)
|
|
end
|
|
print("")
|
|
print("Which address book would you like to use?")
|
|
write("Enter number (default 1): ")
|
|
local choice = tonumber(read()) or 1
|
|
|
|
if choice < 1 or choice > #addressBooks then
|
|
print("Invalid choice, using ATM9")
|
|
choice = 1
|
|
end
|
|
|
|
local selectedAddressBook = addressBooks[choice]
|
|
print("Selected: " .. selectedAddressBook)
|
|
print("")
|
|
|
|
local success = 0
|
|
local failed = 0
|
|
|
|
-- Core files to download
|
|
local coreFiles = {
|
|
"startup.lua",
|
|
"utils.lua",
|
|
"display.lua",
|
|
"events.lua",
|
|
"handlers.lua"
|
|
}
|
|
|
|
-- Download core files
|
|
print("Downloading core files...")
|
|
for _, filename in ipairs(coreFiles) 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
|
|
print("")
|
|
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
|
|
|
|
-- Download addresses.lua from server-specific folder
|
|
print("")
|
|
print("Downloading addresses for " .. selectedAddressBook .. "...")
|
|
local addressUrl = baseUrl .. "addresses/" .. selectedAddressBook .. "/addresses.lua"
|
|
if downloadFile("addresses.lua", addressUrl) then
|
|
success = success + 1
|
|
else
|
|
failed = failed + 1
|
|
end
|
|
|
|
-- Update config with selected address book
|
|
print("")
|
|
print("Configuring address book setting...")
|
|
if fs.exists("config.lua") then
|
|
local file = fs.open("config.lua", "r")
|
|
if file then
|
|
local content = file.readAll()
|
|
file.close()
|
|
|
|
-- Update addressBook line
|
|
content = content:gsub(
|
|
'config%.addressBook%s*=%s*"[^"]*"',
|
|
'config.addressBook = "' .. selectedAddressBook .. '"'
|
|
)
|
|
|
|
file = fs.open("config.lua", "w")
|
|
if file then
|
|
file.write(content)
|
|
file.close()
|
|
print(" [OK] Address book set to: " .. selectedAddressBook)
|
|
end
|
|
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("The system will start automatically.")
|
|
print("To change settings, edit config.lua")
|
|
print("")
|
|
print("Rebooting in 3 seconds...")
|
|
sleep(3)
|
|
os.reboot()
|
|
end
|