From 390e6272ecdcb419e69aa33b9cb5118df6b5dd17 Mon Sep 17 00:00:00 2001 From: roger109z Date: Wed, 16 Oct 2019 00:00:20 -0700 Subject: [PATCH 01/32] Slimmed down startup.lua --- startup.lua | 77 +++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 58 deletions(-) diff --git a/startup.lua b/startup.lua index a5c371c..c796983 100644 --- a/startup.lua +++ b/startup.lua @@ -8,66 +8,27 @@ if not commands then -- Attempt to prevent user from running this on non-command return end -local config = {} - -do -- Configuration parsing - local file, default = fs.open("cfg/allium.lson", "r"), {updates = {deps = true, allium = true}} - local function verify_cfg(input, default, index) - for f_k, f_v in pairs(input) do -- input key, value - for t_k, t_v in pairs(default) do -- standard key, value - if type(f_v) == "table" and type(t_v) == "table" then - if not verify_cfg(f_v, t_v, f_k..".") then - return false - end - elseif f_k == t_k and type(f_v) ~= type(t_v) then - printError("Invalid config option "..(index or "")..f_k.." (expected "..type(t_v)..", got "..type(f_v)..")") - return false - end - end - end - return true - end - local function fill_missing(file, default) - local out = {} - if not file then file = {} end - for k, v in pairs(default) do - if type(v) == "table" then - out[k] = fill_missing(file[k], v) - else - if type(file[k]) == "nil" then - out[k] = v - else - out[k] = file[k] - end - end - end - for k, v in pairs(file) do - if out[k] == nil then - out[k] = v - end - end - return out +--load settings from file +local loadSettings = function(file, default) + assert(type(file) == "string", "file must be a string") + if not fs.exists(file) then + local setting = fs.open(file,"w") + setting.write(textutils.serialise(default)) + setting.close() + return default end - local output = {} - if file then -- Could not read file - output = textutils.unserialise(file.readAll()) or {} - file.close() - end - if verify_cfg(output, default) then -- Make sure none of the config opts are invalid (skips missing ones) - config = fill_missing(output, default) -- Fill in the remaining options that are missing - if config.version ~= allium_version then - config.version = allium_version - file = fs.open("cfg/allium.lson", "w") - if file then - file.write(textutils.serialise(config)) - file.close() - end - end - else - return - end + local setting = fs.open(file, "r") + local config = setting.readAll() + setting.close() + config = textutils.unserialise(config) + if type(config) ~= "table" then + return default + end + return config end +config = loadSettings("cfg/allium.lson", {updates = {dependencies = true, allium = true}}) + -- Checking Allium/Plugin updates if config.updates.allium then if fs.exists("cfg/repolist.csh") then -- Checking for a repolist shell executable @@ -79,7 +40,7 @@ if config.updates.allium then end -- Filling Dependencies -if config.updates.deps then +if config.updates.dependencies then -- Allium DepMan Instance: https://pastebin.com/nRgBd3b6 print("Updating Dependencies...") local didrun = false From 4e8f6be4674b9128d3d7d79990dd0e7efa55346f Mon Sep 17 00:00:00 2001 From: roger109z Date: Wed, 16 Oct 2019 00:59:56 -0700 Subject: [PATCH 02/32] Added checks to ensure that keys are not missing from configs --- startup.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/startup.lua b/startup.lua index c796983..79c822d 100644 --- a/startup.lua +++ b/startup.lua @@ -24,6 +24,17 @@ local loadSettings = function(file, default) if type(config) ~= "table" then return default end + local checkForKeys + checkForKeys = function(default, test) + for key, value in pairs(default) do + if not test[key] then + test[key] = value + elseif type(test[key]) == "table" then + checkForKeys(value, test[key]) + end + end + end + checkForKeys(default, config) return config end From d99c2b463969687a460bcaa43f712a94611fa925 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 19 Oct 2019 01:22:09 -0700 Subject: [PATCH 03/32] General code cleanup - Removed duplicate config checking code in both the startup and main program - Added type checking where it was needed - Updated minor text bleed in allium stem --- .gitignore | 3 +- allium.lua | 70 ++++++++++++----------------------------- plugins/allium-stem.lua | 4 +-- startup.lua | 38 +++++++++++++++------- 4 files changed, 50 insertions(+), 65 deletions(-) diff --git a/.gitignore b/.gitignore index 7b8cb54..8195780 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ lib/* -cfg/* \ No newline at end of file +cfg/* +.DS_Store diff --git a/allium.lua b/allium.lua index 22711ad..7bb1448 100644 --- a/allium.lua +++ b/allium.lua @@ -28,6 +28,15 @@ local function print(noline, ...) -- Magical function that takes in a table and term.setTextColor(text_color) end +local function getData(name) -- Extract data on user from data command + local suc, data = commands.exec("data get entity "..name) + if not suc then return suc, data end + data = data[1]:sub(data[1]:find("{"), -1) + local data = mojson.parseList(data) + if not data then return false end + return data +end + local function deep_copy(table) -- Recursively copy a module out = {} for name, func in pairs(table) do @@ -50,59 +59,18 @@ local cli = { error = {true, "[", colors.red, "E", colors.white, "] "} } -local config + +local config = ... do -- Configuration parsing - local file, default, rule = fs.open("cfg/allium.lson", "r"), {import_timeout = 5, label = "<&r&dAll&5&h[[Hugeblank was here. Hi.]]&i[[https://www.youtube.com/watch?v=hjGZLnja1o8]]i&r&dum&r> "} - local function verify_cfg(input, default, index) - for f_k, f_v in pairs(input) do -- input key, value - for t_k, t_v in pairs(default) do -- standard key, value - if type(f_v) == "table" and type(t_v) == "table" then - if not verify_cfg(f_v, t_v, f_k..".") then - return false - end - elseif f_k == t_k and type(f_v) ~= type(t_v) then - printError("Invalid config option "..(index or "")..f_k.." (expected "..type(t_v)..", got "..type(f_v)..")") - return false - end - end - end - return true - end - local function fill_missing(file, default) - local out = {} - for k, v in pairs(default) do - if type(v) == "table" then - out[k] = fill_missing(file[k], v) - else - if file[k] == nil then - out[k] = v - else - out[k] = file[k] - end - end - end - return out - end - if not file then -- Could not read file - printError("Could not read config") - return - end - local output = textutils.unserialise(file.readAll()) - if not output then -- Config file in invalid format - printError("Could not parse config") + if type(config) ~= "table" then + printError("Invalid input configuration, make sure you're using the provided init file.") return end - allium.version, rule = semver.parse(output.version) + allium.version, rule = semver.parse(config.version) if not allium.version then -- Invalid Allium version printError("Could not parse Allium's version (breaks SemVer rule #"..rule..")") return end - output.version = nil - if verify_cfg(output, default) then -- Invalid configuration option (skips missing ones) - config = fill_missing(output, default) - else - return - end end do -- Allium image setup <3 @@ -160,6 +128,8 @@ allium.tell = function(name, message, alt_name) end allium.execute = function(name, command) + assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") + assert(type(command) == "string", "Invalid argument #2 (string expected, got "..type(command)..")") os.queueEvent("chat_capture", command, "execute", name) end @@ -180,10 +150,9 @@ allium.getPlayers = function() end allium.getPosition = function(name) - local suc, data = commands.exec("data get entity "..name) - if not suc then return false, data end - data = data[1]:sub(data[1]:find("{"), -1) - local data = mojson.parseList(data) + assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") + local data = allium.getData(name) + assert(data, "Failed to get data on user ".. name) return { position = data.Pos, rotation = data.Rotation, @@ -343,6 +312,7 @@ allium.register = function(p_name, version, fullname) end allium.verify = function(param) -- Verification code ripped from DepMan instance + assert(type(param) == "string", "Invalid argument #1 (string expected, got "..type(param)..")") local function convert(str) -- Use the semver API to convert. Provide a detailed error if conversion fails if type(str) ~= "string" then error("Could not convert "..tostring(str)) diff --git a/plugins/allium-stem.lua b/plugins/allium-stem.lua index ad5b8e9..9c48a59 100644 --- a/plugins/allium-stem.lua +++ b/plugins/allium-stem.lua @@ -1,5 +1,5 @@ local allium = require("allium") -local stem = allium.register("allium", "0.4.1", "Allium Stem") +local stem = allium.register("allium", "0.4.2", "Allium Stem") local addDetails do -- Just a block for organization of command parsing stuffs local function infill(variant, execute) @@ -169,7 +169,7 @@ local help = function(name, args, data) data.error(cmd..": "..infill_info) return end - info[#info+1] = "&c&s[["..infill_text.."]]&h[[Click to add to chat input]]"..infill_text + info[#info+1] = "&c&s[["..infill_text.."]]&h[[Click to add to chat input]]"..infill_text.."&r" for i = 1, #infill_info do info[#info+1] = infill_info[i] end diff --git a/startup.lua b/startup.lua index a5c371c..bf5932a 100644 --- a/startup.lua +++ b/startup.lua @@ -1,26 +1,39 @@ shell.openTab("shell") -- Allium version -local allium_version = "0.8.1" +local allium_version = "0.9.0-pr1" if not commands then -- Attempt to prevent user from running this on non-command comps printError("Allium must be run on a command computer") return end -local config = {} +--[[ + DEFAULT ALLIUM CONFIGS ### DO NOT CHANGE THESE ### + Configurations can be changed in /cfg/allium.lson +]] +local default = { + version = allium_version, -- Allium's version + import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. + label = "<&r&dAll&5&h[[Hugeblank was here. Hi.]]&i[[https://www.youtube.com/watch?v=hjGZLnja1o8]]i&r&dum&r> ", -- The label the loader uses + updates = { -- Various auto-update configurations. Server operators may want to change this from the default + deps = true, -- Automatically update dependencies + allium = true -- Automatically update allium + } +} +local config = {} do -- Configuration parsing - local file, default = fs.open("cfg/allium.lson", "r"), {updates = {deps = true, allium = true}} + local file = fs.open("cfg/allium.lson", "r") local function verify_cfg(input, default, index) - for f_k, f_v in pairs(input) do -- input key, value - for t_k, t_v in pairs(default) do -- standard key, value - if type(f_v) == "table" and type(t_v) == "table" then - if not verify_cfg(f_v, t_v, f_k..".") then + for givenField, givenValue in pairs(input) do -- input key, value + for expectedField, expectedValue in pairs(default) do -- standard key, value + if type(givenValue) == "table" and type(expectedValue) == "table" then + if not verify_cfg(givenValue, expectedValue, givenField..".") then return false end - elseif f_k == t_k and type(f_v) ~= type(t_v) then - printError("Invalid config option "..(index or "")..f_k.." (expected "..type(t_v)..", got "..type(f_v)..")") + elseif givenField == expectedField and type(givenValue) ~= type(expectedValue) then + printError("Invalid config option "..(index or "")..givenField.." (expected "..type(expectedValue)..", got "..type(givenValue)..")") return false end end @@ -81,7 +94,7 @@ end -- Filling Dependencies if config.updates.deps then -- Allium DepMan Instance: https://pastebin.com/nRgBd3b6 - print("Updating Dependencies...") + print("Checking for dependency updates...") local didrun = false parallel.waitForAll(function() didrun = shell.run("pastebin run nRgBd3b6 upgrade https://pastebin.com/raw/fisfxn76 /cfg/deps.lson /lib "..allium_version) @@ -102,14 +115,15 @@ term.clear() term.setCursorPos(1, 1) -- Running Allium -shell.run("allium.lua") +multishell.setTitle(multishell.getCurrent(), "Allium") +os.run(_ENV, "allium.lua", config) -- Removing all captures for _, side in pairs(peripheral.getNames()) do -- Finding the chat module if peripheral.getMethods(side) then for _, method in pairs(peripheral.getMethods(side)) do if method == "uncapture" then - peripheral.call(side, "uncapture", ".") + peripheral.call(side, "uncapture") break end end From 3d2ce8a7c5e2b9e29f612a1de1db8f5658acae7d Mon Sep 17 00:00:00 2001 From: roger109z Date: Tue, 22 Oct 2019 14:22:13 -0700 Subject: [PATCH 04/32] Added allium.register.loadConfig --- allium.lua | 102 +++++++++++++++++++++++++++++++++++++++++----------- startup.lua | 4 +-- 2 files changed, 83 insertions(+), 23 deletions(-) diff --git a/allium.lua b/allium.lua index 7bb1448..62b1160 100644 --- a/allium.lua +++ b/allium.lua @@ -28,15 +28,6 @@ local function print(noline, ...) -- Magical function that takes in a table and term.setTextColor(text_color) end -local function getData(name) -- Extract data on user from data command - local suc, data = commands.exec("data get entity "..name) - if not suc then return suc, data end - data = data[1]:sub(data[1]:find("{"), -1) - local data = mojson.parseList(data) - if not data then return false end - return data -end - local function deep_copy(table) -- Recursively copy a module out = {} for name, func in pairs(table) do @@ -59,18 +50,59 @@ local cli = { error = {true, "[", colors.red, "E", colors.white, "] "} } - -local config = ... +local config do -- Configuration parsing - if type(config) ~= "table" then - printError("Invalid input configuration, make sure you're using the provided init file.") + local file, default, rule = fs.open("cfg/allium.lson", "r"), {import_timeout = 5, label = "<&r&dAll&5&h[[Hugeblank was here. Hi.]]&i[[https://www.youtube.com/watch?v=hjGZLnja1o8]]i&r&dum&r> "} + local function verify_cfg(input, default, index) + for f_k, f_v in pairs(input) do -- input key, value + for t_k, t_v in pairs(default) do -- standard key, value + if type(f_v) == "table" and type(t_v) == "table" then + if not verify_cfg(f_v, t_v, f_k..".") then + return false + end + elseif f_k == t_k and type(f_v) ~= type(t_v) then + printError("Invalid config option "..(index or "")..f_k.." (expected "..type(t_v)..", got "..type(f_v)..")") + return false + end + end + end + return true + end + local function fill_missing(file, default) + local out = {} + for k, v in pairs(default) do + if type(v) == "table" then + out[k] = fill_missing(file[k], v) + else + if file[k] == nil then + out[k] = v + else + out[k] = file[k] + end + end + end + return out + end + if not file then -- Could not read file + printError("Could not read config") + return + end + local output = textutils.unserialise(file.readAll()) + if not output then -- Config file in invalid format + printError("Could not parse config") return end - allium.version, rule = semver.parse(config.version) + allium.version, rule = semver.parse(output.version) if not allium.version then -- Invalid Allium version printError("Could not parse Allium's version (breaks SemVer rule #"..rule..")") return end + output.version = nil + if verify_cfg(output, default) then -- Invalid configuration option (skips missing ones) + config = fill_missing(output, default) + else + return + end end do -- Allium image setup <3 @@ -128,8 +160,6 @@ allium.tell = function(name, message, alt_name) end allium.execute = function(name, command) - assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") - assert(type(command) == "string", "Invalid argument #2 (string expected, got "..type(command)..")") os.queueEvent("chat_capture", command, "execute", name) end @@ -150,9 +180,10 @@ allium.getPlayers = function() end allium.getPosition = function(name) - assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") - local data = allium.getData(name) - assert(data, "Failed to get data on user ".. name) + local suc, data = commands.exec("data get entity "..name) + if not suc then return false, data end + data = data[1]:sub(data[1]:find("{"), -1) + local data = mojson.parseList(data) return { position = data.Pos, rotation = data.Rotation, @@ -238,6 +269,38 @@ allium.register = function(p_name, version, fullname) return raisin.thread(thread, 0, group.thread) end + funcs.loadConfig = function(name, default) + assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") + assert(type(default) == "table", "Invalid argument #2 (table expected, got "..type(default)..")") + local file = shell.path().."/cfg/"..name + if not fs.exists(file) then + local setting = fs.open(file,"w") + setting.write(textutils.serialise(default)) + setting.close() + return default + end + local setting = fs.open(file, "r") + local config = setting.readAll() + setting.close() + config = textutils.unserialise(config) + if type(config) ~= "table" then + return default + end + local checkForKeys + checkForKeys = function(default, test) + for key, value in pairs(default) do + if not test[key] then + test[key] = value + elseif type(test[key]) == "table" then + checkForKeys(value, test[key]) + end + end + end + checkForKeys(default, config) + return config + end + + funcs.getPersistence = function(name) assert(type(name) ~= "nil", "Invalid argument #1 (expected anything but nil, got "..type(name)..")") if fs.exists("cfg/persistence.lson") then @@ -312,7 +375,6 @@ allium.register = function(p_name, version, fullname) end allium.verify = function(param) -- Verification code ripped from DepMan instance - assert(type(param) == "string", "Invalid argument #1 (string expected, got "..type(param)..")") local function convert(str) -- Use the semver API to convert. Provide a detailed error if conversion fails if type(str) ~= "string" then error("Could not convert "..tostring(str)) diff --git a/startup.lua b/startup.lua index 0b89d2b..973525e 100644 --- a/startup.lua +++ b/startup.lua @@ -1,5 +1,3 @@ -shell.openTab("shell") - -- Allium version local allium_version = "0.9.0-pr1" @@ -37,7 +35,7 @@ local loadSettings = function(file, default) local checkForKeys checkForKeys = function(default, test) for key, value in pairs(default) do - if not test[key] then + if type(test[key]) ~= type(value) then test[key] = value elseif type(test[key]) == "table" then checkForKeys(value, test[key]) From 43b2e5dfe84582461abfc6478416812ca4e15d9f Mon Sep 17 00:00:00 2001 From: roger109z Date: Tue, 22 Oct 2019 14:40:29 -0700 Subject: [PATCH 05/32] Fixed previous commit --- allium.lua | 70 ++++++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 50 deletions(-) diff --git a/allium.lua b/allium.lua index 62b1160..ec1c2c0 100644 --- a/allium.lua +++ b/allium.lua @@ -28,6 +28,15 @@ local function print(noline, ...) -- Magical function that takes in a table and term.setTextColor(text_color) end +local function getData(name) -- Extract data on user from data command + local suc, data = commands.exec("data get entity "..name) + if not suc then return suc, data end + data = data[1]:sub(data[1]:find("{"), -1) + local data = mojson.parseList(data) + if not data then return false end + return data +end + local function deep_copy(table) -- Recursively copy a module out = {} for name, func in pairs(table) do @@ -50,59 +59,18 @@ local cli = { error = {true, "[", colors.red, "E", colors.white, "] "} } -local config + +local config = ... do -- Configuration parsing - local file, default, rule = fs.open("cfg/allium.lson", "r"), {import_timeout = 5, label = "<&r&dAll&5&h[[Hugeblank was here. Hi.]]&i[[https://www.youtube.com/watch?v=hjGZLnja1o8]]i&r&dum&r> "} - local function verify_cfg(input, default, index) - for f_k, f_v in pairs(input) do -- input key, value - for t_k, t_v in pairs(default) do -- standard key, value - if type(f_v) == "table" and type(t_v) == "table" then - if not verify_cfg(f_v, t_v, f_k..".") then - return false - end - elseif f_k == t_k and type(f_v) ~= type(t_v) then - printError("Invalid config option "..(index or "")..f_k.." (expected "..type(t_v)..", got "..type(f_v)..")") - return false - end - end - end - return true - end - local function fill_missing(file, default) - local out = {} - for k, v in pairs(default) do - if type(v) == "table" then - out[k] = fill_missing(file[k], v) - else - if file[k] == nil then - out[k] = v - else - out[k] = file[k] - end - end - end - return out - end - if not file then -- Could not read file - printError("Could not read config") - return - end - local output = textutils.unserialise(file.readAll()) - if not output then -- Config file in invalid format - printError("Could not parse config") + if type(config) ~= "table" then + printError("Invalid input configuration, make sure you're using the provided init file.") return end - allium.version, rule = semver.parse(output.version) + allium.version, rule = semver.parse(config.version) if not allium.version then -- Invalid Allium version printError("Could not parse Allium's version (breaks SemVer rule #"..rule..")") return end - output.version = nil - if verify_cfg(output, default) then -- Invalid configuration option (skips missing ones) - config = fill_missing(output, default) - else - return - end end do -- Allium image setup <3 @@ -160,6 +128,8 @@ allium.tell = function(name, message, alt_name) end allium.execute = function(name, command) + assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") + assert(type(command) == "string", "Invalid argument #2 (string expected, got "..type(command)..")") os.queueEvent("chat_capture", command, "execute", name) end @@ -180,10 +150,9 @@ allium.getPlayers = function() end allium.getPosition = function(name) - local suc, data = commands.exec("data get entity "..name) - if not suc then return false, data end - data = data[1]:sub(data[1]:find("{"), -1) - local data = mojson.parseList(data) + assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") + local data = allium.getData(name) + assert(data, "Failed to get data on user ".. name) return { position = data.Pos, rotation = data.Rotation, @@ -375,6 +344,7 @@ allium.register = function(p_name, version, fullname) end allium.verify = function(param) -- Verification code ripped from DepMan instance + assert(type(param) == "string", "Invalid argument #1 (string expected, got "..type(param)..")") local function convert(str) -- Use the semver API to convert. Provide a detailed error if conversion fails if type(str) ~= "string" then error("Could not convert "..tostring(str)) From e8d393d4a9bac75ab145e7b674454a2bc994ecd8 Mon Sep 17 00:00:00 2001 From: roger109z Date: Tue, 22 Oct 2019 14:50:37 -0700 Subject: [PATCH 06/32] Fixed previous commit --- allium.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/allium.lua b/allium.lua index ec1c2c0..0b8af42 100644 --- a/allium.lua +++ b/allium.lua @@ -238,10 +238,9 @@ allium.register = function(p_name, version, fullname) return raisin.thread(thread, 0, group.thread) end - funcs.loadConfig = function(name, default) - assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") - assert(type(default) == "table", "Invalid argument #2 (table expected, got "..type(default)..")") - local file = shell.path().."/cfg/"..name + funcs.loadConfig = function(default) + assert(type(default) == "table", "Invalid argument #1 (table expected, got "..type(default)..")") + local file = shell.path().."/cfg/"..real_name if not fs.exists(file) then local setting = fs.open(file,"w") setting.write(textutils.serialise(default)) From 61d07cf1a1ee7e6f5fb35f619db1b643bbfd9e08 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Tue, 22 Oct 2019 15:22:05 -0700 Subject: [PATCH 07/32] Undo startup modifications --- startup.lua | 89 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 28 deletions(-) diff --git a/startup.lua b/startup.lua index 973525e..bf5932a 100644 --- a/startup.lua +++ b/startup.lua @@ -1,3 +1,5 @@ +shell.openTab("shell") + -- Allium version local allium_version = "0.9.0-pr1" @@ -6,6 +8,10 @@ if not commands then -- Attempt to prevent user from running this on non-command return end +--[[ + DEFAULT ALLIUM CONFIGS ### DO NOT CHANGE THESE ### + Configurations can be changed in /cfg/allium.lson +]] local default = { version = allium_version, -- Allium's version import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. @@ -16,38 +22,65 @@ local default = { } } ---load settings from file -local loadSettings = function(file, default) - assert(type(file) == "string", "file must be a string") - if not fs.exists(file) then - local setting = fs.open(file,"w") - setting.write(textutils.serialise(default)) - setting.close() - return default - end - local setting = fs.open(file, "r") - local config = setting.readAll() - setting.close() - config = textutils.unserialise(config) - if type(config) ~= "table" then - return default - end - local checkForKeys - checkForKeys = function(default, test) - for key, value in pairs(default) do - if type(test[key]) ~= type(value) then - test[key] = value - elseif type(test[key]) == "table" then - checkForKeys(value, test[key]) +local config = {} +do -- Configuration parsing + local file = fs.open("cfg/allium.lson", "r") + local function verify_cfg(input, default, index) + for givenField, givenValue in pairs(input) do -- input key, value + for expectedField, expectedValue in pairs(default) do -- standard key, value + if type(givenValue) == "table" and type(expectedValue) == "table" then + if not verify_cfg(givenValue, expectedValue, givenField..".") then + return false + end + elseif givenField == expectedField and type(givenValue) ~= type(expectedValue) then + printError("Invalid config option "..(index or "")..givenField.." (expected "..type(expectedValue)..", got "..type(givenValue)..")") + return false + end + end + end + return true + end + local function fill_missing(file, default) + local out = {} + if not file then file = {} end + for k, v in pairs(default) do + if type(v) == "table" then + out[k] = fill_missing(file[k], v) + else + if type(file[k]) == "nil" then + out[k] = v + else + out[k] = file[k] + end end end + for k, v in pairs(file) do + if out[k] == nil then + out[k] = v + end + end + return out end - checkForKeys(default, config) - return config + local output = {} + if file then -- Could not read file + output = textutils.unserialise(file.readAll()) or {} + file.close() + end + if verify_cfg(output, default) then -- Make sure none of the config opts are invalid (skips missing ones) + config = fill_missing(output, default) -- Fill in the remaining options that are missing + if config.version ~= allium_version then + config.version = allium_version + file = fs.open("cfg/allium.lson", "w") + if file then + file.write(textutils.serialise(config)) + file.close() + end + end + else + return + end end -config = loadSettings("cfg/allium.lson", default) - -- Checking Allium/Plugin updates if config.updates.allium then if fs.exists("cfg/repolist.csh") then -- Checking for a repolist shell executable @@ -59,7 +92,7 @@ if config.updates.allium then end -- Filling Dependencies -if config.updates.dependencies then +if config.updates.deps then -- Allium DepMan Instance: https://pastebin.com/nRgBd3b6 print("Checking for dependency updates...") local didrun = false From 5aa3f17e3e6394808a9c8af908e1cac3c44ef581 Mon Sep 17 00:00:00 2001 From: roger109z Date: Tue, 22 Oct 2019 15:38:41 -0700 Subject: [PATCH 08/32] Didn't do anything here don't worry about it --- startup.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/startup.lua b/startup.lua index 973525e..4a229e4 100644 --- a/startup.lua +++ b/startup.lua @@ -9,7 +9,7 @@ end local default = { version = allium_version, -- Allium's version import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. - label = "<&r&dAll&5&h[[Hugeblank was here. Hi.]]&i[[https://www.youtube.com/watch?v=hjGZLnja1o8]]i&r&dum&r> ", -- The label the loader uses + label = "<&r&dAll&5&h[[Killroy wuz here.]]&i[[https://www.youtube.com/watch?v=XqZsoesa55w&t=15s]]i&r&dum&r> ", -- The label the loader uses updates = { -- Various auto-update configurations. Server operators may want to change this from the default deps = true, -- Automatically update dependencies allium = true -- Automatically update allium From ba46eb378919ba3edc40773c46ef3ea0c46bacc3 Mon Sep 17 00:00:00 2001 From: roger109z Date: Tue, 22 Oct 2019 15:42:36 -0700 Subject: [PATCH 09/32] fixed huges screw-up --- startup.lua | 89 +++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 61 deletions(-) diff --git a/startup.lua b/startup.lua index 643cb2a..4a229e4 100644 --- a/startup.lua +++ b/startup.lua @@ -1,5 +1,3 @@ -shell.openTab("shell") - -- Allium version local allium_version = "0.9.0-pr1" @@ -8,10 +6,6 @@ if not commands then -- Attempt to prevent user from running this on non-command return end ---[[ - DEFAULT ALLIUM CONFIGS ### DO NOT CHANGE THESE ### - Configurations can be changed in /cfg/allium.lson -]] local default = { version = allium_version, -- Allium's version import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. @@ -22,65 +16,38 @@ local default = { } } -local config = {} -do -- Configuration parsing - local file = fs.open("cfg/allium.lson", "r") - local function verify_cfg(input, default, index) - for givenField, givenValue in pairs(input) do -- input key, value - for expectedField, expectedValue in pairs(default) do -- standard key, value - if type(givenValue) == "table" and type(expectedValue) == "table" then - if not verify_cfg(givenValue, expectedValue, givenField..".") then - return false - end - elseif givenField == expectedField and type(givenValue) ~= type(expectedValue) then - printError("Invalid config option "..(index or "")..givenField.." (expected "..type(expectedValue)..", got "..type(givenValue)..")") - return false - end - end - end - return true - end - local function fill_missing(file, default) - local out = {} - if not file then file = {} end - for k, v in pairs(default) do - if type(v) == "table" then - out[k] = fill_missing(file[k], v) - else - if type(file[k]) == "nil" then - out[k] = v - else - out[k] = file[k] - end - end - end - for k, v in pairs(file) do - if out[k] == nil then - out[k] = v - end - end - return out +--load settings from file +local loadSettings = function(file, default) + assert(type(file) == "string", "file must be a string") + if not fs.exists(file) then + local setting = fs.open(file,"w") + setting.write(textutils.serialise(default)) + setting.close() + return default + end + local setting = fs.open(file, "r") + local config = setting.readAll() + setting.close() + config = textutils.unserialise(config) + if type(config) ~= "table" then + return default end - local output = {} - if file then -- Could not read file - output = textutils.unserialise(file.readAll()) or {} - file.close() - end - if verify_cfg(output, default) then -- Make sure none of the config opts are invalid (skips missing ones) - config = fill_missing(output, default) -- Fill in the remaining options that are missing - if config.version ~= allium_version then - config.version = allium_version - file = fs.open("cfg/allium.lson", "w") - if file then - file.write(textutils.serialise(config)) - file.close() + local checkForKeys + checkForKeys = function(default, test) + for key, value in pairs(default) do + if type(test[key]) ~= type(value) then + test[key] = value + elseif type(test[key]) == "table" then + checkForKeys(value, test[key]) end end - else - return - end + end + checkForKeys(default, config) + return config end +config = loadSettings("cfg/allium.lson", default) + -- Checking Allium/Plugin updates if config.updates.allium then if fs.exists("cfg/repolist.csh") then -- Checking for a repolist shell executable @@ -92,7 +59,7 @@ if config.updates.allium then end -- Filling Dependencies -if config.updates.deps then +if config.updates.dependencies then -- Allium DepMan Instance: https://pastebin.com/nRgBd3b6 print("Checking for dependency updates...") local didrun = false From 1466cbb9763112fd26cfb96e1343a29087f6b6e3 Mon Sep 17 00:00:00 2001 From: roger109z Date: Tue, 22 Oct 2019 15:44:18 -0700 Subject: [PATCH 10/32] added a comment back --- startup.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/startup.lua b/startup.lua index 4a229e4..a3bfff0 100644 --- a/startup.lua +++ b/startup.lua @@ -6,6 +6,11 @@ if not commands then -- Attempt to prevent user from running this on non-command return end + +--[[ + DEFAULT ALLIUM CONFIGS ### DO NOT CHANGE THESE ### + Configurations can be changed in /cfg/allium.lson +]] local default = { version = allium_version, -- Allium's version import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. From d4df18424f8657d606e60d50e2947f25b4a3848c Mon Sep 17 00:00:00 2001 From: roger109z Date: Wed, 23 Oct 2019 10:46:39 -0700 Subject: [PATCH 11/32] added .lson extension to config files --- allium.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/allium.lua b/allium.lua index 0b8af42..cbf0ed3 100644 --- a/allium.lua +++ b/allium.lua @@ -240,7 +240,7 @@ allium.register = function(p_name, version, fullname) funcs.loadConfig = function(default) assert(type(default) == "table", "Invalid argument #1 (table expected, got "..type(default)..")") - local file = shell.path().."/cfg/"..real_name + local file = shell.path().."/cfg/"..real_name..".lson" if not fs.exists(file) then local setting = fs.open(file,"w") setting.write(textutils.serialise(default)) From 8550b3c2c9a8de2e98cb5f35d29fc0d071d5b7d4 Mon Sep 17 00:00:00 2001 From: roger109z Date: Wed, 23 Oct 2019 12:02:48 -0700 Subject: [PATCH 12/32] fixed improper path in loadConfig --- allium.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/allium.lua b/allium.lua index cbf0ed3..57648dc 100644 --- a/allium.lua +++ b/allium.lua @@ -5,7 +5,10 @@ local raisin, color, semver, mojson = require("lib.raisin"), require("lib.color" -- Internal definitions local allium, plugins, group = {}, {}, {thread = raisin.group(1) , command = raisin.group(2)} - +local path = "" +for str in string.gmatch(shell.getRunningProgram(), ".+[/]") do + path = path..str +end local function print(noline, ...) -- Magical function that takes in a table and changes the text color/writes at the same time local words = {...} if type(noline) ~= "boolean" then @@ -240,7 +243,7 @@ allium.register = function(p_name, version, fullname) funcs.loadConfig = function(default) assert(type(default) == "table", "Invalid argument #1 (table expected, got "..type(default)..")") - local file = shell.path().."/cfg/"..real_name..".lson" + local file = path.."/cfg/"..real_name..".lson" if not fs.exists(file) then local setting = fs.open(file,"w") setting.write(textutils.serialise(default)) From 1987a77f0729be9ff39207adbf0972990627f897 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Wed, 23 Oct 2019 15:17:35 -0700 Subject: [PATCH 13/32] Minor code cleanup --- .gitignore | 1 + allium.lua | 9 +++++---- startup.lua | 9 +++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 8195780..45803c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ lib/* cfg/* .DS_Store +.vscode \ No newline at end of file diff --git a/allium.lua b/allium.lua index 0b8af42..485c77f 100644 --- a/allium.lua +++ b/allium.lua @@ -38,7 +38,7 @@ local function getData(name) -- Extract data on user from data command end local function deep_copy(table) -- Recursively copy a module - out = {} + local out = {} for name, func in pairs(table) do if type(func) == "table" then out[name] = deep_copy(func) @@ -66,7 +66,8 @@ do -- Configuration parsing printError("Invalid input configuration, make sure you're using the provided init file.") return end - allium.version, rule = semver.parse(config.version) + local ver, rule = semver.parse(config.version) + allium.version = ver if not allium.version then -- Invalid Allium version printError("Could not parse Allium's version (breaks SemVer rule #"..rule..")") return @@ -151,7 +152,7 @@ end allium.getPosition = function(name) assert(type(name) == "string", "Invalid argument #1 (string expected, got "..type(name)..")") - local data = allium.getData(name) + local data = getData(name) assert(data, "Failed to get data on user ".. name) return { position = data.Pos, @@ -471,7 +472,7 @@ local interpreter = function() -- Main command interpretation thread while true do local _, message, _, name, uuid = os.pullEvent("chat_capture") -- Pull chat messages if message:find("!") == 1 then -- Are they for allium? - args = {} + local args = {} for k in message:gmatch("%S+") do -- Put all arguments spaced out into a table args[#args+1] = k end diff --git a/startup.lua b/startup.lua index a3bfff0..544d99b 100644 --- a/startup.lua +++ b/startup.lua @@ -1,5 +1,6 @@ -- Allium version -local allium_version = "0.9.0-pr1" +-- x.x.x-pr = unstable, potential breaking changes +local allium_version = "0.9.0-pr" if not commands then -- Attempt to prevent user from running this on non-command comps printError("Allium must be run on a command computer") @@ -23,7 +24,7 @@ local default = { --load settings from file local loadSettings = function(file, default) - assert(type(file) == "string", "file must be a string") + assert(type(file) == "string", "file must be a string") if not fs.exists(file) then local setting = fs.open(file,"w") setting.write(textutils.serialise(default)) @@ -51,7 +52,7 @@ local loadSettings = function(file, default) return config end -config = loadSettings("cfg/allium.lson", default) +local config = loadSettings("cfg/allium.lson", default) -- Checking Allium/Plugin updates if config.updates.allium then @@ -70,7 +71,7 @@ if config.updates.dependencies then local didrun = false parallel.waitForAll(function() didrun = shell.run("pastebin run nRgBd3b6 upgrade https://pastebin.com/raw/fisfxn76 /cfg/deps.lson /lib "..allium_version) - end, + end, function() multishell.setTitle(multishell.getCurrent(), "depman") end) From c1e69535fbbfb92046e107e4dfe9ea2daafd412e Mon Sep 17 00:00:00 2001 From: hugeblank Date: Wed, 23 Oct 2019 15:18:42 -0700 Subject: [PATCH 14/32] Fix plugin import issues The entire system was just incomplete. I don't know how I missed it for so long. --- allium.lua | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/allium.lua b/allium.lua index 485c77f..5eff4a3 100644 --- a/allium.lua +++ b/allium.lua @@ -218,7 +218,8 @@ allium.register = function(p_name, version, fullname) assert(plugins[real_name] == nil, "Invalid argument #1 (plugin exists under name "..real_name..")") local version, rule = semver.parse(version) assert(type(version) == "table", "Invalid argument #2 (malformed SemVer, breaks rule "..(rule or "")..")") - plugins[real_name] = {commands = {}, name = fullname or p_name, version = version} + local loaded = {} + plugins[real_name] = {commands = {}, loaded = loaded, name = fullname or p_name, version = version} local funcs, this = {}, plugins[real_name] funcs.command = function(c_name, command, info) -- name: name | command: executing function | info: help information @@ -315,28 +316,26 @@ allium.register = function(p_name, version, fullname) funcs.import = function(p_name) -- request the API from a specific plugin assert(type(p_name) == "string", "Invalid argument #1 (string expected, got "..type(p_name)..")") p_name = allium.sanitize(p_name) + assert(p_name == real_name, real_name.." attempted to load self. What made you think you could do this?") local timer = os.startTimer(config.import_timeout or 5) - repeat - local e = {os.pullEvent()} - until (e[1] == "timer" and e[2] == timer) or (plugins[p_name] and plugins[p_name].module) - if not plugins[p_name] and plugins[p_name].module then + parallel.waitForAny(function() + repeat + local e = {os.pullEvent()} + until (e[1] == "timer" and e[2] == timer) or (plugins[p_name] and plugins[p_name].module) + end, function() + repeat + sleep() + until plugins[p_name].module + end) + if not plugins[p_name].module then return false end - for being_loaded, loaded_plugins in pairs(loaded) do -- Plugin being loaded, plugins that the plugin being loaded has loaded - if being_loaded == p_name then - for i = 1, #loaded_plugins do - if loaded_plugins[i] == real_name then - return false - end - end - break + for i = 1, #plugins[p_name].loaded do + if plugins[p_name].loaded[i] == real_name then + error("Cannot import "..p_name.."Circular dependencies with "..real_name.." and "..plugins[p_name].loaded[i]) end end - if loaded[real_name] then - loaded[real_name][#loaded[real_name]+1] = p_name - else - loaded[real_name] = {p_name} - end + loaded[#loaded+1] = p_name return deep_copy(plugins[p_name].module) end From 63509416aad99f276c5001da1b8830d2760b9ad8 Mon Sep 17 00:00:00 2001 From: roger109z Date: Wed, 23 Oct 2019 15:20:58 -0700 Subject: [PATCH 15/32] unabsoluted paths --- allium.lua | 17 ++++++++--------- startup.lua | 17 +++++++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/allium.lua b/allium.lua index 57648dc..1a72c1e 100644 --- a/allium.lua +++ b/allium.lua @@ -5,7 +5,7 @@ local raisin, color, semver, mojson = require("lib.raisin"), require("lib.color" -- Internal definitions local allium, plugins, group = {}, {}, {thread = raisin.group(1) , command = raisin.group(2)} -local path = "" +local path = "/" for str in string.gmatch(shell.getRunningProgram(), ".+[/]") do path = path..str end @@ -274,8 +274,8 @@ allium.register = function(p_name, version, fullname) funcs.getPersistence = function(name) assert(type(name) ~= "nil", "Invalid argument #1 (expected anything but nil, got "..type(name)..")") - if fs.exists("cfg/persistence.lson") then - local fper = fs.open("cfg/persistence.lson", "r") + if fs.exists(path.."cfg/persistence.lson") then + local fper = fs.open(path.."cfg/persistence.lson", "r") local tpersist = textutils.unserialize(fper.readAll()) fper.close() if not tpersist[real_name] then @@ -296,7 +296,7 @@ allium.register = function(p_name, version, fullname) end if type(name) == "string" then tpersist[real_name][name] = data - local fpers = fs.open("cfg/persistence.lson", "w") + local fpers = fs.open(path.."cfg/persistence.lson", "w") if not fpers then return false end @@ -444,9 +444,8 @@ do -- Plugin loading process end end end - local dir = shell.dir() - if fs.exists(dir.."/plugins") then - scopeDown(dir.."/plugins") + if fs.exists(path.."/plugins") then + scopeDown(path.."/plugins") end raisin.manager.runGroup(loader_group) end @@ -596,8 +595,8 @@ end raisin.thread(interpreter, 0) raisin.thread(scanner, 1) -if not fs.exists("cfg/persistence.lson") then --In the situation that this is a first installation, let's do some setup - local fpers = fs.open("cfg/persistence.lson", "w") +if not fs.exists(path.."cfg/persistence.lson") then --In the situation that this is a first installation, let's do some setup + local fpers = fs.open(path.."cfg/persistence.lson", "w") fpers.write("{}") fpers.close() end diff --git a/startup.lua b/startup.lua index a3bfff0..fa48af3 100644 --- a/startup.lua +++ b/startup.lua @@ -1,6 +1,11 @@ -- Allium version local allium_version = "0.9.0-pr1" +local path = "/" +for str in string.gmatch(shell.getRunningProgram(), ".+[/]") do + path = path..str +end + if not commands then -- Attempt to prevent user from running this on non-command comps printError("Allium must be run on a command computer") return @@ -51,14 +56,14 @@ local loadSettings = function(file, default) return config end -config = loadSettings("cfg/allium.lson", default) +config = loadSettings(path.."cfg/allium.lson", default) -- Checking Allium/Plugin updates if config.updates.allium then - if fs.exists("cfg/repolist.csh") then -- Checking for a repolist shell executable + if fs.exists(path.."cfg/repolist.csh") then -- Checking for a repolist shell executable -- Update all plugins and programs on the repolist - for line in io.lines("cfg/repolist.csh") do - shell.run(line) + for line in io.lines(path.."cfg/repolist.csh") do + shell.run(path..line) end end end @@ -69,7 +74,7 @@ if config.updates.dependencies then print("Checking for dependency updates...") local didrun = false parallel.waitForAll(function() - didrun = shell.run("pastebin run nRgBd3b6 upgrade https://pastebin.com/raw/fisfxn76 /cfg/deps.lson /lib "..allium_version) + didrun = shell.run("pastebin run nRgBd3b6 upgrade "..path.." https://pastebin.com/raw/fisfxn76 "..path.."/cfg/deps.lson "..path.."/lib "..allium_version) end, function() multishell.setTitle(multishell.getCurrent(), "depman") @@ -88,7 +93,7 @@ term.setCursorPos(1, 1) -- Running Allium multishell.setTitle(multishell.getCurrent(), "Allium") -os.run(_ENV, "allium.lua", config) +os.run(_ENV, path.."allium.lua", config) -- Removing all captures for _, side in pairs(peripheral.getNames()) do -- Finding the chat module From daac8d69784087f326b75d22798bd7c3f878e854 Mon Sep 17 00:00:00 2001 From: roger109z Date: Wed, 23 Oct 2019 16:18:32 -0700 Subject: [PATCH 16/32] Fixed label --- startup.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/startup.lua b/startup.lua index fa48af3..0891683 100644 --- a/startup.lua +++ b/startup.lua @@ -19,7 +19,7 @@ end local default = { version = allium_version, -- Allium's version import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. - label = "<&r&dAll&5&h[[Killroy wuz here.]]&i[[https://www.youtube.com/watch?v=XqZsoesa55w&t=15s]]i&r&dum&r> ", -- The label the loader uses + label = "<&r&dAll&5&h[[Killroy wuz here.]]&i[[https://www.youtube.com/watch?v=XqZsoesa55w\\&t=15s]]i&r&dum&r> ", -- The label the loader uses updates = { -- Various auto-update configurations. Server operators may want to change this from the default deps = true, -- Automatically update dependencies allium = true -- Automatically update allium From 282c1eee5752beb47364246b4a5dc456efe8c832 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Wed, 23 Oct 2019 16:46:30 -0700 Subject: [PATCH 17/32] Redirect depman Untested and probably will fail --- startup.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/startup.lua b/startup.lua index f22aa1d..d77ceee 100644 --- a/startup.lua +++ b/startup.lua @@ -12,7 +12,6 @@ if not commands then -- Attempt to prevent user from running this on non-command return end - --[[ DEFAULT ALLIUM CONFIGS ### DO NOT CHANGE THESE ### Configurations can be changed in /cfg/allium.lson @@ -71,14 +70,18 @@ end -- Filling Dependencies if config.updates.dependencies then - -- Allium DepMan Instance: https://pastebin.com/nRgBd3b6 + -- Allium DepMan Instance & Listing: https://github.com/hugeblank/allium-depman/ print("Checking for dependency updates...") local didrun = false parallel.waitForAll(function() - didrun = shell.run("pastebin run nRgBd3b6 upgrade "..path.." https://pastebin.com/raw/fisfxn76 "..path.."/cfg/deps.lson "..path.."/lib "..allium_version) - end, - - function() + local ipath = path.."instance.lua" + if fs.exists(ipath) then + fs.delete(ipath) + end + didrun = shell.run("wget https://raw.githubusercontent.com/hugeblank/allium-depman/master/instance.lua "..ipath) + if not didrun then return end + didrun = shell.run(ipath.." upgrade "..path.." https://raw.githubusercontent.com/hugeblank/allium-depman/master/listing.lson "..path.."/cfg/deps.lson "..path.."/lib "..allium_version) + end, function() multishell.setTitle(multishell.getCurrent(), "depman") end) if not didrun then From c7a87f1db2fe4c53ac00ff2a5713e6ea1ca746b9 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Wed, 23 Oct 2019 16:58:51 -0700 Subject: [PATCH 18/32] Fix version getting overwritten in config --- startup.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/startup.lua b/startup.lua index d77ceee..d0bf661 100644 --- a/startup.lua +++ b/startup.lua @@ -30,9 +30,11 @@ local default = { local loadSettings = function(file, default) assert(type(file) == "string", "file must be a string") if not fs.exists(file) then - local setting = fs.open(file,"w") + local setting, v = fs.open(file,"w"), default.version + default.version = nil setting.write(textutils.serialise(default)) setting.close() + default.version = v return default end local setting = fs.open(file, "r") From 593fde3dbc0bffe495b3f789455eda9c7b2bd9d8 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Thu, 24 Oct 2019 00:30:35 -0700 Subject: [PATCH 19/32] deps ~= dependencies duh --- startup.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/startup.lua b/startup.lua index d0bf661..f439156 100644 --- a/startup.lua +++ b/startup.lua @@ -18,10 +18,10 @@ end ]] local default = { version = allium_version, -- Allium's version - import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. label = "<&r&dAll&5&h[[Killroy wuz here.]]&i[[https://www.youtube.com/watch?v=XqZsoesa55w\\&t=15s]]i&r&dum&r> ", -- The label the loader uses + import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. updates = { -- Various auto-update configurations. Server operators may want to change this from the default - deps = true, -- Automatically update dependencies + dependencies = true, -- Automatically update dependencies allium = true -- Automatically update allium } } From 7c73b3a9b49dcec24dbbf4487686c552145e7195 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Thu, 24 Oct 2019 02:15:16 -0700 Subject: [PATCH 20/32] Logging methods - added allium.log/warn so that you can warn using the fancy system. You're welcome. - Reworked print function because it had to be done --- allium.lua | 74 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/allium.lua b/allium.lua index f13fe52..0b8df9c 100644 --- a/allium.lua +++ b/allium.lua @@ -4,31 +4,35 @@ local raisin, color, semver, mojson = require("lib.raisin"), require("lib.color"), require("lib.semver"), require("lib.mojson") -- Internal definitions -local allium, plugins, group = {}, {}, {thread = raisin.group(1) , command = raisin.group(2)} +local allium, plugins, group = {}, {}, {thread = raisin.group(1) , command = raisin.group(2)} + +-- Executing path local path = "/" for str in string.gmatch(shell.getRunningProgram(), ".+[/]") do path = path..str end -local function print(noline, ...) -- Magical function that takes in a table and changes the text color/writes at the same time - local words = {...} - if type(noline) ~= "boolean" then - table.insert(words, 1, noline) - noline = false - end - local text_color = term.getTextColor() - for i = 1, #words do - if type(words[i]) == "number" then - term.setTextColor(words[i]) - elseif type(words[i]) == "table" then - print(unpack(words[i])) - else - write(tostring(words[i])) + +-- Defining custom print +local nprint = _G.print +local function print(prefix, wcText, ...) -- Magical function that takes in a table and changes the text color/writes at the same time + local color = term.getTextColor() + local function writeColor(cdata) + for i = 1, #cdata do + if type(cdata[i]) == "string" then + write(cdata[i]) + else + term.setTextColor(cdata[i]) + end end + term.setTextColor(color) end - if not noline then - write("\n") + writeColor(prefix) + if wcText then + writeColor({...}) + nprint() + else + nprint(...) end - term.setTextColor(text_color) end local function getData(name) -- Extract data on user from data command @@ -57,9 +61,9 @@ local function assert(condition, message, level) end local cli = { - info = {true, "[", colors.lime, "I", colors.white, "] "}, - warn = {true, "[", colors.yellow, "W", colors.white, "] "}, - error = {true, "[", colors.red, "E", colors.white, "] "} + info = {"[", colors.lime, "I", colors.white, "] "}, + warn = {"[", colors.yellow, "W", colors.white, "] "}, + error = {"[", colors.red, "E", colors.white, "] "} } @@ -107,8 +111,8 @@ do -- Allium image setup <3 term.setCursorPos(1, 1) term.setBackgroundColor(colors.black) -- Reset terminal and cursor term.setTextColor(colors.white) - print(cli.info, "Loading ", colors.magenta, "All", colors.purple, "i", colors.magenta, "um") - print(cli.info, "Initializing API") + print(cli.info, true, "Loading ", colors.magenta, "All", colors.purple, "i", colors.magenta, "um") + print(cli.info, false, "Initializing API") end allium.assert = assert @@ -118,6 +122,14 @@ allium.sanitize = function(name) return name:lower():gsub(" ", "_"):gsub("[^a-z0-9_]", "") end +allium.log = function(...) + print(cli.info, false, ...) +end + +allium.warn = function(...) + print(cli.warn, false, ...) +end + allium.tell = function(name, message, alt_name) assert(type(name) == "string", "Invalid argument #1 (expected string, got "..type(name)..")") assert(type(message) == "string" or type(message) == "table", "Invalid argument #2 (expected string or table, got "..type(message)..")") @@ -408,7 +420,7 @@ for _, side in pairs(peripheral.getNames()) do -- Finding the chat module if allium.side then break end end if not allium.side then - print(cli.warn, "Allium could not find chat module") + print(cli.warn, false, "Allium could not find chat module") end -- Packaging the Allium API @@ -417,24 +429,24 @@ if not package.preload["allium"] then return allium end else - print(cli.error, "Another instance of Allium is already running") + print(cli.error, false, "Another instance of Allium is already running") return end do -- Plugin loading process - print(cli.info, "Loading plugins") + print(cli.info, false, "Loading plugins") local loader_group = raisin.group(1) local function scopeDown(dir) for _, plugin in pairs(fs.list(dir)) do if (not fs.isDir(dir.."/"..plugin)) and plugin:find(".lua") then local file, err = loadfile(dir.."/"..plugin, _ENV) if not file then - print(cli.error, err) + print(cli.error, false, err) else local thread = function() local suc, err = pcall(file) if not suc then - print(cli.error, err) + print(cli.error, false, err) end end raisin.thread(thread, 0, loader_group) @@ -554,7 +566,7 @@ local interpreter = function() -- Main command interpretation thread "&4!"..cmd_exec.command.." crashed! This is likely not your fault, but the developer's. Please contact the developer of &a"..cmd_exec.plugin.."&4. Error:", "&c&h[[Click here to place error into chat prompt, so you may copy it if needed for an issue report]]&s[["..err.."]]"..err.."&r" }) - print(cli.warn, cmd.." | "..err) + print(cli.warn, false, cmd.." | "..err) end end raisin.thread(exec_command, 0, group.command) @@ -587,7 +599,7 @@ local scanner = function() -- Login/out scanner thread end end else - print(cli.warn, "Could not list online players, skipping tick.") + print(cli.warn, false, "Could not list online players, skipping tick.") end end end @@ -601,7 +613,7 @@ if not fs.exists(path.."cfg/persistence.lson") then --In the situation that this fpers.close() end -print(cli.info, "Allium started.") +print(cli.info, false, "Allium started.") allium.tell("@a", "&eHello World!") raisin.manager.run() From 17e9de006a538e2d63df453870bb35c72289da06 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Thu, 24 Oct 2019 02:31:55 -0700 Subject: [PATCH 21/32] Modify depman downloading Stopped it from being saved on disk --- startup.lua | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/startup.lua b/startup.lua index f439156..b946371 100644 --- a/startup.lua +++ b/startup.lua @@ -74,20 +74,13 @@ end if config.updates.dependencies then -- Allium DepMan Instance & Listing: https://github.com/hugeblank/allium-depman/ print("Checking for dependency updates...") - local didrun = false - parallel.waitForAll(function() - local ipath = path.."instance.lua" - if fs.exists(ipath) then - fs.delete(ipath) - end - didrun = shell.run("wget https://raw.githubusercontent.com/hugeblank/allium-depman/master/instance.lua "..ipath) - if not didrun then return end - didrun = shell.run(ipath.." upgrade "..path.." https://raw.githubusercontent.com/hugeblank/allium-depman/master/listing.lson "..path.."/cfg/deps.lson "..path.."/lib "..allium_version) - end, function() - multishell.setTitle(multishell.getCurrent(), "depman") - end) + local didrun, err + didrun = http.get("https://raw.githubusercontent.com/hugeblank/allium-depman/master/instance.lua") + if didrun then + didrun, err = pcall(load(didrun.readAll(), "Depman", nil, _ENV), "upgrade", path, "https://raw.githubusercontent.com/hugeblank/allium-depman/master/listing.lson", path.."/cfg/deps.lson", path.."/lib", allium_version) + end if not didrun then - printError("Could not update dependencies") + printError("Could not update dependencies: "..(err or "Failed to download instance")) return end end From d4f3f6ceda1fab5e4c9141cd43d06f4b4c173446 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Thu, 24 Oct 2019 02:34:23 -0700 Subject: [PATCH 22/32] Update allium-stem plugin - Added 'position_x/y/z' infill - Brought parsing block into help command as a result --- plugins/allium-stem.lua | 221 +++++++++++++++++++++------------------- 1 file changed, 117 insertions(+), 104 deletions(-) diff --git a/plugins/allium-stem.lua b/plugins/allium-stem.lua index 9c48a59..e569d18 100644 --- a/plugins/allium-stem.lua +++ b/plugins/allium-stem.lua @@ -1,121 +1,133 @@ local allium = require("allium") -local stem = allium.register("allium", "0.4.2", "Allium Stem") -local addDetails -do -- Just a block for organization of command parsing stuffs - local function infill(variant, execute) - local out = {} - if variant == "username" then - local players = allium.getPlayers() - for i = 1, #players do - out[#out+1] = " &6-&r &g[["..execute..players[i].." ]]&h[[Click to add user "..players[i].."]]&a"..players[i] - end - elseif variant == "plugin" then - local list = allium.getInfo() - for plugin in pairs(list) do - out[#out+1] = " &6-&r &g[["..execute..plugin.." ]]&h[[Click to add plugin "..plugin.."]]&a"..plugin - end - elseif variant == "command" then - local list = allium.getInfo() - for plugin, v in pairs(list) do - for command in pairs(v) do - local rawcmd = command - local command = plugin..":"..command - out[#out+1] = " &6-&r &g[["..execute..command.." ]]&h[[Click to add command !"..rawcmd.."]]&a!"..command +local stem = allium.register("allium", "0.5.0", "Allium Stem") --UPDATE THIS + +local help = function(name, args, data) + local cmds_per, page = 8, 1 -- Turn this into a per-user persistence preference + local info = {} + local out_str = "" + local addDetails + local next_command = "!allium:help " + + do -- Just a block for organization of command parsing stuffs + local function infill(variant, execute) + local out = {} + if type(variant) == "string" then + if variant == "username" then + local players = allium.getPlayers() + for i = 1, #players do + out[#out+1] = " &6-&r &g[["..execute..players[i].." ]]&h[[Click to add user "..players[i].."]]&a"..players[i] + end + elseif variant == "plugin" then + local list = allium.getInfo() + for plugin in pairs(list) do + out[#out+1] = " &6-&r &g[["..execute..plugin.." ]]&h[[Click to add plugin "..plugin.."]]&a"..plugin + end + elseif variant == "command" then + local list = allium.getInfo() + for plugin, v in pairs(list) do + for command in pairs(v) do + local rawcmd = command + local command = plugin..":"..command + out[#out+1] = " &6-&r &g[["..execute..command.." ]]&h[[Click to add command !"..rawcmd.."]]&a!"..command + end + end + elseif variant:sub(1, -2) == "position_" then + local position = allium.getPosition(name).position + if variant:sub(-1, -1) == "x" then + out[#out+1] = " &6-&r &g[["..execute..position[1].." ]]&h[[Click to add your x position]]&a"..position[1] + elseif variant:sub(-1, -1) == "y" then + out[#out+1] = " &6-&r &g[["..execute..position[2].." ]]&h[[Click to add your y position]]&a"..position[2] + elseif variant:sub(-1, -1) == "z" then + out[#out+1] = " &6-&r &g[["..execute..position[3].." ]]&h[[Click to add your z position]]&a"..position[3] + end + end + elseif type(variant) == "function" or type(variant) == "table" then + local result = {} + if type(variant) == "function" then + result = variant() + else + result = variant + end + for i = 1, #result do + if type(result[i]) == "string" and not result[i]:find("=") then + out[#out+1] = " &6-&r &g[["..execute..result[i].." ]]&h[[Click to add "..result[i].."]]&a"..result[i] + end end end - elseif type(variant) == "function" or type(variant) == "table" then - local result = {} - if type(variant) == "function" then - result = variant() + return out + end + + local function parse(label, data, execute) + local prefix, postfix, execution, hover, information = "&6 - &r<&a", "&r>:", "", "" + if type(data[1]) == "string" then + information = data[1] else - result = variant + information = "&oNo information found" + end + if data.optional == true then + prefix, postfix = "&6 - &r[&a", "&r]:" end - for i = 1, #result do - if type(result[i]) == "string" and not result[i]:find("=") then - out[#out+1] = " &6-&r &g[["..execute..result[i].." ]]&h[[Click to add "..result[i].."]]&a"..result[i] + if data.clickable == true or data.clickable == nil then + hover, execution = "Click to add this parameter", execute..label + if type(data.infill) == "string" then + execution = execution.."=" end end - end - return out - end - - local function parse(label, data, execute) - local prefix, postfix, execution, hover, information = "&6 - &r<&a", "&r>:", "", "" - if type(data[1]) == "string" then - information = data[1] - else - information = "&oNo information found" - end - if data.optional == true then - prefix, postfix = "&6 - &r[&a", "&r]:" - end - if data.clickable == true or data.clickable == nil then - hover, execution = "Click to add this parameter", execute..label - if type(data.infill) == "string" then - execution = execution.."=" + if data.default and tostring(data.default) then -- Overrides infill. default and infill shouldn't even be used in the same place anyways. + execution = execute..label.."=\"\""..data.default.."\"\"" -- Quoting a quote so it gets placed in chat properly end + local meta = "" + if #execution ~= 0 then + meta = meta.."&g[["..execution.."]]" + end + if #hover ~= 0 then + meta = meta.."&h[["..hover.."]]" + end + return prefix..meta..label..postfix.." "..information end - if data.default and tostring(data.default) then -- Overrides infill. default and infill shouldn't even be used in the same place anyways. - execution = execute..label.."=\"\""..data.default.."\"\"" -- Quoting a quote so it gets placed in chat properly - end - local meta = "" - if #execution ~= 0 then - meta = meta.."&g[["..execution.."]]" - end - if #hover ~= 0 then - meta = meta.."&h[["..hover.."]]" - end - return prefix..meta..label..postfix.." "..information - end - addDetails = function(info, args, execute, command) - if not args[1] then - -- We're at the end of parsing and should render possible fields - local out = {} - if info then - for k, v in pairs(info) do - if type(v) == "table" then - out[#out+1] = parse(k, v, execute) + addDetails = function(info, args, execute, command) + if not args[1] then --or info then + -- We're at the end of parsing and should render possible fields + local out = {} + if info then + for k, v in pairs(info) do + if type(v) == "table" then + out[#out+1] = parse(k, v, execute) + end end end + if #out == 0 or not info then + out = {" &6-&a No more parameters to add!", " &6-&a Click &r&c&h[[Click to run command]]&g[["..command.."]]here&r&a to run the command", " &6- &eOR&a click on the first line to add the command to the chat input."} + end + return out, command + else -- Otherwise things are going totally as planned and we should just recurse onwards + local param_data = {} + local is_tag = args[1]:find("=") + if is_tag then + param_data.param = args[1]:sub(1, is_tag-1) + param_data.tag = args[1]:sub(is_tag+1, -1) + table.remove(args, 1) + else + param_data.param = table.remove(args, 1) end - if #out == 0 or not info then - out = {" &6-&a No more parameters to add!", " &6-&a Click &r&c&h[[Add command to chat input]]&s[["..command.."]]here&r&a, or the red command to add it to your chat input."} - end - return out, command - else -- Otherwise things are going totally as planned and we should just recurse onwards - local param_data = {} - local is_tag = args[1]:find("=") - if is_tag then - param_data.param = args[1]:sub(1, is_tag-1) - param_data.tag = args[1]:sub(is_tag+1, -1) - table.remove(args, 1) - else - param_data.param = table.remove(args, 1) - end - if is_tag and #param_data.tag == 0 then - -- If the parameter is an infill thing, and doesn't have a value attached to it: - if not (info[param_data.param] and info[param_data.param].infill) then - return "Missing infill information" + if is_tag and #param_data.tag == 0 then + -- If the parameter is an infill thing, and doesn't have a value attached to it: + if not (info[param_data.param] and info[param_data.param].infill) then + return "Missing infill information" + end + return infill(info[param_data.param].infill, execute..param_data.param.."="), command + elseif param_data.tag then + execute = execute..param_data.param.."="..param_data.tag.." " + command = command..param_data.tag.." " + else + execute = execute..param_data.param.." " + command = command..param_data.param.." " end - return infill(info[param_data.param].infill, execute..param_data.param.."="), command - elseif param_data.tag then - execute = execute..param_data.param.."="..param_data.tag.." " - command = command..param_data.tag.." " - else - execute = execute..param_data.param.." " - command = command..param_data.param.." " + return addDetails(info[param_data.param], args, execute, command) end - return addDetails(info[param_data.param], args, execute, command) end end -end - -local help = function(name, args, data) - local cmds_per, page = 7, 1 -- Turn this into a per-user persistence preference - local info = {} - local out_str = "" - local next_command = "!allium:help " local function run() for i = (cmds_per*(page-1))+1, (cmds_per*page) do @@ -123,7 +135,7 @@ local help = function(name, args, data) out_str = out_str..info[i].."\\n" end end - if out_str == "" or page <= 0 then + if #out_str == 0 or page <= 0 then data.error("Page does not exist.") return end @@ -134,8 +146,9 @@ local help = function(name, args, data) allium.tell(name, out_str, true) end - if tonumber(args[#args]) then - page = tonumber(args[#args]) + local pagenum = tonumber(args[#args]) + if pagenum and pagenum == math.ceil(pagenum) then + page = pagenum args[#args] = nil end From 1c5240bc5b4ffab53c3875d239db948f36761c13 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Thu, 24 Oct 2019 20:28:48 -0700 Subject: [PATCH 23/32] Protect commands from crashing Allium --- allium.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/allium.lua b/allium.lua index 0b8df9c..c7614ff 100644 --- a/allium.lua +++ b/allium.lua @@ -112,7 +112,7 @@ do -- Allium image setup <3 term.setBackgroundColor(colors.black) -- Reset terminal and cursor term.setTextColor(colors.white) print(cli.info, true, "Loading ", colors.magenta, "All", colors.purple, "i", colors.magenta, "um") - print(cli.info, false, "Initializing API") + allium.log("Initializing API") end allium.assert = assert @@ -252,7 +252,13 @@ allium.register = function(p_name, version, fullname) funcs.thread = function(thread) -- Add a thread that repeatedly iterates assert(type(thread) == "function", "Invalid argument #1 (function expected, got "..type(thread)..")") - return raisin.thread(thread, 0, group.thread) + local wrapper = function() + local s, e = pcall(thread) + if not s then + allium.warn("Thread in "..real_name.." | "..e) + end + end + return raisin.thread(wrapper, 0, group.thread) end funcs.loadConfig = function(default) @@ -420,7 +426,7 @@ for _, side in pairs(peripheral.getNames()) do -- Finding the chat module if allium.side then break end end if not allium.side then - print(cli.warn, false, "Allium could not find chat module") + allium.warn("Allium could not find chat module") end -- Packaging the Allium API @@ -434,7 +440,7 @@ else end do -- Plugin loading process - print(cli.info, false, "Loading plugins") + allium.log("Loading plugins") local loader_group = raisin.group(1) local function scopeDown(dir) for _, plugin in pairs(fs.list(dir)) do @@ -566,7 +572,7 @@ local interpreter = function() -- Main command interpretation thread "&4!"..cmd_exec.command.." crashed! This is likely not your fault, but the developer's. Please contact the developer of &a"..cmd_exec.plugin.."&4. Error:", "&c&h[[Click here to place error into chat prompt, so you may copy it if needed for an issue report]]&s[["..err.."]]"..err.."&r" }) - print(cli.warn, false, cmd.." | "..err) + allium.warn(cmd.." | "..err) end end raisin.thread(exec_command, 0, group.command) @@ -577,7 +583,7 @@ local interpreter = function() -- Main command interpretation thread end end -local scanner = function() -- Login/out scanner thread +local player_scanner = function() -- Login/out scanner thread local online = {} while true do local cur_players = allium.getPlayers() @@ -599,13 +605,13 @@ local scanner = function() -- Login/out scanner thread end end else - print(cli.warn, false, "Could not list online players, skipping tick.") + allium.warn("Could not list online players, skipping tick.") end end end raisin.thread(interpreter, 0) -raisin.thread(scanner, 1) +raisin.thread(player_scanner, 1) if not fs.exists(path.."cfg/persistence.lson") then --In the situation that this is a first installation, let's do some setup local fpers = fs.open(path.."cfg/persistence.lson", "w") @@ -613,7 +619,7 @@ if not fs.exists(path.."cfg/persistence.lson") then --In the situation that this fpers.close() end -print(cli.info, false, "Allium started.") +allium.log("Allium started.") allium.tell("@a", "&eHello World!") raisin.manager.run() From eb889b1840412feec134dc8e60a76d97f7d58482 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Fri, 25 Oct 2019 23:52:42 -0700 Subject: [PATCH 24/32] Grand Config Rewrite - Added Small button UI to terminate, reboot, shutdown, and update Allium when requested - Automatic updates have been removed in favor of giving notifications - Allowed restart time-out value to be configurable, when Allium crashes. - Added scan task to depman to allow for checking if dependencies need updating - Added a first-run phase to startup - tweaked how the version is handled internally - typo in prior commit title, meant threads. oops. - Finally, THIS IS A PRE-RELEASE. It's janky, and definitely not expected to work perfectly. I need to rewrite the config loading process... --- allium.lua | 108 ++++++++++++++++++++++++++++++---- startup.lua | 164 +++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 234 insertions(+), 38 deletions(-) diff --git a/allium.lua b/allium.lua index c7614ff..b1b0b3f 100644 --- a/allium.lua +++ b/allium.lua @@ -66,6 +66,14 @@ local cli = { error = {"[", colors.red, "E", colors.white, "] "} } +-- Logging wrapper functions +allium.log = function(...) + print(cli.info, false, ...) +end + +allium.warn = function(...) + print(cli.warn, false, ...) +end local config = ... do -- Configuration parsing @@ -81,6 +89,7 @@ do -- Configuration parsing end end +local main -- Main terminal window Allium is outputting to do -- Allium image setup <3 local image = { " 2a2", @@ -107,7 +116,7 @@ do -- Allium image setup <3 term.setCursorPos(x-7, cy+1) end local win = window.create(term.current(), 1, 1, x-9, y, true) -- Create a window to prevent text from writing over the image - term.redirect(win) -- Redirect the terminal + main = term.redirect(win) -- Redirect the terminal term.setCursorPos(1, 1) term.setBackgroundColor(colors.black) -- Reset terminal and cursor term.setTextColor(colors.white) @@ -122,14 +131,6 @@ allium.sanitize = function(name) return name:lower():gsub(" ", "_"):gsub("[^a-z0-9_]", "") end -allium.log = function(...) - print(cli.info, false, ...) -end - -allium.warn = function(...) - print(cli.warn, false, ...) -end - allium.tell = function(name, message, alt_name) assert(type(name) == "string", "Invalid argument #1 (expected string, got "..type(name)..")") assert(type(message) == "string" or type(message) == "table", "Invalid argument #2 (expected string or table, got "..type(message)..")") @@ -610,8 +611,95 @@ local player_scanner = function() -- Login/out scanner thread end end +local common = { + unhide_update = false, + run = {} +} +common.refresh = function() + local done = term.redirect(main) + local x, y = term.getSize() + common.bY = y-1 + if common.unhide_update then + common.bX = x-6 + term.setCursorPos(x-6, y-1) + term.blit("TRS \24", "888f8", "14efb") + else + common.bx = x-4 + term.setCursorPos(x-5, y-1) + term.blit("TRS", "888", "14e") + end + term.setBackgroundColor(colors.black) -- Reset terminal and cursor + term.setTextColor(colors.white) + term.redirect(done) +end + +local button_manager = function() + common.refresh() + while true do + local e = {os.pullEvent("mouse_click")} + table.remove(e, 1) + if table.remove(e, 1) == 1 then + local x = table.remove(e, 1) + if table.remove(e, 1) == common.bY then + if x-common.bX == 0 then -- Terminate + allium.log("Exiting Allium...") + sleep(1) + return + elseif x-common.bX == 1 then -- Reboot + allium.log("Rebooting...") + sleep(1) + os.reboot() + elseif x-common.bX == 2 then -- Shutdown + allium.log("Shutting down...") + sleep(1) + os.shutdown() + elseif x-common.bX == 4 and common.unhide_update then -- Update + allium.log("Downloading updates...") + for i = 1, #common.run do + common.run[i]() + end + allium.log("Rebooting to apply updates...") + sleep(1) + os.reboot() + end + end + end + end +end + +local update_panel = function() -- Update checker & UI handler thread + if config.updates.notify.dependencies then + local deps = config.updates.check.dependencies() + local suffixer + if #deps > 0 then + if #deps == 1 then + suffixer = {"Utility ", " is "} + else + suffixer = {"Utilities: ", " are "} + end + allium.log(suffixer[1]..table.concat(deps, ", ")..suffixer[2].."ready to be updated") + common.run[#common.run+1] = config.updates.run.dependencies + common.unhide_update = true + end + end + if config.updates.notify.allium then + local sha = config.updates.check.allium() + if sha ~= config.sha then + allium.log("Allium is ready to be updated") + common.run[#common.run+1] = config.updates.run.allium + common.unhide_update = true + end + end + if config.updates.notify.plugins then + -- Things will also be here + end + common.refresh() +end + raisin.thread(interpreter, 0) raisin.thread(player_scanner, 1) +raisin.thread(button_manager, 1) +raisin.thread(update_panel, 1) if not fs.exists(path.."cfg/persistence.lson") then --In the situation that this is a first installation, let's do some setup local fpers = fs.open(path.."cfg/persistence.lson", "w") @@ -621,6 +709,6 @@ end allium.log("Allium started.") allium.tell("@a", "&eHello World!") -raisin.manager.run() +raisin.manager.run(1) package.preload["allium"] = nil \ No newline at end of file diff --git a/startup.lua b/startup.lua index b946371..a98bd0f 100644 --- a/startup.lua +++ b/startup.lua @@ -2,7 +2,8 @@ -- x.x.x-pr = unstable, potential breaking changes local allium_version = "0.9.0-pr" -local path = "/" +local github, json, path = require("lib.nap")("https://api.github.com"), require("lib.json"), "/" +local firstrun = false for str in string.gmatch(shell.getRunningProgram(), ".+[/]") do path = path..str end @@ -17,12 +18,20 @@ end Configurations can be changed in /cfg/allium.lson ]] local default = { - version = allium_version, -- Allium's version - label = "<&r&dAll&5&h[[Killroy wuz here.]]&i[[https://www.youtube.com/watch?v=XqZsoesa55w\\&t=15s]]i&r&dum&r> ", -- The label the loader uses + label = "<&r&dAll&5&h[[Kilroy wuz here.]]&i[[https://www.youtube.com/watch?v=XqZsoesa55w\\&t=15s]]i&r&dum&r> ", -- The label the loader uses import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. - updates = { -- Various auto-update configurations. Server operators may want to change this from the default - dependencies = true, -- Automatically update dependencies - allium = true -- Automatically update allium + restart_timeout = 5, -- The amount of time to wait when allium errors before restarting + updates = { -- Various update configurations. + notify = { -- Configurations to trigger notifications when parts of Allium are ready for an update + dependencies = true, -- Notify when dependencies need updating + plugins = true, -- Notify when plugins need updating + allium = true -- Notify when allium needs updating + }, + repo = { -- Repo specific information for Allium in case you want to use a fork + user = "hugeblank", -- User to pull updates from + branch = "master", -- Branch/Tag to pull updates from + name = "Allium" -- Name of repo to pull updates from + } } } @@ -30,11 +39,10 @@ local default = { local loadSettings = function(file, default) assert(type(file) == "string", "file must be a string") if not fs.exists(file) then - local setting, v = fs.open(file,"w"), default.version - default.version = nil + firstrun = true + local setting = fs.open(file,"w") setting.write(textutils.serialise(default)) setting.close() - default.version = v return default end local setting = fs.open(file, "r") @@ -59,32 +67,130 @@ local loadSettings = function(file, default) end local config = loadSettings(path.."cfg/allium.lson", default) +local depman +config.updates.check = {} +config.updates.run = {} --- Checking Allium/Plugin updates -if config.updates.allium then - if fs.exists(path.."cfg/repolist.csh") then -- Checking for a repolist shell executable - -- Update all plugins and programs on the repolist - for line in io.lines(path.."cfg/repolist.csh") do - shell.run(path..line) +if config.updates.notify.dependencies then + local depget = http.get("https://raw.githubusercontent.com/hugeblank/allium-depman/master/instance.lua") + if depget then + local contents = depget.readAll() + depget.close() + local depargs = { -- Depman args minus the task which can be inserted into the first index + path, + "https://raw.githubusercontent.com/hugeblank/allium-depman/master/listing.lson", + path.."/cfg/deps.lson", + path.."/lib", + allium_version + } + depman = function(task) + local args = {} + for i = 1, #depargs do + args[i] = depargs[i] + end + local env = _ENV + env._ENV = env + local out + env.print = function(...) out = {...} end + if pcall(load(contents, "Depman", nil, env), task, table.unpack(args)) then + return table.unpack(out) + end + end + config.updates.check.dependencies = function() + return textutils.unserialise(depman("scan")) + end + config.updates.run.dependencies = function() + return depman("upgrade") + end + end +end + +if config.updates.notify.allium then + config.updates.check.allium = function() + local repo = config.updates.repo + local jsonresponse = github.repos[repo.user][repo.name].commits[repo.branch]({ + method = "GET" + }) + if jsonresponse then + local out = jsonresponse.readAll() + jsonresponse.close() + return json.decode(out).sha + else + config.updates.notify.allium = false + end + end + config.updates.run.allium = function(sha) + local repo = config.updates.repo + os.run({ + term = { + write=function()end, + setCursorPos=function()end + }, + print = function() end + }, + fs.combine(path, "/lib/gget.lua"), + repo.user, + repo.name, + repo.branch + ) + local file = fs.open(fs.combine(path, "/cfg/version.lson"), "w") + if file then + file.write(textutils.serialise({sha = sha})) + -- Not adding version because we're outdated now. We've been replaced. + file.close() + else + printError("Could not write to file. Is the disk full?") + return end end end --- Filling Dependencies -if config.updates.dependencies then - -- Allium DepMan Instance & Listing: https://github.com/hugeblank/allium-depman/ - print("Checking for dependency updates...") - local didrun, err - didrun = http.get("https://raw.githubusercontent.com/hugeblank/allium-depman/master/instance.lua") - if didrun then - didrun, err = pcall(load(didrun.readAll(), "Depman", nil, _ENV), "upgrade", path, "https://raw.githubusercontent.com/hugeblank/allium-depman/master/listing.lson", path.."/cfg/deps.lson", path.."/lib", allium_version) +if config.updates.notify.plugins then + -- Things will be here +end + +-- First run installation of utilities +if firstrun then + print("Welcome to Allium! Doing some first-run setup and then we'll be on our way.") + if depman then + depman("upgrade") end - if not didrun then - printError("Could not update dependencies: "..(err or "Failed to download instance")) + local sha, file = config.updates.check.allium(), fs.open(fs.combine(path, "/cfg/version.lson"), "w") + if file then + file.write(textutils.serialise({sha = sha, version = allium_version})) + file.close() + else + printError("Could not write to file. Is the disk full?") return end end +local r_file = fs.open(fs.combine(path, "/cfg/version.lson"), "r") +if r_file then + local v_data = textutils.unserialise(r_file.readAll()) + r_file.close() + if v_data then + config.version, config.sha = v_data.version, v_data.sha + else + printError("Could not parse version data, did you mess with ./cfg/version.lson?") + return + end + if not config.version then + local w_file = fs.open(fs.combine(path, "/cfg/version.lson"), "w") + if w_file then -- Reapply version because it was removed by the last version + v_data.version = allium_version + w_file.write(textutils.serialise(v_data)) + w_file.close() + else + printError("Could not write to file. Is the disk full?") + return + end + end +else + printError("Could not read version data, did you delete ./cfg/version.lson?") + return +end + -- Clearing the screen term.setBackgroundColor(colors.black) term.setTextColor(colors.white) @@ -108,6 +214,8 @@ for _, side in pairs(peripheral.getNames()) do -- Finding the chat module end -- Rebooting or exiting -print("Rebooting in 5 seconds") -print("Press any key to cancel") -parallel.waitForAny(function() repeat until os.pullEvent("char") end, function() sleep(5) os.reboot() end) \ No newline at end of file +if config.restart_timeout > 0 then + print("Rebooting in "..config.restart_timeout.." seconds") + print("Press any key to cancel") + parallel.waitForAny(function() repeat until os.pullEvent("char") end, function() sleep(config.restart_timeout) os.reboot() end) +end \ No newline at end of file From 3851791ebd1d4293a490e43ecd3b1113849b6d1b Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 26 Oct 2019 00:22:20 -0700 Subject: [PATCH 25/32] This is why we have an unstable-as branch --- allium.lua | 5 +++-- startup.lua | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/allium.lua b/allium.lua index b1b0b3f..e666517 100644 --- a/allium.lua +++ b/allium.lua @@ -656,7 +656,7 @@ local button_manager = function() elseif x-common.bX == 4 and common.unhide_update then -- Update allium.log("Downloading updates...") for i = 1, #common.run do - common.run[i]() + common.run[i](config.sha) end allium.log("Rebooting to apply updates...") sleep(1) @@ -686,6 +686,7 @@ local update_panel = function() -- Update checker & UI handler thread local sha = config.updates.check.allium() if sha ~= config.sha then allium.log("Allium is ready to be updated") + config.sha = sha common.run[#common.run+1] = config.updates.run.allium common.unhide_update = true end @@ -711,4 +712,4 @@ allium.log("Allium started.") allium.tell("@a", "&eHello World!") raisin.manager.run(1) -package.preload["allium"] = nil \ No newline at end of file +package.preload["allium"] = nil diff --git a/startup.lua b/startup.lua index a98bd0f..be60ebe 100644 --- a/startup.lua +++ b/startup.lua @@ -124,9 +124,13 @@ if config.updates.notify.allium then os.run({ term = { write=function()end, - setCursorPos=function()end + setCursorPos=function()end, + getCursorPos=function() return 1, 1 end }, - print = function() end + print = function() end, + shell = { + getRunningProgram = function() return path.."/lib/gget.lua" end + } }, fs.combine(path, "/lib/gget.lua"), repo.user, @@ -135,7 +139,7 @@ if config.updates.notify.allium then ) local file = fs.open(fs.combine(path, "/cfg/version.lson"), "w") if file then - file.write(textutils.serialise({sha = sha})) + file.write(textutils.serialise({sha = sha})) -- Not adding version because we're outdated now. We've been replaced. file.close() else @@ -179,6 +183,7 @@ if r_file then local w_file = fs.open(fs.combine(path, "/cfg/version.lson"), "w") if w_file then -- Reapply version because it was removed by the last version v_data.version = allium_version + config.version = allium_version w_file.write(textutils.serialise(v_data)) w_file.close() else @@ -218,4 +223,4 @@ if config.restart_timeout > 0 then print("Rebooting in "..config.restart_timeout.." seconds") print("Press any key to cancel") parallel.waitForAny(function() repeat until os.pullEvent("char") end, function() sleep(config.restart_timeout) os.reboot() end) -end \ No newline at end of file +end From f39fa554a85d597f1d2c9424abe41199c0398e90 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 26 Oct 2019 01:59:07 -0700 Subject: [PATCH 26/32] Minor fixes beyond what was functional --- allium.lua | 14 ++++++++------ startup.lua | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/allium.lua b/allium.lua index e666517..12358a4 100644 --- a/allium.lua +++ b/allium.lua @@ -624,7 +624,7 @@ common.refresh = function() term.setCursorPos(x-6, y-1) term.blit("TRS \24", "888f8", "14efb") else - common.bx = x-4 + common.bX = x-4 term.setCursorPos(x-5, y-1) term.blit("TRS", "888", "14e") end @@ -656,7 +656,10 @@ local button_manager = function() elseif x-common.bX == 4 and common.unhide_update then -- Update allium.log("Downloading updates...") for i = 1, #common.run do - common.run[i](config.sha) + local s, e = pcall(table.unpack(common.run[i])) + if not s then + print(cli.error, true, "Failed to execute an update: "..e) + end end allium.log("Rebooting to apply updates...") sleep(1) @@ -678,7 +681,7 @@ local update_panel = function() -- Update checker & UI handler thread suffixer = {"Utilities: ", " are "} end allium.log(suffixer[1]..table.concat(deps, ", ")..suffixer[2].."ready to be updated") - common.run[#common.run+1] = config.updates.run.dependencies + common.run[#common.run+1] = {config.updates.run.dependencies} common.unhide_update = true end end @@ -686,8 +689,7 @@ local update_panel = function() -- Update checker & UI handler thread local sha = config.updates.check.allium() if sha ~= config.sha then allium.log("Allium is ready to be updated") - config.sha = sha - common.run[#common.run+1] = config.updates.run.allium + common.run[#common.run+1] = {config.updates.run.allium, sha} common.unhide_update = true end end @@ -712,4 +714,4 @@ allium.log("Allium started.") allium.tell("@a", "&eHello World!") raisin.manager.run(1) -package.preload["allium"] = nil +package.preload["allium"] = nil \ No newline at end of file diff --git a/startup.lua b/startup.lua index be60ebe..74ff753 100644 --- a/startup.lua +++ b/startup.lua @@ -79,18 +79,31 @@ if config.updates.notify.dependencies then local depargs = { -- Depman args minus the task which can be inserted into the first index path, "https://raw.githubusercontent.com/hugeblank/allium-depman/master/listing.lson", - path.."/cfg/deps.lson", + path.."/cfg/dependencies.lson", path.."/lib", allium_version } + local copyEnv -- My linter sucks and doesn't understand recursion. + copyEnv = function(t) + local out = {} + for key, value in pairs(t) do + if key == "_ENV" then + out[key] = out + elseif type(value) == "table" then + out[key] = copyEnv(value) + else + out[key] = value + end + end + return out + end depman = function(task) local args = {} for i = 1, #depargs do args[i] = depargs[i] end - local env = _ENV - env._ENV = env local out + local env = copyEnv(_ENV) env.print = function(...) out = {...} end if pcall(load(contents, "Depman", nil, env), task, table.unpack(args)) then return table.unpack(out) @@ -121,13 +134,15 @@ if config.updates.notify.allium then end config.updates.run.allium = function(sha) local repo = config.updates.repo + local null = function() end os.run({ term = { - write=function()end, - setCursorPos=function()end, + write=null, + setCursorPos=null, getCursorPos=function() return 1, 1 end }, - print = function() end, + print = null, + write = null, shell = { getRunningProgram = function() return path.."/lib/gget.lua" end } @@ -177,6 +192,7 @@ if r_file then config.version, config.sha = v_data.version, v_data.sha else printError("Could not parse version data, did you mess with ./cfg/version.lson?") + print("If you're updating from a prior version, delete allium.config, reboot, and you should be good.") return end if not config.version then @@ -193,6 +209,7 @@ if r_file then end else printError("Could not read version data, did you delete ./cfg/version.lson?") + print("If you're updating from a prior version, delete allium.config, reboot, and you should be good.") return end @@ -204,7 +221,10 @@ term.setCursorPos(1, 1) -- Running Allium multishell.setTitle(multishell.getCurrent(), "Allium") -os.run(_ENV, path.."allium.lua", config) +local s, e = pcall(os.run(_ENV, path.."allium.lua", config)) +if not s then + printError(e) +end -- Removing all captures for _, side in pairs(peripheral.getNames()) do -- Finding the chat module @@ -223,4 +243,4 @@ if config.restart_timeout > 0 then print("Rebooting in "..config.restart_timeout.." seconds") print("Press any key to cancel") parallel.waitForAny(function() repeat until os.pullEvent("char") end, function() sleep(config.restart_timeout) os.reboot() end) -end +end \ No newline at end of file From 5ee38eb64b55157ebca62e2990f0741731db9e31 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 26 Oct 2019 02:34:28 -0700 Subject: [PATCH 27/32] Replace that damn environment copier with something dumber --- startup.lua | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/startup.lua b/startup.lua index 74ff753..f182595 100644 --- a/startup.lua +++ b/startup.lua @@ -83,34 +83,22 @@ if config.updates.notify.dependencies then path.."/lib", allium_version } - local copyEnv -- My linter sucks and doesn't understand recursion. - copyEnv = function(t) - local out = {} - for key, value in pairs(t) do - if key == "_ENV" then - out[key] = out - elseif type(value) == "table" then - out[key] = copyEnv(value) - else - out[key] = value - end - end - return out - end depman = function(task) local args = {} for i = 1, #depargs do args[i] = depargs[i] end local out - local env = copyEnv(_ENV) - env.print = function(...) out = {...} end - if pcall(load(contents, "Depman", nil, env), task, table.unpack(args)) then + local temp = _G.print -- The good ol' switcheroo + _G.print = function(...) out = {...} end + local result = pcall(load(contents, "Depman", nil, _ENV), task, table.unpack(args)) + _G.print = temp + if result then return table.unpack(out) end end config.updates.check.dependencies = function() - return textutils.unserialise(depman("scan")) + return depman("scan") end config.updates.run.dependencies = function() return depman("upgrade") @@ -221,7 +209,7 @@ term.setCursorPos(1, 1) -- Running Allium multishell.setTitle(multishell.getCurrent(), "Allium") -local s, e = pcall(os.run(_ENV, path.."allium.lua", config)) +local s, e = pcall(os.run, _ENV, path.."allium.lua", config) if not s then printError(e) end From f657e6cd7e486ed965a8d45871ee3b6a2df78678 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 26 Oct 2019 14:35:22 -0700 Subject: [PATCH 28/32] Fix issues related to pulling updates --- allium.lua | 125 +++++++++++++++++++++++++++------------------------- startup.lua | 21 ++++++--- 2 files changed, 78 insertions(+), 68 deletions(-) diff --git a/allium.lua b/allium.lua index 12358a4..da1c3cd 100644 --- a/allium.lua +++ b/allium.lua @@ -624,7 +624,7 @@ common.refresh = function() term.setCursorPos(x-6, y-1) term.blit("TRS \24", "888f8", "14efb") else - common.bX = x-4 + common.bX = x-5 term.setCursorPos(x-5, y-1) term.blit("TRS", "888", "14e") end @@ -633,76 +633,79 @@ common.refresh = function() term.redirect(done) end -local button_manager = function() - common.refresh() - while true do - local e = {os.pullEvent("mouse_click")} - table.remove(e, 1) - if table.remove(e, 1) == 1 then - local x = table.remove(e, 1) - if table.remove(e, 1) == common.bY then - if x-common.bX == 0 then -- Terminate - allium.log("Exiting Allium...") - sleep(1) - return - elseif x-common.bX == 1 then -- Reboot - allium.log("Rebooting...") - sleep(1) - os.reboot() - elseif x-common.bX == 2 then -- Shutdown - allium.log("Shutting down...") - sleep(1) - os.shutdown() - elseif x-common.bX == 4 and common.unhide_update then -- Update - allium.log("Downloading updates...") - for i = 1, #common.run do - local s, e = pcall(table.unpack(common.run[i])) - if not s then - print(cli.error, true, "Failed to execute an update: "..e) - end - end - allium.log("Rebooting to apply updates...") - sleep(1) - os.reboot() +local update_interaction = function() + parallel.waitForAll(function() -- Update checker on initialize + if config.updates.notify.dependencies then + local suc, deps = config.updates.check.dependencies() + local suffixer + if type(deps) == "table" and #deps > 0 then + if #deps == 1 then + suffixer = {"Utility ", " is "} + else + suffixer = {"Utilities: ", " are "} end + allium.log(suffixer[1]..table.concat(deps, ", ")..suffixer[2].."ready to be updated") + common.run[#common.run+1] = {config.updates.run.dependencies} + common.unhide_update = true + elseif not suc then + print(cli.error, true, "Error in checking for dependency updates: "..deps) end end - end -end - -local update_panel = function() -- Update checker & UI handler thread - if config.updates.notify.dependencies then - local deps = config.updates.check.dependencies() - local suffixer - if #deps > 0 then - if #deps == 1 then - suffixer = {"Utility ", " is "} - else - suffixer = {"Utilities: ", " are "} + if config.updates.notify.allium then + local sha = config.updates.check.allium() + if sha ~= config.sha then + allium.log("Allium is ready to be updated") + common.run[#common.run+1] = {config.updates.run.allium, sha} + common.unhide_update = true + elseif not sha then + allium.warn("Failed to scan for allium updates") end - allium.log(suffixer[1]..table.concat(deps, ", ")..suffixer[2].."ready to be updated") - common.run[#common.run+1] = {config.updates.run.dependencies} - common.unhide_update = true end - end - if config.updates.notify.allium then - local sha = config.updates.check.allium() - if sha ~= config.sha then - allium.log("Allium is ready to be updated") - common.run[#common.run+1] = {config.updates.run.allium, sha} - common.unhide_update = true + if config.updates.notify.plugins then + -- Things will also be here end - end - if config.updates.notify.plugins then - -- Things will also be here - end - common.refresh() + common.refresh() + end, function() -- User Interface + common.refresh() + while true do + local e = {os.pullEvent("mouse_click")} + table.remove(e, 1) + if table.remove(e, 1) == 1 then + local x = table.remove(e, 1) + if table.remove(e, 1) == common.bY then + if x-common.bX == 0 then -- Terminate + allium.log("Exiting Allium...") + sleep(1) + return + elseif x-common.bX == 1 then -- Reboot + allium.log("Rebooting...") + sleep(1) + os.reboot() + elseif x-common.bX == 2 then -- Shutdown + allium.log("Shutting down...") + sleep(1) + os.shutdown() + elseif x-common.bX == 4 and common.unhide_update then -- Update + allium.log("Downloading updates...") + for i = 1, #common.run do + local s, err = pcall(table.unpack(common.run[i])) + if not s then + print(cli.error, true, "Failed to execute an update: "..err) + end + end + allium.log("Rebooting to apply updates...") + sleep(1) + os.reboot() + end + end + end + end + end) end raisin.thread(interpreter, 0) raisin.thread(player_scanner, 1) -raisin.thread(button_manager, 1) -raisin.thread(update_panel, 1) +raisin.thread(update_interaction, 1) if not fs.exists(path.."cfg/persistence.lson") then --In the situation that this is a first installation, let's do some setup local fpers = fs.open(path.."cfg/persistence.lson", "w") diff --git a/startup.lua b/startup.lua index f182595..cb72a9a 100644 --- a/startup.lua +++ b/startup.lua @@ -28,9 +28,9 @@ local default = { allium = true -- Notify when allium needs updating }, repo = { -- Repo specific information for Allium in case you want to use a fork - user = "hugeblank", -- User to pull updates from - branch = "master", -- Branch/Tag to pull updates from - name = "Allium" -- Name of repo to pull updates from + user = "hugeblank", -- User to check updates from + branch = "master", -- Branch/Tag to check updates from + name = "Allium" -- Name of repo to check updates from } } } @@ -91,14 +91,21 @@ if config.updates.notify.dependencies then local out local temp = _G.print -- The good ol' switcheroo _G.print = function(...) out = {...} end - local result = pcall(load(contents, "Depman", nil, _ENV), task, table.unpack(args)) + local result, err = pcall(load(contents, "Depman", nil, _ENV), task, table.unpack(args)) _G.print = temp if result then - return table.unpack(out) + return result, table.unpack(out) + else + return result, err end end config.updates.check.dependencies = function() - return depman("scan") + local suc, out = depman("scan") + if suc then + return suc, textutils.unserialise(out) + else + return suc, out + end end config.updates.run.dependencies = function() return depman("upgrade") @@ -117,7 +124,7 @@ if config.updates.notify.allium then jsonresponse.close() return json.decode(out).sha else - config.updates.notify.allium = false + return false end end config.updates.run.allium = function(sha) From 78732c3683ee878eb77bc2fb3e4f306b24254723 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 26 Oct 2019 21:34:31 -0700 Subject: [PATCH 29/32] Pre-Release for color 2.0 Woo! --- allium.lua | 32 ++++++++++++++-------------- plugins/allium-stem.lua | 44 +++++++++++++++++++-------------------- startup.lua | 46 +++++++++++++++++------------------------ 3 files changed, 57 insertions(+), 65 deletions(-) diff --git a/allium.lua b/allium.lua index da1c3cd..f0ddd31 100644 --- a/allium.lua +++ b/allium.lua @@ -66,15 +66,6 @@ local cli = { error = {"[", colors.red, "E", colors.white, "] "} } --- Logging wrapper functions -allium.log = function(...) - print(cli.info, false, ...) -end - -allium.warn = function(...) - print(cli.warn, false, ...) -end - local config = ... do -- Configuration parsing if type(config) ~= "table" then @@ -121,7 +112,7 @@ do -- Allium image setup <3 term.setBackgroundColor(colors.black) -- Reset terminal and cursor term.setTextColor(colors.white) print(cli.info, true, "Loading ", colors.magenta, "All", colors.purple, "i", colors.magenta, "um") - allium.log("Initializing API") + print(cli.info, true, "Initializing API") end allium.assert = assert @@ -131,14 +122,23 @@ allium.sanitize = function(name) return name:lower():gsub(" ", "_"):gsub("[^a-z0-9_]", "") end +-- Logging wrapper functions +allium.log = function(...) + print(cli.info, false, ...) +end + +allium.warn = function(...) + print(cli.warn, false, ...) +end + allium.tell = function(name, message, alt_name) assert(type(name) == "string", "Invalid argument #1 (expected string, got "..type(name)..")") assert(type(message) == "string" or type(message) == "table", "Invalid argument #2 (expected string or table, got "..type(message)..")") local out if type(message) == "table" then - _, out = commands.tellraw(name, color.format(table.concat(message, "\\n"))) + _, out = commands.tellraw(name, color.format(table.concat(message, "\n"))) else - message = message:gsub("\n", "\\n") + --message = message:gsub("\n", "\\n") _, out = commands.tellraw(name, color.format((function(alt_name) if alt_name == true then return "" elseif alt_name then return alt_name.."&r" else return config.label.."&r" end end)(alt_name)..message)) end return textutils.serialise(out) @@ -571,14 +571,14 @@ local interpreter = function() -- Main command interpretation thread if stat == false then -- It crashed... allium.tell(name, { "&4!"..cmd_exec.command.." crashed! This is likely not your fault, but the developer's. Please contact the developer of &a"..cmd_exec.plugin.."&4. Error:", - "&c&h[[Click here to place error into chat prompt, so you may copy it if needed for an issue report]]&s[["..err.."]]"..err.."&r" + "&c&h(Click here to place error into chat prompt, so you may copy it if needed for an issue report)&s("..err..")"..err.."&r" }) allium.warn(cmd.." | "..err) end end raisin.thread(exec_command, 0, group.command) else -- This isn't even a valid command... - allium.tell(name, "&6Invalid Command, use &c&g[[!allium:help]]!help&r&6 for assistance.") --bleh! + allium.tell(name, "&6Invalid Command, use &c&g(!allium:help)!help&r&6 for assistance.") --bleh! end end end @@ -635,7 +635,7 @@ end local update_interaction = function() parallel.waitForAll(function() -- Update checker on initialize - if config.updates.notify.dependencies then + if config.updates.check.dependencies then local suc, deps = config.updates.check.dependencies() local suffixer if type(deps) == "table" and #deps > 0 then @@ -651,7 +651,7 @@ local update_interaction = function() print(cli.error, true, "Error in checking for dependency updates: "..deps) end end - if config.updates.notify.allium then + if config.updates.check.allium then local sha = config.updates.check.allium() if sha ~= config.sha then allium.log("Allium is ready to be updated") diff --git a/plugins/allium-stem.lua b/plugins/allium-stem.lua index e569d18..f02c27a 100644 --- a/plugins/allium-stem.lua +++ b/plugins/allium-stem.lua @@ -1,5 +1,5 @@ local allium = require("allium") -local stem = allium.register("allium", "0.5.0", "Allium Stem") --UPDATE THIS +local stem = allium.register("allium", "0.6.0", "Allium Stem") local help = function(name, args, data) local cmds_per, page = 8, 1 -- Turn this into a per-user persistence preference @@ -15,12 +15,12 @@ local help = function(name, args, data) if variant == "username" then local players = allium.getPlayers() for i = 1, #players do - out[#out+1] = " &6-&r &g[["..execute..players[i].." ]]&h[[Click to add user "..players[i].."]]&a"..players[i] + out[#out+1] = " &6-&r &g("..execute..players[i].." )&h(Click to add user "..players[i]..")&a"..players[i] end elseif variant == "plugin" then local list = allium.getInfo() for plugin in pairs(list) do - out[#out+1] = " &6-&r &g[["..execute..plugin.." ]]&h[[Click to add plugin "..plugin.."]]&a"..plugin + out[#out+1] = " &6-&r &g("..execute..plugin.." )&h(Click to add plugin "..plugin..")&a"..plugin end elseif variant == "command" then local list = allium.getInfo() @@ -28,17 +28,17 @@ local help = function(name, args, data) for command in pairs(v) do local rawcmd = command local command = plugin..":"..command - out[#out+1] = " &6-&r &g[["..execute..command.." ]]&h[[Click to add command !"..rawcmd.."]]&a!"..command + out[#out+1] = " &6-&r &g("..execute..command.." )&h(Click to add command !"..rawcmd..")&a!"..command end end elseif variant:sub(1, -2) == "position_" then local position = allium.getPosition(name).position if variant:sub(-1, -1) == "x" then - out[#out+1] = " &6-&r &g[["..execute..position[1].." ]]&h[[Click to add your x position]]&a"..position[1] + out[#out+1] = " &6-&r &g("..execute..position[1].." )&h(Click to add your x position)&a"..position[1] elseif variant:sub(-1, -1) == "y" then - out[#out+1] = " &6-&r &g[["..execute..position[2].." ]]&h[[Click to add your y position]]&a"..position[2] + out[#out+1] = " &6-&r &g("..execute..position[2].." )&h(Click to add your y position)&a"..position[2] elseif variant:sub(-1, -1) == "z" then - out[#out+1] = " &6-&r &g[["..execute..position[3].." ]]&h[[Click to add your z position]]&a"..position[3] + out[#out+1] = " &6-&r &g("..execute..position[3].." )&h(Click to add your z position)&a"..position[3] end end elseif type(variant) == "function" or type(variant) == "table" then @@ -50,7 +50,7 @@ local help = function(name, args, data) end for i = 1, #result do if type(result[i]) == "string" and not result[i]:find("=") then - out[#out+1] = " &6-&r &g[["..execute..result[i].." ]]&h[[Click to add "..result[i].."]]&a"..result[i] + out[#out+1] = " &6-&r &g("..execute..result[i].." )&h(Click to add "..result[i]..")&a"..result[i] end end end @@ -78,10 +78,10 @@ local help = function(name, args, data) end local meta = "" if #execution ~= 0 then - meta = meta.."&g[["..execution.."]]" + meta = meta.."&g("..execution..")" end if #hover ~= 0 then - meta = meta.."&h[["..hover.."]]" + meta = meta.."&h("..hover..")" end return prefix..meta..label..postfix.." "..information end @@ -98,7 +98,7 @@ local help = function(name, args, data) end end if #out == 0 or not info then - out = {" &6-&a No more parameters to add!", " &6-&a Click &r&c&h[[Click to run command]]&g[["..command.."]]here&r&a to run the command", " &6- &eOR&a click on the first line to add the command to the chat input."} + out = {" &6-&a No more parameters to add!", " &6-&a Click &r&c&h(Click to run command)&g("..command..")here&r&a to run the command", " &6- &eOR&a click on the first line to add the command to the chat input."} end return out, command else -- Otherwise things are going totally as planned and we should just recurse onwards @@ -142,7 +142,7 @@ local help = function(name, args, data) out_str = "&2===================&r &dAll&5i&r&dum&e Help Menu&r &2===================&r\\n"..out_str local template = #(" << "..page.."/"..math.ceil(#info/cmds_per).." >> ") local sides = 32-template - out_str = out_str.."&2"..string.rep("=", sides).."&r &6&l&h[[Previous Page]]&g[["..next_command..(page-1).."]]<<&r&c&l "..page.."/"..math.ceil(#info/cmds_per).." &r&6&l&h[[Next Page]]&g[["..next_command..(page+1).."]]>>&r &2"..string.rep("=", sides).."&r" + out_str = out_str.."&2"..string.rep("=", sides).."&r &6&l&h(Previous Page)&g("..next_command..(page-1)..")<<&r&c&l "..page.."/"..math.ceil(#info/cmds_per).." &r&6&l&h(Next Page)&g("..next_command..(page+1)..")>>&r &2"..string.rep("=", sides).."&r" allium.tell(name, out_str, true) end @@ -161,7 +161,7 @@ local help = function(name, args, data) else entry.usage = "" end - info[#info+1] = "&c&g[[!allium:help "..p_name..":"..cmd_name.."]]&h[[Click to begin autofill]]!"..p_name..":"..cmd_name.."&r: "..entry.info[1] + info[#info+1] = "&c&g(!allium:help "..p_name..":"..cmd_name..")&h(Click to begin autofill)!"..p_name..":"..cmd_name.."&r: "..entry.info[1] end end return run() @@ -182,7 +182,7 @@ local help = function(name, args, data) data.error(cmd..": "..infill_info) return end - info[#info+1] = "&c&s[["..infill_text.."]]&h[[Click to add to chat input]]"..infill_text.."&r" + info[#info+1] = "&c&s("..infill_text..")&h(Click to add to chat input)"..infill_text.."&r" for i = 1, #infill_info do info[#info+1] = infill_info[i] end @@ -204,7 +204,7 @@ local help = function(name, args, data) else entry.usage = "" end - info[#info+1] = "&c&g[[!allium:help "..args[1]..":"..cmd_name.."]]&h[[Click to begin autofill]]!"..cmd_name.."&r: "..entry.info[1] + info[#info+1] = "&c&g(!allium:help "..args[1]..":"..cmd_name..")&h(Click to begin autofill)!"..cmd_name.."&r: "..entry.info[1] end return run() else @@ -217,12 +217,12 @@ end local credits = function(name) allium.tell(name, { - "&dAll&5i&dum &av"..tostring(allium.version).."&r was cultivated with love by &a&h[[Check out his repo!]]&i[[https://github.com/hugeblank]]hugeblank&r.", - "Documentation on Allium can be found here: &9&h[[Read up on Allium!]]&ihttps://github.com/hugeblank/allium-wiki&r.", - "Contribute and report issues to Allium here: &9&h[[Check out where Allium is grown!]]&ihttps://github.com/hugeblank/allium&r.", + "&dAll&5i&dum &av"..tostring(allium.version).."&r was cultivated with love by &a&h(Check out his repo!)&i(https://github.com/hugeblank)hugeblank&r.", + "Documentation on Allium can be found here: &9&h(Read up on Allium!)&ihttps://github.com/hugeblank/allium-wiki&r.", + "Contribute and report issues to Allium here: &9&h(Check out where Allium is grown!)&ihttps://github.com/hugeblank/allium&r.", "&6Other Contributors:", - "&a - &rCommand formatting API by &1&h[[Check out his profile!]]&i[[https://github.com/roger109z]]roger109z&r.", - "&a - &rJSON parsing library by &d&h[[Check out their profile!]]&i[[https://github.com/rxi]]rxi&r." + "&a - &rCommand formatting API by &1&h(Check out his profile!)&i(https://github.com/roger109z)roger109z&r.", + "&a - &rJSON parsing library by &d&h(Check out their profile!)&i(https://github.com/rxi)rxi&r." }, true) end @@ -231,9 +231,9 @@ local plugins = function(name) local str = "" local plugins = allium.getInfo() for p_name in pairs(plugins) do - local p_str = "&h[["..p_name.." v"..tostring(allium.getVersion(p_name)).."]]" + local p_str = "&h("..p_name.." v"..tostring(allium.getVersion(p_name))..")" if plugins[p_name]["credits"] then - p_str = p_str.."&g[[!"..p_name..":credits]]" + p_str = p_str.."&g(!"..p_name..":credits)" end pluginlist[#pluginlist+1] = p_str..allium.getName(p_name) end diff --git a/startup.lua b/startup.lua index cb72a9a..d9b493d 100644 --- a/startup.lua +++ b/startup.lua @@ -1,8 +1,8 @@ -- Allium version -- x.x.x-pr = unstable, potential breaking changes -local allium_version = "0.9.0-pr" +local allium_version = "0.9.0-pr.newcolor" -local github, json, path = require("lib.nap")("https://api.github.com"), require("lib.json"), "/" +local path = "/" local firstrun = false for str in string.gmatch(shell.getRunningProgram(), ".+[/]") do path = path..str @@ -18,9 +18,8 @@ end Configurations can be changed in /cfg/allium.lson ]] local default = { - label = "<&r&dAll&5&h[[Kilroy wuz here.]]&i[[https://www.youtube.com/watch?v=XqZsoesa55w\\&t=15s]]i&r&dum&r> ", -- The label the loader uses + label = "<&r&dAll&5&h(Kilroy wuz here.)&i(https://www.youtube.com/watch?v=XqZsoesa55w\\&t=15s)i&r&dum&r> ", -- The label the loader uses import_timeout = 5, -- The maximum amount of time it takes to wait for a plugin dependency to provide its module. - restart_timeout = 5, -- The amount of time to wait when allium errors before restarting updates = { -- Various update configurations. notify = { -- Configurations to trigger notifications when parts of Allium are ready for an update dependencies = true, -- Notify when dependencies need updating @@ -84,20 +83,12 @@ if config.updates.notify.dependencies then allium_version } depman = function(task) - local args = {} - for i = 1, #depargs do - args[i] = depargs[i] - end - local out + local out = {} local temp = _G.print -- The good ol' switcheroo _G.print = function(...) out = {...} end - local result, err = pcall(load(contents, "Depman", nil, _ENV), task, table.unpack(args)) + local result = pcall(load(contents, "Depman", nil, _ENV), task, table.unpack(depargs)) _G.print = temp - if result then - return result, table.unpack(out) - else - return result, err - end + return result, table.unpack(out) end config.updates.check.dependencies = function() local suc, out = depman("scan") @@ -113,6 +104,17 @@ if config.updates.notify.dependencies then end end + +-- First run installation of utilities +if firstrun then + print("Welcome to Allium! Doing some first-run setup and then we'll be on our way.") + fs.delete(fs.combine(path, "/lib")) + if depman then + depman("upgrade") + end +end +local github, json = require("lib.nap")("https://api.github.com"), require("lib.json") + if config.updates.notify.allium then config.updates.check.allium = function() local repo = config.updates.repo @@ -163,12 +165,9 @@ if config.updates.notify.plugins then -- Things will be here end --- First run installation of utilities +-- Final firstrun stuff if firstrun then - print("Welcome to Allium! Doing some first-run setup and then we'll be on our way.") - if depman then - depman("upgrade") - end + print("Finalizing installation") local sha, file = config.updates.check.allium(), fs.open(fs.combine(path, "/cfg/version.lson"), "w") if file then file.write(textutils.serialise({sha = sha, version = allium_version})) @@ -231,11 +230,4 @@ for _, side in pairs(peripheral.getNames()) do -- Finding the chat module end end end -end - --- Rebooting or exiting -if config.restart_timeout > 0 then - print("Rebooting in "..config.restart_timeout.." seconds") - print("Press any key to cancel") - parallel.waitForAny(function() repeat until os.pullEvent("char") end, function() sleep(config.restart_timeout) os.reboot() end) end \ No newline at end of file From d97a2d0301647ec22459662435f6c518320f9d1c Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 26 Oct 2019 23:09:59 -0700 Subject: [PATCH 30/32] Fix newline issue roger is a bitch he aint shit he can suck on my dick I aint with all this shit why he do me like this??? --- allium.lua | 22 +++++++++++----------- plugins/allium-stem.lua | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/allium.lua b/allium.lua index f0ddd31..72a70dc 100644 --- a/allium.lua +++ b/allium.lua @@ -1,7 +1,7 @@ -- Allium by hugeblank -- Dependency Loading -local raisin, color, semver, mojson = require("lib.raisin"), require("lib.color"), require("lib.semver"), require("lib.mojson") +local raisin, color, semver, mojson, json = require("lib.raisin"), require("lib.color"), require("lib.semver"), require("lib.mojson"), require("lib.json") -- Internal definitions local allium, plugins, group = {}, {}, {thread = raisin.group(1) , command = raisin.group(2)} @@ -133,15 +133,16 @@ end allium.tell = function(name, message, alt_name) assert(type(name) == "string", "Invalid argument #1 (expected string, got "..type(name)..")") - assert(type(message) == "string" or type(message) == "table", "Invalid argument #2 (expected string or table, got "..type(message)..")") - local out + assert(type(message) == "string" or type(message) == "table", "Invalid argument #2 (expected string or table, got "..type(message)..")") + local out = {} if type(message) == "table" then - _, out = commands.tellraw(name, color.format(table.concat(message, "\n"))) + for i = 1, #message do + _, out[#out+1] = commands.async.tellraw(name, json.encode(color.format(message[i]))) + end else - --message = message:gsub("\n", "\\n") - _, out = commands.tellraw(name, color.format((function(alt_name) if alt_name == true then return "" elseif alt_name then return alt_name.."&r" else return config.label.."&r" end end)(alt_name)..message)) - end - return textutils.serialise(out) + _, out = commands.tellraw(name, json.encode(color.format((function(alt_name) if alt_name == true then return "" elseif alt_name then return alt_name.."&r" else return config.label.."&r" end end)(alt_name)..message))) + end + return out end allium.execute = function(name, command) @@ -463,8 +464,8 @@ do -- Plugin loading process end end end - if fs.exists(path.."/plugins") then - scopeDown(path.."/plugins") + if fs.exists(fs.combine(path, "/plugins")) then + scopeDown(fs.combine(path, "/plugins")) end raisin.manager.runGroup(loader_group) end @@ -675,7 +676,6 @@ local update_interaction = function() if table.remove(e, 1) == common.bY then if x-common.bX == 0 then -- Terminate allium.log("Exiting Allium...") - sleep(1) return elseif x-common.bX == 1 then -- Reboot allium.log("Rebooting...") diff --git a/plugins/allium-stem.lua b/plugins/allium-stem.lua index f02c27a..97b748b 100644 --- a/plugins/allium-stem.lua +++ b/plugins/allium-stem.lua @@ -132,14 +132,14 @@ local help = function(name, args, data) local function run() for i = (cmds_per*(page-1))+1, (cmds_per*page) do if info[i] then - out_str = out_str..info[i].."\\n" + out_str = out_str..info[i].."\n" end end if #out_str == 0 or page <= 0 then data.error("Page does not exist.") return end - out_str = "&2===================&r &dAll&5i&r&dum&e Help Menu&r &2===================&r\\n"..out_str + out_str = "&2===================&r &dAll&5i&r&dum&e Help Menu&r &2===================&r\n"..out_str local template = #(" << "..page.."/"..math.ceil(#info/cmds_per).." >> ") local sides = 32-template out_str = out_str.."&2"..string.rep("=", sides).."&r &6&l&h(Previous Page)&g("..next_command..(page-1)..")<<&r&c&l "..page.."/"..math.ceil(#info/cmds_per).." &r&6&l&h(Next Page)&g("..next_command..(page+1)..")>>&r &2"..string.rep("=", sides).."&r" @@ -217,7 +217,7 @@ end local credits = function(name) allium.tell(name, { - "&dAll&5i&dum &av"..tostring(allium.version).."&r was cultivated with love by &a&h(Check out his repo!)&i(https://github.com/hugeblank)hugeblank&r.", + "&dAll&5i&dum &av"..tostring(allium.version).."&r was cultivated with love by &a&h(Check out his profile!)&i(https://github.com/hugeblank)hugeblank&r.", "Documentation on Allium can be found here: &9&h(Read up on Allium!)&ihttps://github.com/hugeblank/allium-wiki&r.", "Contribute and report issues to Allium here: &9&h(Check out where Allium is grown!)&ihttps://github.com/hugeblank/allium&r.", "&6Other Contributors:", From 8a62785b9f1c7f4a3fdb2903a8afe1abfcaa382a Mon Sep 17 00:00:00 2001 From: hugeblank Date: Sat, 26 Oct 2019 23:54:07 -0700 Subject: [PATCH 31/32] Utilize latest version of raisin --- allium.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/allium.lua b/allium.lua index 72a70dc..bd0aa77 100644 --- a/allium.lua +++ b/allium.lua @@ -676,7 +676,7 @@ local update_interaction = function() if table.remove(e, 1) == common.bY then if x-common.bX == 0 then -- Terminate allium.log("Exiting Allium...") - return + raisin.manager.halt() elseif x-common.bX == 1 then -- Reboot allium.log("Rebooting...") sleep(1) @@ -715,6 +715,6 @@ end allium.log("Allium started.") allium.tell("@a", "&eHello World!") -raisin.manager.run(1) +raisin.manager.run() package.preload["allium"] = nil \ No newline at end of file From 6360b3abf1957b23ae960452e656f0784aa1ecc2 Mon Sep 17 00:00:00 2001 From: hugeblank Date: Wed, 6 Nov 2019 22:41:03 -0800 Subject: [PATCH 32/32] Final changes for release --- allium.lua | 60 +++++++++++++++++++++++++---------------------------- startup.lua | 20 +++++++++--------- 2 files changed, 38 insertions(+), 42 deletions(-) diff --git a/allium.lua b/allium.lua index bd0aa77..3362969 100644 --- a/allium.lua +++ b/allium.lua @@ -66,7 +66,7 @@ local cli = { error = {"[", colors.red, "E", colors.white, "] "} } -local config = ... +local config, up = ... do -- Configuration parsing if type(config) ~= "table" then printError("Invalid input configuration, make sure you're using the provided init file.") @@ -612,32 +612,30 @@ local player_scanner = function() -- Login/out scanner thread end end -local common = { - unhide_update = false, - run = {} -} -common.refresh = function() - local done = term.redirect(main) - local x, y = term.getSize() - common.bY = y-1 - if common.unhide_update then - common.bX = x-6 - term.setCursorPos(x-6, y-1) - term.blit("TRS \24", "888f8", "14efb") - else - common.bX = x-5 - term.setCursorPos(x-5, y-1) - term.blit("TRS", "888", "14e") +local update_interaction = function() -- Update UI scanning and handling thread + local common = { + run = {} + } + common.refresh = function() + local done = term.redirect(main) + local x, y = term.getSize() + common.bY = y-1 + if #common.run > 0 then + common.bX = x-6 + term.setCursorPos(x-6, y-1) + term.blit("TRS \24", "888f8", "14efb") + else + common.bX = x-5 + term.setCursorPos(x-5, y-1) + term.blit("TRS", "888", "14e") + end + term.setBackgroundColor(colors.black) -- Reset terminal and cursor + term.setTextColor(colors.white) + term.redirect(done) end - term.setBackgroundColor(colors.black) -- Reset terminal and cursor - term.setTextColor(colors.white) - term.redirect(done) -end - -local update_interaction = function() parallel.waitForAll(function() -- Update checker on initialize - if config.updates.check.dependencies then - local suc, deps = config.updates.check.dependencies() + if config.updates.notify.dependencies then + local suc, deps = up.check.dependencies() local suffixer if type(deps) == "table" and #deps > 0 then if #deps == 1 then @@ -646,18 +644,16 @@ local update_interaction = function() suffixer = {"Utilities: ", " are "} end allium.log(suffixer[1]..table.concat(deps, ", ")..suffixer[2].."ready to be updated") - common.run[#common.run+1] = {config.updates.run.dependencies} - common.unhide_update = true + common.run[#common.run+1] = {up.run.dependencies} elseif not suc then print(cli.error, true, "Error in checking for dependency updates: "..deps) end end - if config.updates.check.allium then - local sha = config.updates.check.allium() + if config.updates.notify.allium then + local sha = up.check.allium() if sha ~= config.sha then allium.log("Allium is ready to be updated") - common.run[#common.run+1] = {config.updates.run.allium, sha} - common.unhide_update = true + common.run[#common.run+1] = {up.run.allium, sha} elseif not sha then allium.warn("Failed to scan for allium updates") end @@ -685,7 +681,7 @@ local update_interaction = function() allium.log("Shutting down...") sleep(1) os.shutdown() - elseif x-common.bX == 4 and common.unhide_update then -- Update + elseif x-common.bX == 4 and #common.run > 0 then -- Update allium.log("Downloading updates...") for i = 1, #common.run do local s, err = pcall(table.unpack(common.run[i])) diff --git a/startup.lua b/startup.lua index d9b493d..f212986 100644 --- a/startup.lua +++ b/startup.lua @@ -1,6 +1,6 @@ -- Allium version -- x.x.x-pr = unstable, potential breaking changes -local allium_version = "0.9.0-pr.newcolor" +local allium_version = "0.9.0" local path = "/" local firstrun = false @@ -65,10 +65,10 @@ local loadSettings = function(file, default) return config end -local config = loadSettings(path.."cfg/allium.lson", default) +local config, up = loadSettings(fs.combine(path, "cfg/allium.lson"), default), {} local depman -config.updates.check = {} -config.updates.run = {} +up.check = {} +up.run = {} if config.updates.notify.dependencies then local depget = http.get("https://raw.githubusercontent.com/hugeblank/allium-depman/master/instance.lua") @@ -90,7 +90,7 @@ if config.updates.notify.dependencies then _G.print = temp return result, table.unpack(out) end - config.updates.check.dependencies = function() + up.check.dependencies = function() local suc, out = depman("scan") if suc then return suc, textutils.unserialise(out) @@ -98,7 +98,7 @@ if config.updates.notify.dependencies then return suc, out end end - config.updates.run.dependencies = function() + up.run.dependencies = function() return depman("upgrade") end end @@ -116,7 +116,7 @@ end local github, json = require("lib.nap")("https://api.github.com"), require("lib.json") if config.updates.notify.allium then - config.updates.check.allium = function() + up.check.allium = function() local repo = config.updates.repo local jsonresponse = github.repos[repo.user][repo.name].commits[repo.branch]({ method = "GET" @@ -126,10 +126,10 @@ if config.updates.notify.allium then jsonresponse.close() return json.decode(out).sha else - return false + return false, "No response from github" end end - config.updates.run.allium = function(sha) + up.run.allium = function(sha) local repo = config.updates.repo local null = function() end os.run({ @@ -215,7 +215,7 @@ term.setCursorPos(1, 1) -- Running Allium multishell.setTitle(multishell.getCurrent(), "Allium") -local s, e = pcall(os.run, _ENV, path.."allium.lua", config) +local s, e = pcall(os.run, _ENV, path.."allium.lua", config, up) if not s then printError(e) end