2N/A# Helper library for grub-mkconfig
2N/A# Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc.
2N/A# Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2N/A#
2N/A# GRUB is free software: you can redistribute it and/or modify
2N/A# it under the terms of the GNU General Public License as published by
2N/A# the Free Software Foundation, either version 3 of the License, or
2N/A# (at your option) any later version.
2N/A#
2N/A# GRUB is distributed in the hope that it will be useful,
2N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A# GNU General Public License for more details.
2N/A#
2N/A# You should have received a copy of the GNU General Public License
2N/A# along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A
2N/Atransform="@program_transform_name@"
2N/A
2N/APATH=/usr/gnu/bin:$PATH
2N/Aprefix="@prefix@"
2N/Aexec_prefix="@exec_prefix@"
2N/Adatarootdir="@datarootdir@"
2N/Adatadir="@datadir@"
2N/Abindir="@bindir@"
2N/Asbindir="@sbindir@"
2N/Apkgdatadir="${datadir}/`echo "@PACKAGE_TARNAME@" | sed "${transform}"`"
2N/A
2N/Aif test "x$grub_probe" = x; then
2N/A grub_probe="${sbindir}/`echo grub-probe | sed "${transform}"`"
2N/Afi
2N/Aif test "x$grub_mkrelpath" = x; then
2N/A grub_mkrelpath="${bindir}/`echo grub-mkrelpath | sed "${transform}"`"
2N/Afi
2N/A
2N/Aif $(which gettext >/dev/null 2>/dev/null) ; then
2N/A gettext="gettext"
2N/Aelse
2N/A gettext="echo"
2N/Afi
2N/A
2N/Agrub_warn ()
2N/A{
2N/A echo "Warning: $@" >&2
2N/A}
2N/A
2N/Amake_system_path_relative_to_its_root ()
2N/A{
2N/A "${grub_mkrelpath}" "$1"
2N/A}
2N/A
2N/Ais_path_readable_by_grub ()
2N/A{
2N/A path="$1"
2N/A
2N/A # abort if path doesn't exist
2N/A if test -e "$path" ; then : ;else
2N/A return 1
2N/A fi
2N/A
2N/A # abort if file is in a filesystem we can't read
2N/A if "${grub_probe}" -t fs "$path" > /dev/null 2>&1 ; then : ; else
2N/A return 1
2N/A fi
2N/A
2N/A # ... or if we can't figure out the abstraction module, for example if
2N/A # memberlist fails on an LVM volume group.
2N/A if abstractions="`"${grub_probe}" -t abstraction "$path"`" 2>&1 ; then
2N/A :
2N/A else
2N/A return 1
2N/A fi
2N/A
2N/A if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
2N/A return 0
2N/A fi
2N/A
2N/A for abstraction in $abstractions; do
2N/A if [ "x$abstraction" = xcryptodisk ]; then
2N/A return 1
2N/A fi
2N/A done
2N/A
2N/A return 0
2N/A}
2N/A
2N/Aconvert_system_path_to_grub_path ()
2N/A{
2N/A path="$1"
2N/A
2N/A grub_warn "convert_system_path_to_grub_path() is deprecated. Use prepare_grub_to_access_device() instead."
2N/A
2N/A # abort if GRUB can't access the path
2N/A if is_path_readable_by_grub "${path}" ; then : ; else
2N/A return 1
2N/A fi
2N/A
2N/A if drive="`"${grub_probe}" -t drive "$path"`" ; then : ; else
2N/A return 1
2N/A fi
2N/A
2N/A if relative_path="`make_system_path_relative_to_its_root "$path"`" ; then : ; else
2N/A return 1
2N/A fi
2N/A
2N/A echo "${drive}${relative_path}"
2N/A}
2N/A
2N/Asave_default_entry ()
2N/A{
2N/A if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
2N/A cat << EOF
2N/Asavedefault
2N/AEOF
2N/A fi
2N/A}
2N/A
2N/Aprepare_grub_to_access_device ()
2N/A{
2N/A device="$1"
2N/A
2N/A partmap="`"${grub_probe}" --device "${device}" --target=partmap`"
2N/A for module in ${partmap} ; do
2N/A case "${module}" in
2N/A netbsd | openbsd)
2N/A echo "insmod part_bsd";;
2N/A *)
2N/A echo "insmod part_${module}";;
2N/A esac
2N/A done
2N/A
2N/A # Abstraction modules aren't auto-loaded.
2N/A abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
2N/A for module in ${abstraction} ; do
2N/A echo "insmod ${module}"
2N/A done
2N/A
2N/A fs="`"${grub_probe}" --device "${device}" --target=fs`"
2N/A for module in ${fs} ; do
2N/A echo "insmod ${module}"
2N/A done
2N/A
2N/A if [ x$GRUB_CRYPTODISK_ENABLE = xy ]; then
2N/A for uuid in "`"${grub_probe}" --device "${device}" --target=cryptodisk_uuid`"; do
2N/A echo "cryptomount -u $uuid"
2N/A done
2N/A fi
2N/A
2N/A # If there's a filesystem UUID that GRUB is capable of identifying, use it;
2N/A # otherwise set root as per value in device.map.
2N/A echo "set root='`"${grub_probe}" --device "${device}" --target=compatibility_hint`'"
2N/A if fs_uuid="`"${grub_probe}" --device "${device}" --target=fs_uuid 2> /dev/null`" ; then
2N/A hints="`"${grub_probe}" --device "${device}" --target=hints_string 2> /dev/null`"
2N/A echo "if [ x\$feature_platform_search_hint = xy ]; then"
2N/A echo " search --no-floppy --fs-uuid --set=root ${hints} ${fs_uuid}"
2N/A echo "else"
2N/A echo " search --no-floppy --fs-uuid --set=root ${fs_uuid}"
2N/A echo "fi"
2N/A fi
2N/A}
2N/A
2N/Agrub_file_is_not_garbage ()
2N/A{
2N/A if test -f "$1" ; then
2N/A case "$1" in
2N/A *.dpkg-*) return 1 ;; # debian dpkg
2N/A README*|*/README*) return 1 ;; # documentation
2N/A esac
2N/A else
2N/A return 1
2N/A fi
2N/A return 0
2N/A}
2N/A
2N/Aversion_test_numeric ()
2N/A{
2N/A version_test_numeric_a="$1"
2N/A version_test_numeric_cmp="$2"
2N/A version_test_numeric_b="$3"
2N/A if [ "$version_test_numeric_a" = "$version_test_numeric_b" ] ; then
2N/A case "$version_test_numeric_cmp" in
2N/A ge|eq|le) return 0 ;;
2N/A gt|lt) return 1 ;;
2N/A esac
2N/A fi
2N/A if [ "$version_test_numeric_cmp" = "lt" ] ; then
2N/A version_test_numeric_c="$version_test_numeric_a"
2N/A version_test_numeric_a="$version_test_numeric_b"
2N/A version_test_numeric_b="$version_test_numeric_c"
2N/A fi
2N/A if (echo "$version_test_numeric_a" ; echo "$version_test_numeric_b") | sort -n | head -n 1 | grep -qx "$version_test_numeric_b" ; then
2N/A return 0
2N/A else
2N/A return 1
2N/A fi
2N/A}
2N/A
2N/Aversion_test_gt ()
2N/A{
2N/A version_test_gt_a="`echo "$1" | sed -e "s/[^-]*-//"`"
2N/A version_test_gt_b="`echo "$2" | sed -e "s/[^-]*-//"`"
2N/A version_test_gt_cmp=gt
2N/A if [ "x$version_test_gt_b" = "x" ] ; then
2N/A return 0
2N/A fi
2N/A case "$version_test_gt_a:$version_test_gt_b" in
2N/A *.old:*.old) ;;
2N/A *.old:*) version_test_gt_a="`echo -n "$version_test_gt_a" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=gt ;;
2N/A *:*.old) version_test_gt_b="`echo -n "$version_test_gt_b" | sed -e 's/\.old$//'`" ; version_test_gt_cmp=ge ;;
2N/A esac
2N/A version_test_numeric "$version_test_gt_a" "$version_test_gt_cmp" "$version_test_gt_b"
2N/A return "$?"
2N/A}
2N/A
2N/Aversion_find_latest ()
2N/A{
2N/A version_find_latest_a=""
2N/A for i in "$@" ; do
2N/A if version_test_gt "$i" "$version_find_latest_a" ; then
2N/A version_find_latest_a="$i"
2N/A fi
2N/A done
2N/A echo "$version_find_latest_a"
2N/A}
2N/A
2N/A# One layer of quotation is eaten by "", the second by sed, and the third by
2N/A# printf; so this turns ' into \'. Note that you must use the output of
2N/A# this function in a printf format string.
2N/Agettext_quoted () {
2N/A "$gettext" "$@" | sed "s/'/'\\\\\\\\''/g"
2N/A}
2N/A
2N/A# Run the first argument through gettext_quoted, and then pass that and all
2N/A# remaining arguments to printf. This is a useful abbreviation and tends to
2N/A# be easier to type.
2N/Agettext_printf () {
2N/A gettext_printf_format="$1"
2N/A shift
2N/A printf "$(gettext_quoted "$gettext_printf_format")" "$@"
2N/A}
2N/A
2N/Auses_abstraction () {
2N/A device="$1"
2N/A
2N/A abstraction="`"${grub_probe}" --device "${device}" --target=abstraction`"
2N/A for module in ${abstraction}; do
2N/A if test "x${module}" = "x$2"; then
2N/A return 0
2N/A fi
2N/A done
2N/A return 1
2N/A}