The Opus package manager deletes the entire package directory on update (fs.delete(packageDir)) before re-downloading files. This wiped all config files (.manager_config, .client_config, etc.) that were stored inside packages/inventory-manager/. Fix: add _configPath() helper to every program that resolves config file paths to usr/config/inventory-manager/ when running under Opus, which lives outside the package directory and survives updates. Falls back to the local _path() for standalone (non-Opus) use. Updated files: - inventoryManager.lua, manager/config.lua, inventoryClient.lua, inventoryWebBridge.lua, dropperController.lua, craftingTurtle.lua - .package install script: saves configs to usr/config/inventory-manager/ - autorun/startup.lua: checks both persistent and package dirs - startup/client.lua: uses persistent dir for .client_setup/.dropper_config - web/server/Dockerfile: switch health check to wget (from prior fix)
90 lines
2.4 KiB
Lua
90 lines
2.4 KiB
Lua
-- Inventory Manager - Opus autorun script
|
|
-- Detects configured role and launches the appropriate program at boot
|
|
|
|
local fs = _G.fs
|
|
local kernel = _G.kernel
|
|
local os = _G.os
|
|
local peripheral = _G.peripheral
|
|
local shell = _ENV.shell
|
|
|
|
local BASE = 'packages/inventory-manager'
|
|
local CFG = 'usr/config/inventory-manager'
|
|
|
|
-------------------------------------------------
|
|
-- Determine role from config files written during install
|
|
-------------------------------------------------
|
|
|
|
local function cfgExists(name)
|
|
return fs.exists(fs.combine(CFG, name))
|
|
or fs.exists(fs.combine(BASE, name))
|
|
end
|
|
|
|
local role
|
|
if cfgExists('.manager_config') then
|
|
role = 'manager'
|
|
elseif cfgExists('.client_config') then
|
|
role = 'client'
|
|
elseif cfgExists('.webbridge_config') then
|
|
role = 'bridge'
|
|
elseif _G.turtle then
|
|
role = 'turtle'
|
|
end
|
|
|
|
if not role then return end
|
|
|
|
-------------------------------------------------
|
|
-- Register reboot listener as a kernel hook
|
|
-- Allows remote reboot via modem (channel 4205)
|
|
-------------------------------------------------
|
|
|
|
local SYSTEM_CHANNEL = 4205
|
|
|
|
local modem = peripheral.find('modem')
|
|
if modem then
|
|
modem.open(SYSTEM_CHANNEL)
|
|
|
|
kernel.hook('modem_message', function(_, data)
|
|
-- data = { side, channel, replyChannel, message, distance }
|
|
if data[2] == SYSTEM_CHANNEL
|
|
and type(data[4]) == 'table'
|
|
and data[4].type == 'reboot'
|
|
then
|
|
local target = data[4].target or 'all'
|
|
if target == 'all'
|
|
or target == role
|
|
or target == tostring(os.getComputerID())
|
|
then
|
|
os.reboot()
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
|
|
-------------------------------------------------
|
|
-- Launch the program for this role
|
|
-------------------------------------------------
|
|
|
|
local programs = {
|
|
manager = 'inventoryManager.lua',
|
|
client = 'inventoryClient.lua',
|
|
bridge = 'inventoryWebBridge.lua',
|
|
turtle = 'craftingTurtle.lua',
|
|
}
|
|
|
|
local program = fs.combine(BASE, programs[role])
|
|
|
|
if shell.openForegroundTab then
|
|
shell.openForegroundTab(program)
|
|
|
|
-- Client role also runs the dropper controller
|
|
if role == 'client' then
|
|
local dropper = fs.combine(BASE, 'dropperController.lua')
|
|
if fs.exists(dropper) then
|
|
shell.openTab(dropper)
|
|
end
|
|
end
|
|
else
|
|
-- No multishell — run directly (blocks boot)
|
|
shell.run(program)
|
|
end
|