mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
[Kindle NT] fix terminal and timesync (#12765)
Closes #12760 Credits go to @benoit-pierre (Thank you!)
This commit is contained in:
@@ -1635,4 +1635,14 @@ function util.round_decimal(num, points)
|
||||
return math.floor(num * op) / op
|
||||
end
|
||||
|
||||
function util.which(command, path)
|
||||
path = path or os.getenv("PATH") or ""
|
||||
for p in path:gmatch("([^:]+)") do
|
||||
p = p .. "/" .. command
|
||||
if ffiUtil.isExecutable(p) then
|
||||
return p
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return util
|
||||
|
||||
@@ -6,6 +6,7 @@ This plugin provides a terminal emulator (VT52 (+some ANSI and some VT100))
|
||||
|
||||
local Device = require("device")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
require("ffi/posix_h")
|
||||
@@ -76,10 +77,11 @@ local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local TermInputText = require("terminputtext")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local bit = require("bit")
|
||||
local ffiUtil = require("ffi/util")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local _ = require("gettext")
|
||||
local C_ = _.pgettext
|
||||
local T = require("ffi/util").template
|
||||
local T = ffiUtil.template
|
||||
|
||||
local CHUNK_SIZE = 80 * 40 -- max. nb of read bytes (reduce this, if taps are not detected)
|
||||
|
||||
@@ -94,7 +96,7 @@ local Terminal = WidgetContainer:extend{
|
||||
|
||||
function Terminal:isExecutable(file)
|
||||
-- check if file is an executable or a command in PATH
|
||||
return os.execute(string.format("test -x %s || command -v %s", file, file)) == 0
|
||||
return ffiUtil.isExecutable(file) or util.which(file) ~= nil
|
||||
end
|
||||
|
||||
-- Try SHELL environment variable and some standard shells
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
local Device = require("device")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
|
||||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local util = require("util")
|
||||
require("ffi/posix_h")
|
||||
|
||||
-- We need to be root to be able to set the time (CAP_SYS_TIME)
|
||||
if C.getuid() ~= 0 then
|
||||
return { disabled = true, }
|
||||
@@ -11,19 +12,16 @@ end
|
||||
|
||||
local ntp_cmd
|
||||
-- Check if we have access to ntpd or ntpdate
|
||||
if os.execute("command -v ntpd >/dev/null") == 0 then
|
||||
local ntpd = util.which("ntpd")
|
||||
if ntpd then
|
||||
-- Make sure it's actually busybox's implementation, as the syntax may otherwise differ...
|
||||
-- (Of particular note, Kobo ships busybox ntpd, but not ntpdate; and Kindle ships ntpdate and !busybox ntpd).
|
||||
local path = os.getenv("PATH") or ""
|
||||
for p in path:gmatch("([^:]+)") do
|
||||
local sym = lfs.symlinkattributes(p .. "/ntpd")
|
||||
if sym and sym.mode == "link" and string.sub(sym.target, -7) == "busybox" then
|
||||
ntp_cmd = "ntpd -q -n -p pool.ntp.org"
|
||||
break
|
||||
end
|
||||
local sym = lfs.symlinkattributes(ntpd)
|
||||
if sym and sym.mode == "link" and string.sub(sym.target, -7) == "busybox" then
|
||||
ntp_cmd = "ntpd -q -n -p pool.ntp.org"
|
||||
end
|
||||
end
|
||||
if not ntp_cmd and os.execute("command -v ntpdate >/dev/null") == 0 then
|
||||
if not ntp_cmd and util.which("ntpdate") then
|
||||
ntp_cmd = "ntpdate pool.ntp.org"
|
||||
end
|
||||
if not ntp_cmd then
|
||||
|
||||
Reference in New Issue
Block a user