#!/usr/bin/env bash

pkgname="forgejo"
arch="amd64"
pkgrel=1
pkgver="1.21.5-0"
pkgdesc="A painless selfhost git service."
url="https://codeberg.org/forgejo/forgejo"
maintainer="Leafee98 <me@leafee98.com>"
_arch="amd64"

source=(
    "forgejo-${pkgver}-linux-${_arch}.xz::https://codeberg.org/forgejo/forgejo/releases/download/v${pkgver}/forgejo-${pkgver}-linux-${_arch}.xz"
    "forgejo.service::materials/forgejo.service"
    "robots.txt::materials/robots.txt"
)

function package {
    install -Dm755 "${srcdir}/forgejo-${pkgver}-linux-${_arch}" "${pkgdir}/usr/bin/forgejo"
    install -Dm644 "${srcdir}/forgejo.service" "${pkgdir}/usr/lib/systemd/system/forgejo.service"
    install -Dm644 "${srcdir}/robots.txt" "${pkgdir}/etc/forgejo/robots.txt"
}

function debian_postinst {
    cat << EOF
#!/usr/bin/env bash

mkdir -p /var/lib/forgejo
mkdir -p /etc/forgejo/conf
touch /etc/forgejo/conf/app.ini

adduser --system --group git
chown -R git:git /var/lib/forgejo

systemctl daemon-reload
if systemctl is-active --quiet forgejo.service ; then
    systemctl restart forgejo.service
fi
EOF
}