has_package() {
    pacman -Qq "${1}" > /dev/null 2>&1
}

post_install() {
    # Configure mkinitcpio.conf
    if has_package "mkinitcpio" && \
       [ -f /etc/mkinitcpio.conf ] && \
       grep -q '^MODULES=()' /etc/mkinitcpio.conf; then
        echo "Configuring /etc/mkinitcpio.conf..."
        sed -i s/"^MODULES=()"/"MODULES=(rockchipdrm)"/g /etc/mkinitcpio.conf
    fi
}

post_upgrade() {
    # Provide instructions about the video output kernel modules
    if has_package "mkinitcpio" && \
       [ -f /etc/mkinitcpio.conf ] && \
       ! grep -q '^MODULES=(.*rockchipdrm)' /etc/mkinitcpio.conf; then
        echo "To have the boot screen visible as early as possible, please ensure that"
        echo "'rockchipdrm' is found at the end of the 'MODULES' list in /etc/mkinitcpio.conf"
        echo "and rebuild the initcpio images.  You can do that by running these two commands:"
        echo "# sed -i 's/^MODULES=(.*)/MODULES=(rockchipdrm)/g' /etc/mkinitcpio.conf"
        echo "# mkinitcpio -P"
    fi
}
