From 387523724ebaf4647f4fbfd5069ba10784893167 Mon Sep 17 00:00:00 2001 From: Maik Macho Date: Wed, 25 Dec 2019 15:45:16 +0100 Subject: [PATCH 1/3] Fix OpenOS '/bin/sh cmd' failing due to lack of env table /bin/sh.lua should be able to execute a command passed as an argument, but failed to do so as sh.execute (in /lib/sh.lua) expects an env table. Meanwhile, /bin/source.lua passes said environment table when starting the sh process manually. --- .../assets/opencomputers/loot/openos/bin/sh.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua index ae33bd3c96..c3b792afa0 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua @@ -41,7 +41,16 @@ if #args == 0 then end else -- execute command. - local result = table.pack(sh.execute(...)) + local cargs = table.pack(...) + -- sh can run as a shell command (no env table) + local cenv = _ENV + local cargsStart = 1 + if type(cargs[1]) == "table" then + -- sh can also run as a manually started process (see /bin/source.lua) + cenv = cargs[1] + cargsStart = 2 + end + local result = table.pack(sh.execute(cenv, table.unpack(cargs, cargsStart))) if not result[1] then error(result[2], 0) end From 23d0f0111dbb35db2192092760d730efc9caa59f Mon Sep 17 00:00:00 2001 From: Maik Macho Date: Wed, 25 Dec 2019 16:12:13 +0100 Subject: [PATCH 2/3] Use remove instead of unpack + start index, {...} instead of pack --- .../resources/assets/opencomputers/loot/openos/bin/sh.lua | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua index c3b792afa0..c5a6479e3a 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua @@ -41,16 +41,14 @@ if #args == 0 then end else -- execute command. - local cargs = table.pack(...) + local cargs = {...} -- sh can run as a shell command (no env table) local cenv = _ENV - local cargsStart = 1 if type(cargs[1]) == "table" then -- sh can also run as a manually started process (see /bin/source.lua) - cenv = cargs[1] - cargsStart = 2 + cenv = table.remove(cargs, 1) end - local result = table.pack(sh.execute(cenv, table.unpack(cargs, cargsStart))) + local result = {sh.execute(cenv, table.unpack(cargs))} if not result[1] then error(result[2], 0) end From f2ea1fbace3d7b10000560cede7a1b5e4ce92b25 Mon Sep 17 00:00:00 2001 From: Maik Macho Date: Wed, 25 Dec 2019 23:39:26 +0100 Subject: [PATCH 3/3] Take nil into account as a possible env arg in /bin/sh.lua --- src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua index c5a6479e3a..2f07961fc4 100644 --- a/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua +++ b/src/main/resources/assets/opencomputers/loot/openos/bin/sh.lua @@ -44,7 +44,7 @@ else local cargs = {...} -- sh can run as a shell command (no env table) local cenv = _ENV - if type(cargs[1]) == "table" then + if cargs[1] == nil or type(cargs[1]) == "table" then -- sh can also run as a manually started process (see /bin/source.lua) cenv = table.remove(cargs, 1) end