create_config() {
    # Create new extlinux.conf
    if [ ! -f /boot/extlinux/extlinux.conf ]; then
        echo "Creating new /boot/extlinux/extlinux.conf..."
        mkdir -p /boot/extlinux
        echo "LABEL Manjaro
LINUX /Image
INITRD /initramfs-linux.img
FDT /dtbs/amlogic/meson-sm1-g1-tpc.dtb
APPEND root=LABEL=ROOT_MNJRO rootflags=data=writeback rw console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0 audit=0 splash plymouth.ignore-serial-consoles" > /boot/extlinux/extlinux.conf

    fi
}

update_config() {
    # Reconfigure extlinux.conf if needed
    if [ -f /boot/extlinux/extlinux.conf ]; then
        if grep -q -F 'bootsplash.bootfile=bootsplash-themes/manjaro/bootsplash' /boot/extlinux/extlinux.conf; then
            echo "Reconfiguring /boot/extlinux/extlinux.conf..."
            sed -i s!"bootsplash.bootfile=bootsplash-themes/manjaro/bootsplash"!"splash plymouth.ignore-serial-consoles"!g \
                /boot/extlinux/extlinux.conf
        else
            echo "Keeping current /boot/extlinux/extlinux.conf..."
        fi
    fi
}

post_install() {
    # Provide the instructions
    
    if [ -f /boot/extlinux/extlinux.conf.pacsave ]; then
        echo "Picking up /boot/extlinux/extlinux.conf.pacsave..."
        mv -f /boot/extlinux/extlinux.conf.pacsave /boot/extlinux/extlinux.conf
    fi

    if [ -f /boot/extlinux/extlinux.conf ]; then
        update_config
    else
        create_config
    fi
}

post_upgrade() {
    # Provide the instructions

    if [ -f /boot/extlinux/extlinux.conf.pacsave ]; then
        echo "Picking up /boot/extlinux/extlinux.conf.pacsave..."
        mv -f /boot/extlinux/extlinux.conf.pacsave /boot/extlinux/extlinux.conf
    fi

    if [ -f /boot/extlinux/extlinux.conf ]; then
        update_config
    else
        create_config
    fi
}

