From 6de5927dc27bd1af5c8361ca48064806eb481e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fern=C3=A1ndez?= Date: Thu, 3 Jan 2019 18:21:35 +0100 Subject: [PATCH] [build] Add support for Debian packages (#4434) * Add support for Debian packages * SDL: add device probe --- .gitignore | 5 +++ Makefile | 28 +++++++++++++ datastorage.lua | 2 +- frontend/device/generic/device.lua | 1 + frontend/device/sdl/device.lua | 46 ++++++++++++++++---- kodev | 36 ++++++++++++++++ platform/debian/do_debian_package.sh | 63 ++++++++++++++++++++++++++++ platform/debian/koreader.desktop | 9 ++++ platform/debian/koreader.sh | 42 +++++++++++++++++++ 9 files changed, 223 insertions(+), 9 deletions(-) create mode 100755 platform/debian/do_debian_package.sh create mode 100644 platform/debian/koreader.desktop create mode 100755 platform/debian/koreader.sh diff --git a/.gitignore b/.gitignore index 3c598d9be..e4ad8f577 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ trace-out.txt koreader-*.zip koreader-*.apk +koreader-*.deb koreader-*.tar.gz koreader-*.targz koreader-*.click @@ -42,6 +43,10 @@ koreader-android-arm-linux-androideabi* koreader-android-i686-linux-android* koreader-cervantes-arm-linux-gnueabi* koreader-cervantes-arm-cervantes-linux-gnueabi* +koreader-debian-i686-linux-gnu* +koreader-debian-x86_64-linux-gnu* +koreader-debian-armel-arm-linux-gnueabi* +koreader-debian-armhf-arm-linux-gnueabihf* koreader-kindle-legacy-arm-kindle-linux-gnueabi* koreader-kindle-arm-linux-gnueabi* koreader-kobo-arm-linux-gnueabihf* diff --git a/Makefile b/Makefile index 7c177579d..f922304b7 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ ANDROID_DIR=$(PLATFORM_DIR)/android ANDROID_LAUNCHER_DIR:=$(ANDROID_DIR)/luajit-launcher APPIMAGE_DIR=$(PLATFORM_DIR)/appimage CERVANTES_DIR=$(PLATFORM_DIR)/cervantes +DEBIAN_DIR=$(PLATFORM_DIR)/debian KINDLE_DIR=$(PLATFORM_DIR)/kindle KOBO_DIR=$(PLATFORM_DIR)/kobo POCKETBOOK_DIR=$(PLATFORM_DIR)/pocketbook @@ -365,6 +366,24 @@ androidupdate: all cp $(ANDROID_LAUNCHER_DIR)/bin/NativeActivity-debug.apk \ koreader-android-$(MACHINE)-$(VERSION).apk +debianupdate: all + mkdir -p $(INSTALL_DIR)/debian/usr/share/pixmaps + cp -pr resources/koreader.png $(INSTALL_DIR)/debian/usr/share/pixmaps + + mkdir -p $(INSTALL_DIR)/debian/usr/share/applications + cp -pr $(DEBIAN_DIR)/koreader.desktop $(INSTALL_DIR)/debian/usr/share/applications + + mkdir -p $(INSTALL_DIR)/debian/usr/bin + cp -pr $(DEBIAN_DIR)/koreader.sh $(INSTALL_DIR)/debian/usr/bin/koreader + + mkdir -p $(INSTALL_DIR)/debian/usr/lib + cp -Lr $(INSTALL_DIR)/koreader $(INSTALL_DIR)/debian/usr/lib + + cd $(INSTALL_DIR)/debian/usr/lib/koreader && pwd && \ + rm -rf ota cache clipboard screenshots spec && \ + rm -rf resources/fonts resources/icons/src && \ + rm -rf ev_replay.py + sony-prstuxupdate: all # ensure that the binaries were built for ARM file $(INSTALL_DIR)/koreader/luajit | grep ARM || exit 1 @@ -439,6 +458,15 @@ else ifeq ($(TARGET), sony-prstux) make sony-prstuxupdate else ifeq ($(TARGET), ubuntu-touch) make utupdate +else ifeq ($(TARGET), debian) + make debianupdate + $(CURDIR)/platform/debian/do_debian_package.sh $(INSTALL_DIR) +else ifeq ($(TARGET), debian-armel) + make debianupdate + $(CURDIR)/platform/debian/do_debian_package.sh $(INSTALL_DIR) armel +else ifeq ($(TARGET), debian-armhf) + make debianupdate + $(CURDIR)/platform/debian/do_debian_package.sh $(INSTALL_DIR) armhf endif androiddev: androidupdate diff --git a/datastorage.lua b/datastorage.lua index 40a095da0..8e08831a7 100644 --- a/datastorage.lua +++ b/datastorage.lua @@ -17,7 +17,7 @@ function DataStorage:getDataDir() local package_name = app_id:match("^(.-)_") -- confined ubuntu app has write access to this dir data_dir = string.format("%s/%s", os.getenv("XDG_DATA_HOME"), package_name) - elseif os.getenv("APPIMAGE") then + elseif os.getenv("APPIMAGE") or os.getenv("KO_MULTIUSER") then data_dir = string.format("%s/%s/%s", os.getenv("HOME"), ".config", "koreader") else data_dir = "." diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index be88b6196..15f7bdcae 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -39,6 +39,7 @@ local Device = { isPocketBook = no, isSonyPRSTUX = no, isSDL = no, + isEmulator = no, -- some devices have part of their screen covered by the bezel viewport = nil, diff --git a/frontend/device/sdl/device.lua b/frontend/device/sdl/device.lua index 3ea50fe4b..6e4eb1e4b 100644 --- a/frontend/device/sdl/device.lua +++ b/frontend/device/sdl/device.lua @@ -12,25 +12,46 @@ local Device = Generic:new{ hasKeyboard = yes, hasKeys = yes, hasDPad = yes, - hasFrontlight = yes, isTouchDevice = yes, needsScreenRefreshAfterResume = no, hasColorScreen = yes, } -if os.getenv("DISABLE_TOUCH") == "1" then - Device.isTouchDevice = no -end +local AppImage = Device:new{ + model = "AppImage", +} + +local Emulator = Device:new{ + model = "Emulator", + isEmulator = yes, + hasFrontlight = yes, +} + +local Linux = Device:new{ + model = "Linux", +} + +local UbuntuTouch = Device:new{ + model = "UbuntuTouch", + hasFrontlight = yes, +} function Device:init() + local emulator = self.isEmulator -- allows to set a viewport via environment variable -- syntax is Lua table syntax, e.g. EMULATE_READER_VIEWPORT="{x=10,w=550,y=5,h=790}" local viewport = os.getenv("EMULATE_READER_VIEWPORT") - if viewport then + if emulator and viewport then self.viewport = require("ui/geometry"):new(loadstring("return " .. viewport)()) end + + local touchless = os.getenv("DISABLE_TOUCH") == "1" + if emulator and touchless then + self.isTouchDevice = no + end + local portrait = os.getenv("EMULATE_READER_FORCE_PORTRAIT") - if portrait then + if emulator and portrait then self.isAlwaysPortrait = yes end @@ -151,7 +172,7 @@ function Device:init() self.keyboard_layout = require("device/sdl/keyboard_layout") - if portrait then + if emulator and portrait then self.input:registerEventAdjustHook(self.input.adjustTouchSwitchXY) self.input:registerEventAdjustHook( self.input.adjustTouchMirrorX, @@ -196,4 +217,13 @@ function Device:simulateResume() }) end -return Device +-------------- device probe ------------ +if os.getenv("APPIMAGE") then + return AppImage +elseif os.getenv("KO_MULTIUSER") then + return Linux +elseif os.getenv("UBUNTU_APPLICATION_ISOLATION") then + return UbuntuTouch +else + return Emulator +end diff --git a/kodev b/kodev index fed9a56c7..ea574818b 100755 --- a/kodev +++ b/kodev @@ -122,6 +122,9 @@ SUPPORTED_TARGETS=" pocketbook ubuntu-touch appimage + debian Debian package for current arch + debian-armel Debian package for generic armel devices + debian-armhf Debian package for generic armhf devices emu (*default) If no TARGET is given, assume emulator win32 " @@ -228,6 +231,18 @@ ${SUPPORTED_TARGETS}" make TARGET=appimage assert_ret_zero $? ;; + debian) + make TARGET=debian + assert_ret_zero $? + ;; + debian-armel) + make TARGET=debian-armel + assert_ret_zero $? + ;; + debian-armhf) + make TARGET=debian-armhf + assert_ret_zero $? + ;; win32) make TARGET=win32 assert_ret_zero $? @@ -308,6 +323,15 @@ ${SUPPORTED_TARGETS}" appimage) make TARGET=appimage clean ;; + debian) + make TARGET=debian clean + ;; + debian-armel) + make TARGET=debian-armel clean + ;; + debian-armhf) + make TARGET=debian-armhf clean + ;; win32) make TARGET=win32 clean ;; @@ -428,6 +452,18 @@ ${SUPPORTED_RELEASE_TARGETS}" kodev-build appimage make TARGET=appimage update ;; + debian) + kodev-build debian + make TARGET=debian update + ;; + debian-armel) + kodev-build debian-armel + make TARGET=debian-armel update + ;; + debian-armhf) + kodev-build debian-armhf + make TARGET=debian-armhf update + ;; *) echo "Unsupported target for release: $1." echo "${RELEASE_HELP_MSG}" diff --git a/platform/debian/do_debian_package.sh b/platform/debian/do_debian_package.sh new file mode 100755 index 000000000..76d4ce325 --- /dev/null +++ b/platform/debian/do_debian_package.sh @@ -0,0 +1,63 @@ +#!/bin/bash +# Script to generate debian packages for KOReader + +if [ -z "${1}" ]; then + echo "${0}: can't find KOReader build, please specify a path" + exit 1 +else + INSTALL_DIR="${1}" + VERSION="$(cut -f2 -dv "${1}/koreader/git-rev" | cut -f1,2 -d-)" +fi + +uname_to_debian() { + if [ "$(uname -m)" == "x86_64" ]; then + echo "amd64" + elif [ "$(uname -m)" == "i686" ]; then + echo "i686" + elif [ "$(uname -m)" == "arm64" ]; then + echo "aarch64" + else + echo "any" + fi +} + +if [ -z "${2}" ]; then + ARCH="$(uname_to_debian)" +else + ARCH="${2}" +fi + +command_exists() { + type "$1" >/dev/null 2>/dev/null +} + +# Run only if dpkg-deb exists +COMMAND="dpkg-deb" +if command_exists "$COMMAND"; then + mkdir -p "${INSTALL_DIR}/debian/DEBIAN" + { + echo "Section: graphics" + echo "Priority: optional" + echo "Depends: libsdl2-2.0-0" + echo "Architecture: ${ARCH}" + echo "Version: ${VERSION}" + echo "Installed-Size: $(du -ks "${INSTALL_DIR}/debian/usr/" | cut -f 1)" + + echo "Package: KOReader" + echo "Maintainer: KOReader team" + echo "Homepage: https://koreader.rocks" + echo "Description: An ebook reader application supporting PDF, DjVu, EPUB, FB2 and many more formats" + echo " KOReader is a document viewer application, originally created for Kindle e-ink readers." + echo " It currently runs on Kindle, Kobo, PocketBook, Ubuntu Touch, Android and Linux devices" + + } >"${INSTALL_DIR}/debian/DEBIAN/control" + + (cd "${INSTALL_DIR}/.." \ + && fakeroot dpkg-deb -b "${INSTALL_DIR}/debian" "koreader-${VERSION}-${ARCH}.deb") +else + echo "${COMMAND} not found, unable to build Debian package" + exit 1 +fi + +exit 0 + diff --git a/platform/debian/koreader.desktop b/platform/debian/koreader.desktop new file mode 100644 index 000000000..c1d778763 --- /dev/null +++ b/platform/debian/koreader.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=KOReader +Comment=KOReader is a document viewer +Exec=koreader %u +Icon=koreader +Terminal=false +Type=Application +Categories=Graphics; +MimeType=application/pdf;application/x-cbz;application/epub+zip;image/vnd.djvu;text/plain; diff --git a/platform/debian/koreader.sh b/platform/debian/koreader.sh new file mode 100755 index 000000000..e730e74fb --- /dev/null +++ b/platform/debian/koreader.sh @@ -0,0 +1,42 @@ +#!/bin/bash +export LC_ALL="en_US.UTF-8" + +# writable storage: ${HOME}/.config/koreader. +export KO_MULTIUSER=1 + +if [ -z "${1}" ]; then + ARGS="${HOME}" +else + if [ $# -eq 1 ] && [ -e "$(pwd)/${1}" ]; then + ARGS="$(pwd)/${1}" + else + ARGS="${*}" + fi +fi + +# working directory of koreader +KOREADER_DIR="/usr/lib/koreader" + +# we're always starting from our working directory +cd "${KOREADER_DIR}" || exit + +# export load library path +export LD_LIBRARY_PATH=${KOREADER_DIR}/libs:$LD_LIBRARY_PATH + +# export external font directory +export EXT_FONT_DIR="${HOME}/.config/koreader/fonts" +[ ! -d "${EXT_FONT_DIR}" ] && mkdir -pv "${EXT_FONT_DIR}" + +RETURN_VALUE=85 +while [ $RETURN_VALUE -eq 85 ]; do + ./reader.lua "${ARGS}" + RETURN_VALUE=$? + # do not restart with saved arguments + ARGS="${HOME}" +done + +# remove the flag to avoid emulator confusion +export -n KO_MULTIUSER + +exit $RETURN_VALUE +