Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for debian packages #4434

Merged
merged 7 commits into from Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Expand Up @@ -26,6 +26,7 @@ trace-out.txt

koreader-*.zip
koreader-*.apk
koreader-*.deb
koreader-*.tar.gz
koreader-*.targz
koreader-*.click
Expand All @@ -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*
Expand Down
28 changes: 28 additions & 0 deletions Makefile
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion datastorage.lua
Expand Up @@ -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 = "."
Expand Down
1 change: 1 addition & 0 deletions frontend/device/generic/device.lua
Expand Up @@ -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,
Expand Down
46 changes: 38 additions & 8 deletions frontend/device/sdl/device.lua
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
36 changes: 36 additions & 0 deletions kodev
Expand Up @@ -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
"
Expand Down Expand Up @@ -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 $?
Expand Down Expand Up @@ -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
;;
Expand Down Expand Up @@ -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}"
Expand Down
63 changes: 63 additions & 0 deletions 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)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just shellcheck. Hail spaces! :-P


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

9 changes: 9 additions & 0 deletions 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;
42 changes: 42 additions & 0 deletions 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