#!/usr/bin/env bash
set -e
declare -r pkgname="plato"
declare -r pkgdesc="Document reader"
declare -r url="https://github.com/LinusCDE/plato"
declare -r pkgver="0.9.1-13"
declare -r timestamp="2020-12-28T17:53Z"
declare -r section="readers"
declare -r maintainer="Linus K. <linus@cosmos-ink.net>"
declare -r license="AGPL-3.0-or-later"
declare -ar depends=()
declare -ar conflicts=()
declare -r arch="armv7-3.2"
declare -r image="rust:v1.2.1"
declare -ar source=([0]="https://github.com/LinusCDE/plato/archive/0.9.13-rm-release-7.zip")
declare -ar noextract=()
declare -ar sha256sums=([0]="17718d74066e5cbec043c98b52958a311eb793674751d6b7789b5baff2227f96")
declare -ar flags=()
#!/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 in an enabled-like state
# ("enabled", "enabled-runtime", "alias", "static", "indirect", "generated"
# or "transient")
#
# Arguments:
#
# $1 - Name of the systemd unit, e.g. "xochitl.service" or "xochitl"
#
# Exit code:
#
# 0 if the unit exists and is enabled, 1 otherwise
is-enabled() {
    systemctl --quiet is-enabled "$1" 2> /dev/null
}

# Check whether a systemd unit is in an active state
# ("running")
#
# Arguments:
#
# $1 - Name of the systemd unit, e.g. "xochitl.service" or "xochitl"
#
# Exit code:
#
# 0 if the unit exists and is enabled, 1 otherwise
is-active() {
    systemctl --quiet is-active "$1" 2> /dev/null
}

# 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() {
    # systemd automatically adds a conflict with "shutdown.target" to all
    # service units (see systemd.service(5), section "Automatic Dependencies")
    systemctl show "$1" | awk -F'=' '/^Conflicts=/{print $2}' \
        | sed 's|\bshutdown.target\b||'
}

# 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/}"
}

# Reload Oxide applications if tarnish is running
#
# Output:
#
# Status message
reload-oxide-apps() {
    if ! is-active tarnish.service; then
        return
    fi
    echo -n "Reloading Oxide applications: "
    if ! /opt/bin/rot apps call reload 2> /dev/null; then
        echo "Failed!"
    else
        echo "Done!"
    fi
}
configure () 
{ 
    local mediadir=/home/root/plato-media;
    if [ ! -d $mediadir ]; then
        mkdir $mediadir;
        echo "";
        echo "Place your media files for plato in '$mediadir'";
        echo "";
    fi
}
if [[ $1 = configure ]]; then
    configure
fi
