# Maintainer: Valeria Fadeeva <valeria@fadeeva.me>

_gitname="$(basename $(pwd))"
pkgname=("melawy-$_gitname")
pkgver=1.3
pkgrel=1
pkgdesc="$(head -n 2 README.md | tail -n 1)"
arch=('any')
url="https://git.melawy.ru/Melawy-Linux/$_gitname"
license=('AGPL3')

depends=()

makedepends=('git')

optdepends=()

backup=()
provides=("${pkgname}")
conflicts=("${pkgname}")
options=(!strip !emptydirs)
source=("git+$url.git")
sha256sums=("SKIP")
validpgpkeys=("BC8B600E8DDA1F4CB77B10D2BA803A261A5EE6B8")

# pkgver() {
#       cd "$srcdir/$_gitname"
#       printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
# }

pkgver() {
        cd "${srcdir}/${_gitname}"
        printf "1.%s" "$(git rev-list --count HEAD)"
}

package() {
    # Clone file structure
    install -d "${pkgdir}/etc/skel/"
    cp -rT --no-preserve=ownership "${srcdir}/${_gitname}/skel/" "${pkgdir}/etc/skel/"

    # Find all scripts
    readarray -d '' scripts < <(find "${pkgdir}/etc/skel" -type f \( -iname "*.sh" -o -iname "*.bash" \) -print0)

    # Make scripts executable
    for script in "${scripts[@]}";
    do
        [[ -f ${script} ]] && chmod +x "${script}"
    done
}
