1 # Helper library for grub-mkconfig
2 # Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
4 # GRUB is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # GRUB is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 transform="@program_transform_name@"
20 exec_prefix=@exec_prefix@
21 datarootdir=@datarootdir@
24 pkgdatadir=${datadir}/`echo @PACKAGE_TARNAME@ | sed "${transform}"`
26 grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
30 echo "Warning: $@" >&2
33 make_system_path_relative_to_its_root ()
36 # abort if file doesn't exist
37 if test -e $path ; then : ;else
42 if path=`readlink -f $path` ; then : ; else
46 # if not a directory, climb up to the directory containing it
47 if test -d $path ; then
50 dir=`echo $path | sed -e "s,/[^/]*$,,g"`
55 # this loop sets $dir to the root directory of the filesystem we're inspecting
57 parent=`readlink -f $dir/..`
58 if [ "x`stat -c %d $parent`" = "x$num" ] ; then : ; else
59 # $parent is another filesystem; we found it.
62 if [ "x$dir" = "x/" ] ; then
69 # This function never prints trailing slashes (so that its output can be
70 # appended a slash unconditionally). Each slash in $dir is considered a
71 # preceding slash, and therefore the root directory is an empty string.
72 if [ "$dir" = "/" ] ; then
76 # XXX: This fails if $dir contains ','.
77 path=`echo "$path" | sed -e "s,^$dir,,g"` || return 1
79 case "`uname 2>/dev/null`" in
81 # Cygwin: Check if regular or emulated mount.
82 if [ -z "$dir" ] || [ "`stat -c %D "$dir/.."`" != 620000 ] ; then
83 # Reached some mount point not below /cygdrive.
84 # GRUB does not know Cygwin's emulated mounts,
85 # convert to Win32 path and remove drive letter.
86 path=`cygpath -m "$path" | sed -n 's,^[A-Za-z]:,,p'`
87 test ! -z "$path" || return 1
94 is_path_readable_by_grub ()
98 # abort if path doesn't exist
99 if test -e $path ; then : ;else
103 # abort if file is in a filesystem we can't read
104 if ${grub_probe} -t fs $path > /dev/null 2>&1 ; then : ; else
111 convert_system_path_to_grub_path ()
115 grub_warn "convert_system_path_to_grub_path() is deprecated. Use prepare_grub_to_access_device() instead."
117 # abort if GRUB can't access the path
118 if is_path_readable_by_grub ${path} ; then : ; else
122 if drive=`${grub_probe} -t drive $path` ; then : ; else
126 if relative_path=`make_system_path_relative_to_its_root $path` ; then : ; else
130 echo ${drive}${relative_path}
133 prepare_grub_to_access_device ()
137 # Abstraction modules aren't auto-loaded.
138 abstraction="`${grub_probe} --device ${device} --target=abstraction`"
139 for module in ${abstraction} ; do
140 echo "insmod ${module}"
143 fs="`${grub_probe} --device ${device} --target=fs`"
144 for module in ${fs} ; do
145 echo "insmod ${module}"
148 # If there's a filesystem UUID that GRUB is capable of identifying, use it;
149 # otherwise set root as per value in device.map.
150 echo "set root=`${grub_probe} --device ${device} --target=drive`"
151 if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
152 echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
156 grub_file_is_not_garbage ()
158 if test -f "$1" ; then
160 *.dpkg-*) return 1 ;; # debian dpkg
168 version_test_numeric ()
173 if [ "$a" = "$b" ] ; then
175 ge|eq|le) return 0 ;;
179 if [ "$cmp" = "lt" ] ; then
184 if (echo $a ; echo $b) | sort -n | head -n 1 | grep -qx $b ; then
193 local a=`echo $1 | sed -e "s/[^-]*-//"`
194 local b=`echo $2 | sed -e "s/[^-]*-//"`
196 if [ "x$b" = "x" ] ; then
201 *.old:*) a=`echo -n $a | sed -e s/\.old$//` ; cmp=gt ;;
202 *:*.old) b=`echo -n $b | sed -e s/\.old$//` ; cmp=ge ;;
204 version_test_numeric $a $cmp $b
208 version_find_latest ()
212 if version_test_gt "$i" "$a" ; then