inherit features_check
REQUIRED_DISTRO_FEATURES = "swupdate"

# File in the swupdate subdirectory of this recipe should overwrite the
# same file in meta-swupdate
FILESEXTRAPATHS:prepend := "${THISDIR}/swupdate:"

DEPENDS += "cos-certificates-and-keys-native"

SRC_URI += "\
    file://50-webserver-config.sh \
    file://25-sw-collections-config.sh \
"

PACKAGES =+ "${PN}-coreos-config ${PN}-coreos-installer-config"

# Don't use /www as the web root
wwwdir = "${datadir}/swupdate-www"

# Add the hwrevision files to the main package to prevent
# installation of .swu image built for another machine
FILES:${PN} += "${sysconfdir}/hwrevision"

# If we install the webserver package, it should be started automatically
FILES:${PN}-www += "${libdir}/swupdate/conf.d/50-webserver-config.sh"

FILES:${PN}-coreos-config += "${libdir}/swupdate/conf.d/25-sw-collections-config.sh"

RDEPENDS:${PN}:append = " efibootguard"

# lsblk is used in sw-collections-config.sh
RDEPENDS:${PN}-coreos-config += "util-linux-lsblk"

# Recommends by default the configuration used for normal image
# that contain the A/B update path switch
RRECOMMENDS:${PN} += "${PN}-coreos-config"

# The installer configuration should prevent the normal A/B switch
# configuration to be installed
RCONFLICTS:${PN}-coreos-installer-config = "${PN}-coreos-config"

inherit coreos-efi-secureboot

do_install:append() {
    # Probably replace revision with the value of the device tree
    install -m 755 ${WORKDIR}/50-webserver-config.sh ${D}${libdir}/swupdate/conf.d/
    install -m 755 ${WORKDIR}/25-sw-collections-config.sh ${D}${libdir}/swupdate/conf.d/
    install -m 755 ${COREOS_EFI_SECUREBOOT_KEYDIR}/swupdate.crt ${D}${libdir}/swupdate/
    echo "${MACHINE} 1.0" > ${D}${sysconfdir}/hwrevision
}
