[Android] Add support for custom startup scripts (#6275)

Add the possibility to run *.sh scripts:

After an update of koreader all *.sh scripts in /sdcard/koreader/scripts.afterupdate
are executed.

On every start of koreader run all *.sh scripts in /sdcard/koreader/scripts.always
reviewable/pr6283/r1
zwim 4 years ago committed by GitHub
parent 88feefe788
commit 488721e62e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,6 +94,8 @@ endif
ifdef ANDROID
cd $(INSTALL_DIR)/koreader && \
ln -sf ../../$(ANDROID_DIR)/*.lua .
@echo "[*] Install afterupdate marker"
@echo "# If this file is here, there are no afterupdate scripts in /sdcard/koreader/scripts/afterupdate." > $(INSTALL_DIR)/koreader/afterupdate.marker
endif
ifdef WIN32
@echo "[*] Install runtime libraries for win32..."
@ -105,7 +107,7 @@ endif
@# purge deleted plugins
for d in $$(ls $(INSTALL_DIR)/koreader/plugins); do \
test -d plugins/$$d || rm -rf $(INSTALL_DIR)/koreader/plugins/$$d ; done
@echo "[*] Installresources"
@echo "[*] Install resources"
$(RCP) -pL resources/fonts/. $(INSTALL_DIR)/koreader/fonts/.
install -d $(INSTALL_DIR)/koreader/{screenshots,data/{dict,tessdata},fonts/host,ota}
ifeq ($(IS_RELEASE),1)

@ -1,6 +1,7 @@
local android = require("android")
android.dl.library_path = android.dl.library_path .. ":" .. android.dir .. "/libs"
local lfs = require("libs/libkoreader-lfs")
local ffi = require("ffi")
local dummy = require("ffi/posix_h")
local C = ffi.C
@ -15,6 +16,37 @@ end
-- path to primary external storage partition
local path = android.getExternalStoragePath()
-- run user shell scripts
local function runUserScripts(dir)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
local fullpath = dir .. "/" .. entry
local mode = lfs.attributes(fullpath).mode
if mode == "file" and fullpath:match(".sh$") then
android.execute("sh", fullpath, path .. "/koreader", android.dir)
elseif mode == "directory" then
runUserScripts(fullpath) -- recurse into next directory
end
end
end
end
-- scripts executed once after an update of koreader
local run_once_scripts = path .. "/koreader/scripts.afterupdate"
if lfs.attributes(run_once_scripts, "mode") == "directory" then
local afterupdate_marker = android.dir .. "/afterupdate.marker"
if lfs.attributes(afterupdate_marker, "mode") ~= nil then
runUserScripts(run_once_scripts)
android.execute("rm", afterupdate_marker)
end
end
-- scripts executed every start of koreader
local run_always_scripts = path .. "/koreader/scripts.always"
if lfs.attributes(run_always_scripts, "mode") == "directory" then
runUserScripts(run_always_scripts)
end
-- run koreader patch before koreader startup
pcall(dofile, path.."/koreader/patch.lua")

Loading…
Cancel
Save