mirror of
https://github.com/ShadowKatStudios/OC-Minitel.git
synced 2024-11-27 04:18:05 +11:00
made mtcfg more generally useful
This commit is contained in:
parent
2a2e347663
commit
8f628d7b10
@ -4,39 +4,30 @@ local computer = require "computer"
|
|||||||
local shell = require "shell"
|
local shell = require "shell"
|
||||||
|
|
||||||
local hostname = os.getenv("HOSTNAME")
|
local hostname = os.getenv("HOSTNAME")
|
||||||
local cfgfile = "/etc/minitel.cfg"
|
|
||||||
local cfg = {}
|
|
||||||
cfg.debug = false
|
|
||||||
cfg.port = 4096
|
|
||||||
cfg.retry = 10
|
|
||||||
cfg.retrycount = 64
|
|
||||||
cfg.route = true
|
|
||||||
cfg.rctime = 15
|
|
||||||
cfg.pctime = 30
|
|
||||||
cfg.sroutes = {}
|
|
||||||
|
|
||||||
local args, ops = shell.parse(...)
|
local args, ops = shell.parse(...)
|
||||||
|
local cfgfile = args[1]
|
||||||
|
local cfg = {}
|
||||||
|
|
||||||
local function clear()
|
local function clear()
|
||||||
io.write("\27[2J\27[H")
|
io.write("\27[2J\27[H")
|
||||||
end
|
end
|
||||||
|
|
||||||
local fobj = io.open(cfgfile, "rb")
|
if cfgfile then -- if a config file argument is specified, load it
|
||||||
if fobj then
|
local fobj = io.open(cfgfile, "rb")
|
||||||
cfg = serial.unserialize(fobj:read("*a"))
|
if not fobj then
|
||||||
end
|
print("Error: couldn't open file")
|
||||||
|
return false
|
||||||
if not hostname then
|
|
||||||
local fobj = io.open("/etc/hostname","rb")
|
|
||||||
if fobj then
|
|
||||||
hostname = fobj:read()
|
|
||||||
fobj:close()
|
|
||||||
end
|
end
|
||||||
end
|
cfg = serial.unserialize(fobj:read("*a"))
|
||||||
|
fobj:close()
|
||||||
clear()
|
if not cfg then
|
||||||
|
print("Error: couldn't unserialize file")
|
||||||
if not hostname then
|
return
|
||||||
|
end
|
||||||
|
else -- if not, set the hostname and edit the minitel config file
|
||||||
|
-- you could just replace this whole block with an error message I guess, but let's default to configuring minitel
|
||||||
|
cfgfile = "/etc/minitel.cfg"
|
||||||
|
if not hostname then
|
||||||
print("Hostname not configured.")
|
print("Hostname not configured.")
|
||||||
hostname = computer.address():sub(1,8)
|
hostname = computer.address():sub(1,8)
|
||||||
io.write("New hostname? ["..hostname.."] ")
|
io.write("New hostname? ["..hostname.."] ")
|
||||||
@ -52,15 +43,31 @@ if not hostname then
|
|||||||
os.execute("hostname --update")
|
os.execute("hostname --update")
|
||||||
print("Hostname set to "..hostname..". Press any key to continue.")
|
print("Hostname set to "..hostname..". Press any key to continue.")
|
||||||
event.pull("key_down")
|
event.pull("key_down")
|
||||||
end
|
end
|
||||||
|
|
||||||
if ops.firstrun then
|
if ops.firstrun then -- if --firstrun, quit now
|
||||||
os.execute("rc minitel enable")
|
os.execute("rc minitel enable")
|
||||||
print("Run mtcfg to configure advanced settings.")
|
print("Run mtcfg to configure advanced settings.")
|
||||||
return
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
cfg.debug = false -- some default settings
|
||||||
|
cfg.port = 4096
|
||||||
|
cfg.retry = 10
|
||||||
|
cfg.retrycount = 64
|
||||||
|
cfg.route = true
|
||||||
|
cfg.rctime = 15
|
||||||
|
cfg.pctime = 30
|
||||||
|
cfg.sroutes = {}
|
||||||
|
|
||||||
|
local fobj = io.open(cfgfile, "rb") -- attempt to replace the default settings
|
||||||
|
if fobj then
|
||||||
|
cfg = serial.unserialize(fobj:read("*a")) or cfg
|
||||||
|
fobj:close()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local keytab = {}
|
local keytab = {} -- contains the keys because we don't want to work with the table indices directly
|
||||||
for k,v in pairs(cfg) do
|
for k,v in pairs(cfg) do
|
||||||
if type(v) ~= "table" then
|
if type(v) ~= "table" then
|
||||||
keytab[#keytab+1] = k
|
keytab[#keytab+1] = k
|
||||||
@ -101,7 +108,7 @@ local function editsetting(k)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
while run do
|
while run do -- main loop
|
||||||
drawmenu()
|
drawmenu()
|
||||||
local _,_, ch, co = event.pull("key_down")
|
local _,_, ch, co = event.pull("key_down")
|
||||||
if ch == 113 and co == 16 then
|
if ch == 113 and co == 16 then
|
||||||
@ -139,6 +146,3 @@ if fobj then
|
|||||||
fobj:close()
|
fobj:close()
|
||||||
print("Settings successfully written!")
|
print("Settings successfully written!")
|
||||||
end
|
end
|
||||||
|
|
||||||
print("Enabling daemon...")
|
|
||||||
os.execute("rc minitel enable")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user