#!/usr/bin/env bash
set -e
declare -r pkgname="recrossable"
declare -r pkgdesc="Solve crossword puzzles"
declare -r url="https://github.com/sandsmark/recrossable"
declare -r pkgver="0.0.0-4"
declare -r timestamp="2020-10-05T08:43Z"
declare -r section="games"
declare -r maintainer="Mattéo Delabre <spam@delab.re>"
declare -r license="GPL-2.0-or-later"
declare -ar depends=()
declare -ar conflicts=()
declare -r arch="armv7-3.2"
declare -r image="qt:v1.2"
declare -ar source=([0]="https://github.com/sandsmark/recrossable/archive/5faa37c6e8a13e3ddeb0fe6d9d5f15717f83b662.zip" [1]="recrossable.draft" [2]="recrossable.svg")
declare -ar noextract=()
declare -ar sha256sums=([0]="51e9f630204262fd2b839dafadb4e288797609467e9f07c29f7581711cb2eaec" [1]="SKIP" [2]="SKIP")
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() {
    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/}"
}

# 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
}
if [[ $1 = configure ]]; then
    reload-oxide-apps
fi
