From 2669ccfd02e07cfd5bcf8c77701bec32bdea6f28 Mon Sep 17 00:00:00 2001 From: "Bastian (BaM)" Date: Sun, 14 Sep 2025 14:50:56 +0200 Subject: [PATCH] Refactor SSH command execution to improve command structure and remove unnecessary quoting --- scripts/auto-boot-ollama-host.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/auto-boot-ollama-host.lua b/scripts/auto-boot-ollama-host.lua index ce8666e..7fee491 100644 --- a/scripts/auto-boot-ollama-host.lua +++ b/scripts/auto-boot-ollama-host.lua @@ -120,7 +120,8 @@ local function ssh(command, user, host, port, identity_file) table.insert(pieces, dest) -- Pass remote command as provided; caller is responsible for proper quoting. - table.insert(pieces, " -- " .. command) + table.insert(pieces, "--") + table.insert(pieces, command) -- Join with spaces for os.execute local function join(args) @@ -173,7 +174,8 @@ local function main() if port_is_up(OLLAMA_HOST, SSH_PORT, 60) then log("SSH is reachable. Starting ollama service...") socket.sleep(2) - ssh('wsl.exe -d Debian -- "sudo systemctl enable ollama && sudo systemctl start ollama"', "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) + ssh('wsl.exe -d Debian -- sudo systemctl enable ollama', "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) + ssh('wsl.exe -d Debian -- sudo systemctl start ollama', "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) if (port_is_up(OLLAMA_HOST, OLLAMA_PORT, 90)) then log("Ollama service is reachable again.") socket.sleep(30) @@ -187,7 +189,8 @@ local function main() if line:find(FINISH_PATTERN, 1, true) ~= nil and powered_on == true then log(("Detected finish pattern: %q"):format(FINISH_PATTERN)) log("Shutting down Ollama host to save power...") - ssh('wsl.exe -d Debian -- "sudo systemctl disable ollama && sudo systemctl stop ollama"', "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) + ssh('wsl.exe -d Debian -- sudo systemctl disable ollama', "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) + ssh('wsl.exe -d Debian -- sudo systemctl stop ollama', "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) ssh("shutdown.exe /s /t 0", "micro", OLLAMA_HOST, SSH_PORT, SSH_IDENTITY_FILE) socket.sleep(5) powered_on = false