#!/usr/bin/env bash
set -e
declare -r pkgname="koreader"
declare -r pkgdesc="An ebook reader application supporting PDF, DjVu, EPUB, FB2 and many more formats"
declare -r url="https://github.com/koreader/koreader"
declare -r pkgver="2020.12-1"
declare -r timestamp="2020-10-10T20:13Z"
declare -r section="readers"
declare -r maintainer="raisjn <of.raisjn@gmail.com>"
declare -r license="AGPL-3.0-or-later"
declare -ar depends=([0]="fbink" [1]="fbdepth")
declare -ar conflicts=()
declare -r arch="armv7-3.2"
declare -r image=""
declare -ar source=([0]="https://build.koreader.rocks/download/stable/v2020.12/koreader-remarkable-v2020.12.zip")
declare -ar noextract=()
declare -ar sha256sums=([0]="38db8f3895472828d7c1d63fc54db426135a8dbf8425633e299a1a9abfdb69b2")
#!/usr/bin/env bash
# Copyright (c) 2020 The Toltec Contributors
# SPDX-License-Identifier: MIT

#
# install-lib
#
# Common functions used by the install scripts
#

# Check whether a systemd unit exists and is enabled
#
# Arguments:
#
# $1 - Full name of the systemd unit, e.g. "xochitl.service"
#
# Exit code:
#
# 0 if the unit exists and is enabled, 1 otherwise
is-enabled() {
    # Note that we must invert the condition so that the exit code indicates
    # a failure when the unit exists and is disabled or when the unit does
    # not exist
    ! systemctl list-unit-files "$1" | awk "/$1/{exit \$2 == \"enabled\"}"
}

# Get a list of systemd units with which the given unit conflicts
#
# Arguments:
#
# $1 - Full name of the systemd unit, e.g. "xochitl.service"
#
# Output:
#
# List of conflicting units
get-conflicts() {
    systemctl show "$1" | awk -F'=' '/^Conflicts=/{print $2}'
}

# Print instructions about how to enable a given systemd service and disable
# the services that conflict with it
#
# Arguments:
#
# $1 - Full name of the systemd unit, e.g. "draft.service"
#
# Output:
#
# Commands to run to achieve the desired result
how-to-enable() {
    for conflict in $(get-conflicts "$1"); do
        if is-enabled "$conflict"; then
            echo "$ systemctl disable --now ${conflict/.service/}"
        fi
    done

    echo "$ systemctl enable --now ${1/.service/}"
}
postremove () 
{ 
    if systemctl list-units --full -all | grep -Fq 'tarnish.service' || [[ "$(ps | grep tarnish | grep -v grep)" != "" ]]; then
        echo "You may need to manually remove the application entry for KOReader in Oxide.";
    fi
}
if [[ $1 = remove ]]; then
    "post"remove "$2"
fi
