#!/bin/bash

set -x

check_update_grub()
{
    # Run in container mode, return false for skip
    if $(type running-in-container > /dev/null 2>&1) && running-in-container > /dev/null; then
        return 1
    fi

    # if /proc/1/root is not accessable, we should be in the chroot.
    if [ ! -x /proc/1/root ]; then
        return 1
    fi

    # if / stat not match with /proc/1/root/. , we should be in the chroot.
    if [ "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then
        return 1
    fi

    return 0
}

update-grub-gfxpayload

# If we are not runnning in container mode or chroot, run update-grub
check_update_grub && update-grub || true
