Refactor to use LuaJIT and improve performance

Integrate LuaJIT as an optional runtime for better performance, with a fallback to standard Lua 5.4. Update Dockerfile to install LuaJIT and create a wrapper script for execution. Enhance network module with socket fallback support and update README to reflect these changes and configuration options.
This commit is contained in:
Bastian (BaM)
2025-09-15 08:44:19 +02:00
parent fff635c2d7
commit 8cb6d55782
9 changed files with 219 additions and 48 deletions

View File

@@ -2,13 +2,23 @@
-- Provides SSH command execution functionality
local utils = require("utils")
local config = require("config")
local ssh_module = {}
-- Check if DEBUG environment variable is set to "true"
local function is_debug()
local debug_env = os.getenv("DEBUG")
return debug_env and (string.lower(debug_env) == "true" or debug_env == "1")
-- Quote a string for safe single-quoted POSIX shell context
local function sq(s)
-- Replace ' with: '\'' (close, escape quote, reopen)
return "'" .. tostring(s):gsub("'", "'\\''") .. "'"
end
-- Helper function to log SSH commands with proper formatting
local function log_ssh_command(prefix, command, full_command)
if config.is_debug() then
utils.log(prefix .. full_command)
else
utils.log(prefix .. sq(command))
end
end
-- Execute a remote command over SSH
@@ -20,11 +30,6 @@ function ssh_module.execute(command, user, host, port, identity_file)
port = tonumber(port or 22) or 22
identity_file = tostring(identity_file or "")
-- Quote a string for safe single-quoted POSIX shell context
local function sq(s)
-- Replace ' with: '\'' (close, escape quote, reopen)
return "'" .. tostring(s):gsub("'", "'\\''") .. "'"
end
-- Build base ssh command (run locally)
-- -oBatchMode to avoid interactive prompts
@@ -51,7 +56,7 @@ function ssh_module.execute(command, user, host, port, identity_file)
-- Pass remote command as provided; caller is responsible for proper quoting
table.insert(pieces, "--")
-- Quote the remote command to prevent shell interpretation of && and ||
table.insert(pieces, "'" .. command:gsub("'", "'\\''") .. "'")
table.insert(pieces, sq(command))
-- Join with spaces for os.execute
local function join(args)
@@ -61,12 +66,8 @@ function ssh_module.execute(command, user, host, port, identity_file)
local full = join(pieces)
-- Log based on DEBUG environment variable
if is_debug() then
utils.log("SSH exec: " .. full)
else
utils.log("SSH exec: " .. "'" .. command:gsub("'", "'\\''") .. "'")
end
-- Log SSH command
log_ssh_command("SSH exec: ", command, full)
local ok, reason, code = os.execute(full)
if ok == true or ok == 0 then
@@ -111,7 +112,7 @@ function ssh_module.execute_with_output(command, user, host, port, identity_file
-- Pass remote command as provided
table.insert(pieces, "--")
-- Quote the remote command to prevent shell interpretation of && and ||
table.insert(pieces, "'" .. command:gsub("'", "'\\''") .. "'")
table.insert(pieces, sq(command))
-- Join with spaces for io.popen
local function join(args)
@@ -120,12 +121,8 @@ function ssh_module.execute_with_output(command, user, host, port, identity_file
local full = join(pieces)
-- Log based on DEBUG environment variable
if is_debug() then
utils.log("SSH exec (with output): " .. full)
else
utils.log("SSH exec (with output): " .. "'" .. command:gsub("'", "'\\''") .. "'")
end
-- Log SSH command
log_ssh_command("SSH exec (with output): ", command, full)
-- Use io.popen to capture output
local fh = io.popen(full, "r")