# Maintainer: Antergos NeXT <antergos-next@github>

_tag=0.14.1

pkgbase=antergos-live
pkgname=('antergos-live-base'
        'antergos-live-dinit'
        'antergos-live-openrc'
        'antergos-grub-live')
pkgver=2026.06
pkgrel=4
pkgdesc='Antergos live session'
arch=('any')
url="https://github.com/Antergos-NeXT/antergos-live"
license=('GPL')
makedepends=('git' 'bash' 'artools-base')
source=("git+https://gitea.artixlinux.org/artix/artix-live.git#tag=$_tag")
sha256sums=('SKIP')

pkgver() {
   date +%Y.%m
}

build() {
    make -C artix-live
    sed -i 's/artix/antergos/g; s/Artix/Antergos/g' \
        artix-live/data/grub/cfg/kernels.cfg \
        artix-live/data/grub/cfg/variable.cfg \
        artix-live/data/grub/cfg/grub.cfg \
        artix-live/data/grub/cfg/defaults.cfg \
        artix-live/data/grub/cfg/loopback.cfg \
        artix-live/data/live.conf 2>/dev/null || true
}

package_antergos-live-base() {
    pkgdesc='Antergos live base scripts'
    depends=('artools-base' 'bash')

    make -C artix-live DESTDIR=${pkgdir} install_base install_xdg

    # Rename binary and fix internal references
    sed -i 's/LIVEUSER=${LIVEUSER:-artix}/LIVEUSER=${LIVEUSER:-liveuser}/g; s|LOGFILE='\''/var/log/artix-live.log'\''|LOGFILE='\''/var/log/antergos-live.log'\''|g' "${pkgdir}/usr/bin/artix-live" 2>/dev/null || true
    mv "${pkgdir}/usr/bin/artix-live" "${pkgdir}/usr/bin/antergos-live" 2>/dev/null || true
}

package_antergos-live-openrc() {
    pkgdesc='Antergos live openrc init scripts'
    depends=('antergos-live-base')
    provides=('init-antergos-live')
    conflicts=('init-antergos-live' 'init-artix-live')

    make -C artix-live DESTDIR=${pkgdir} install_rc

    # Rename init script and fix internal references
    sed -i 's/artix live script/antergos live script/g; s|/usr/bin/artix-live|/usr/bin/antergos-live|g' "${pkgdir}/etc/init.d/artix-live" 2>/dev/null || true
    mv "${pkgdir}/etc/init.d/artix-live" "${pkgdir}/etc/init.d/antergos-live" 2>/dev/null || true

    install -d "${pkgdir}"/etc/runlevels/default
    ln -sf /etc/init.d/antergos-live "${pkgdir}"/etc/runlevels/default/antergos-live
    ln -sf /etc/init.d/pacman-init "${pkgdir}"/etc/runlevels/default/pacman-init
}

package_antergos-live-dinit() {
    pkgdesc='Antergos live dinit init scripts'
    depends=('antergos-live-base')
    provides=('init-antergos-live')
    conflicts=('init-antergos-live' 'init-artix-live')

    make -C artix-live DESTDIR=${pkgdir} install_dinit

    # Rename and fix internal references in dinit service files
    sed -i 's|/usr/bin/artix-live|/usr/bin/antergos-live|g; s/artix live/antergos live/g' "${pkgdir}/etc/dinit.d/artix-live" 2>/dev/null || true
    mv "${pkgdir}/etc/dinit.d/artix-live" "${pkgdir}/etc/dinit.d/antergos-live" 2>/dev/null || true

    # Fix boot.d symlinks
    rm -f "${pkgdir}/etc/dinit.d/boot.d/artix-live"
    ln -sf ../antergos-live "${pkgdir}/etc/dinit.d/boot.d/antergos-live"
}

package_antergos-grub-live() {
    pkgdesc='Antergos grub live'

    make -C artix-live PREFIX=/usr DESTDIR=${pkgdir} install_grub
}
