#!/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-10"
declare -r timestamp="2020-09-26T02:41Z"
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.1"
declare -ar source=([0]="https://github.com/LinusCDE/plato/archive/d8536f8f90ddbd9ac54a787ee5c2d9d966d08c0f.zip")
declare -ar sha256sums=([0]="c78eed996a82286c82dd7a68484ee9f8ceaed7cc0842a59dc710724a45605a71")
#!/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/}"
}
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
