#!/bin/sh

if [ -f /etc/default/grub ]; then
	. /etc/default/grub
fi

if [ -z "$GRUB_CMDLINE_LINUX_DEFAULT" ]; then
	set -- $(cat /proc/cmdline)
	bootopts=
	for opt; do
		case "$opt" in
		initrd=*|BOOT_IMAGE=*|root=*|rootflags=*) ;;
		*) bootopts="$bootopts $opt";;
		esac
	done
	mkdir -p /etc/default
	echo "GRUB_CMDLINE_LINUX_DEFAULT=\"$bootopts\"" >> /etc/default/grub
fi

if [ -e /etc/grub-autoinstall ]; then
	. /etc/grub-autoinstall
elif [ "${1%-r*}" != "${2%-r*}" ]; then
	cat >&2 <<-EOF
	*
	* GRUB was upgraded. You may need to re-run grub-install before
	* rebooting. Put the command in /etc/grub-autoinstall to automate this.
	*
	EOF
fi
