#/bin/bash
exe='grub-set-default'
args=()
set_install=
menuentry=
while test "$#" -gt 0
do
	case "${1}" in
		--help) args+=( "${1}" ) ;;
		-h) args+=( "${1}" ) ;;
		--version) args+=( "${1}" ) ;;
		-V) args+=( "${1}" ) ;;
		--boot-directory) args+=( "${1}" ) ;;
		-i) set_install='do_install' ;;
		--) break ;;
		*) break ;;
	esac
	shift
done
# remap a blockdevice
if test -b "${1}"
then
	if test -L "${1}"
	then
		menuentry="${1##*/}"
	else
		echo 2>&1 "${0}: require a /dev/disk/by-label/* symlink if a block device is given"
		exit 1
	fi
else
	menuentry="${1}"
fi
if test -z "${menuentry}"
then
		echo 2>&1 "${0}: require filesystem label from /dev/disk/by-label/* to activate a 'menuentry' in /chainloader/grub2-chainloader/grub2/grub.cfg"
		exit 1
fi
if test -n "${set_install}"
then
	args+=( "install ${menuentry}" )
else
	args+=( "${menuentry}" )
fi
set -x
exec "/usr/lib64/grub2-chainloader/sbin/${exe}" "${args[@]}"
