# Maintainer: lap1sid <development@fascode.net>

pkgname=alterlinux-calamares
_reponame=alterlinux-calamares-old
pkgver="3.2.35"
pkgrel=3
_pkgrel='b2'
pkgdesc='Distribution-independent installer framework'
arch=('i686' 'x86_64')
license=(GPL)
url="https://github.com/FascodeNet/alterlinux-calamares"
license=('LGPL')
depends=('kconfig' 'kcoreaddons' 'kiconthemes' 'ki18n' 'kio' 'solid' 'yaml-cpp' 'kpmcore'
         'boost-libs' 'hwinfo' 'qt5-svg' 'polkit-qt5' 'gtk-update-icon-cache' 'plasma-framework'
         'qt5-xmlpatterns' 'squashfs-tools' 'ckbcomp' 'libffi')
makedepends=('extra-cmake-modules' 'qt5-tools' 'qt5-translations' 'git' 'boost' 'ninja')
backup=(
        'usr/share/calamares/modules/bootloader.conf'
        'usr/share/calamares/modules/displaymanager.conf'
        'usr/share/calamares/modules/initcpio.conf'
        'usr/share/calamares/modules/unpackfs.conf'
        'usr/share/calamares/modules/removeuser.conf'
        'usr/share/calamares/modules/users.conf'
        'usr/share/calamares/branding/alter/branding.desc'
)

source+=("${url}/archive/${pkgver}-${pkgrel}.tar.gz")
#source+=("$url/archive/$pkgver-$_pkgrel.tar.gz")

sha256sums=('SKIP')

prepare() {
    # rename
    mv "${srcdir}/${_reponame}-${pkgver}-${pkgrel}" "${srcdir}/${pkgver}-${pkgrel}"
    #mv ${srcdir}/${pkgname}-${pkgver}-${_pkgrel} ${srcdir}/${pkgver}-${pkgrel}
    cd "${srcdir}/${pkgver}-${pkgrel}"
    sed -i -e 's/"Install configuration files" OFF/"Install configuration files" ON/' CMakeLists.txt

    # change branding
    sed -i -e "s/default/alter/g" src/branding/CMakeLists.txt
}

build() {
    cd ${srcdir}/${pkgver}-${pkgrel}

    mkdir -p build
    cd build
        cmake .. \
              -DCMAKE_BUILD_TYPE=Release \
              -DCMAKE_INSTALL_PREFIX=/usr \
              -DCMAKE_INSTALL_LIBDIR=lib \
              -DWITH_PYTHONQT:BOOL=ON \
              -DBoost_NO_BOOST_CMAKE=ON \
              -GNinja \
              -DSKIP_MODULES="tracking webview interactiveterminal initramfs \
                              initramfscfg dracut dracutlukscfg \
                              dummyprocess dummypython dummycpp \
                              dummypythonqt services-openrc"
        ninja
}

package() {
    cd ${srcdir}/${pkgver}-${pkgrel}/build
    DESTDIR="$pkgdir" ninja install
    install -Dm755 "../data/final-process" "$pkgdir/usr/share/calamares/final-process"
    install -Dm644 "../data/alter-icon.svg" "$pkgdir/usr/share/icons/hicolor/scalable/apps/calamares.svg"
    install -Dm644 "../data/calamares.desktop" "$pkgdir/usr/share/applications/calamares.desktop"
    install -Dm755 "../data/calamares_polkit" "$pkgdir/usr/bin/calamares_polkit"
    install -Dm644 "../data/49-nopasswd-calamares.rules" "$pkgdir/etc/polkit-1/rules.d/49-nopasswd-calamares.rules"
    chmod 750      "$pkgdir"/etc/polkit-1/rules.d

    # rename services-systemd back to services
    mv "$pkgdir/usr/lib/calamares/modules/services-systemd" "$pkgdir/usr/lib/calamares/modules/services"
    mv "$pkgdir/usr/share/calamares/modules/services-systemd.conf" "$pkgdir/usr/share/calamares/modules/services.conf"
    sed -i -e 's/-systemd//' "$pkgdir/usr/lib/calamares/modules/services/module.desc"
    sed -i -e 's/-systemd//' "$pkgdir/usr/share/calamares/settings.conf"
}
