#!/usr/bin/env bash
# Copyright (c) 2021 The Toltec Contributors
# SPDX-License-Identifier: MIT

archs=(rmallos2 rmallos3)
pkgnames=("signature-rm")
pkgdesc="Remove the signature from the bottom of emails"
url="https://github.com/rM-self-serve/signature-rM"
pkgver=1.0.2-2
timestamp=2023-12-06T11:43:00Z
section="utils"
maintainer="rM-self-serve <122753594+rM-self-serve@users.noreply.github.com>"
license=MIT
image=rust:v3.1
conflicts=(webinterface-onboot)
conflicts_rmallos2=(ddvk-hacks)

source=(
    "$url"/archive/b5561af4eb6a0f5aa6e98e1a1279066f0c4bd9b7.zip
)
sha256sums=(
    1a7cc8bf7a3f5a7cc9a10ca968bbb5a0082a065760f4cb7038fdb6b9aed4bb00
)

build() {
    cargo build --release
}

package() {
    install -D -m 755 -t "$pkgdir"/opt/bin \
        "$srcdir/target/armv7-unknown-linux-gnueabihf/release/$pkgname"

    mkdir -p "$pkgdir"/opt/share/toltec/reenable.d
    touch "$pkgdir"/opt/share/toltec/reenable.d/"$pkgname"
}

configure() {
    echo
    echo "Applying signature-rM"
    signature-rm apply -y > /dev/null
    echo "Success"
    echo
}

_restore() {
    echo "Reverting /usr/bin/xochitl"
    if signature-rm has-backup > /dev/null; then
        signature-rm revert --backup -y > /dev/null
    else
        signature-rm revert --reverse -y > /dev/null
    fi
    echo "Success"
    echo
}

preremove() {
    _restore
}

preupgrade() {
    _restore
}
