-- install.lua
-- ComputerCraft Network System Installer
-- Downloads files from GitHub and installs Basalt
local GITHUB_REPO = "https://raw.githubusercontent.com/Temperdox/CC_Networking/main"
-- File structure mapping: [local_path] = github_path
local FILE_MAP = {
-- Root level files
["startup.lua"] = "startup.lua",
["router_startup.lua"] = "router_startup.lua",
["wifi_client.lua"] = "wifi_client.lua",
["dhcp_client.lua"] = "dhcp_client.lua",
["firewall_manager.lua"] = "firewall_manager.lua",
["router_monitor.lua"] = "router_monitor.lua",
["network_demo.lua"] = "network_demo.lua",
["user_startup.lua"] = "user_startup.lua",
-- Bin directory
["bin/netd.lua"] = "bin/netd.lua",
["bin/routerd.lua"] = "bin/routerd.lua",
-- Lib directory
["lib/network.lua"] = "lib/network.lua",
-- Config files
["etc/network.cfg"] = "config/network.cfg",
["etc/router.cfg"] = "config/router.cfg",
["etc/firewall.rules"] = "etc/firewall.rules",
["etc/wireless.cfg"] = "config/wireless.cfg",
["etc/wifi.cfg"] = "config/wifi.cfg",
-- Config directory
["config/network.cfg"] = "config/network.cfg",
-- Protocol implementations
["protocols/protocol_names.lua"] = "protocols/protocol_names.lua",
["protocols/statuses.lua"] = "protocols/statuses.lua",
["protocols/network_adapter.lua"] = "protocols/network_adapter.lua",
["protocols/websocket.lua"] = "protocols/websocket.lua",
["protocols/http_client.lua"] = "protocols/http_client.lua",
["protocols/tcp.lua"] = "protocols/tcp.lua",
["protocols/mqtt.lua"] = "protocols/mqtt.lua",
["protocols/ftp.lua"] = "protocols/ftp.lua",
["protocols/ssh.lua"] = "protocols/ssh.lua",
["protocols/webrtc.lua"] = "protocols/webrtc.lua",
-- Utilities
["util/logger.lua"] = "util/logger.lua",
["util/connection_manager.lua"] = "util/connection_manager.lua",
-- Router system
["usr/lib/router/install.lua"] = "usr/lib/router/install.lua",
["usr/lib/router/routerd.lua"] = "usr/lib/router/routerd.lua",
["usr/lib/router/web_admin.lua"] = "usr/lib/router/web_admin.lua",
["usr/lib/router/qos.lua"] = "usr/lib/router/qos.lua",
}
-- Directories to create
local DIRECTORIES = {
"bin", "lib", "etc", "config", "protocols", "util",
"usr", "usr/lib", "usr/lib/router",
"var", "var/run", "var/lib", "var/lib/dhcp", "var/log", "var/cache",
"logs"
}
local function create_directories()
print("Creating directories...")
for _, dir in ipairs(DIRECTORIES) do
if not fs.exists(dir) then
fs.makeDir(dir)
end
end
end
local function download_file(local_path, github_path)
local url = GITHUB_REPO .. "/" .. github_path
print("Downloading: " .. local_path)
local response = http.get(url)
if not response then
print("Failed to download: " .. github_path)
return false
end
local content = response.readAll()
response.close()
local dir = fs.getDir(local_path)
if dir ~= "" and not fs.exists(dir) then
fs.makeDir(dir)
end
local file = fs.open(local_path, "w")
if not file then
print("Failed to create: " .. local_path)
return false
end
file.write(content)
file.close()
return true
end
local function install_basalt()
print("Installing Basalt GUI framework...")
local url = "https://basalt.madefor.cc/install.lua"
local response = http.get(url)
if response then
local installer = response.readAll()
response.close()
local func = load(installer)
if func then
func()
print("Basalt installed successfully")
else
print("Failed to run Basalt installer")
end
else
print("Failed to download Basalt installer")
end
end
local function install_files()
print("Installing network system files...")
for local_path, github_path in pairs(FILE_MAP) do
download_file(local_path, github_path)
sleep(0.05) -- Small delay
end
end
-- Main installation
print("CC Network System Installer")
print("===========================")
if not http then
print("ERROR: HTTP API not available")
return
end
create_directories()
install_files()
install_basalt()
print("Installation complete!")
print("Deleting installer...")
-- Delete this file
fs.delete("install.lua")