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 if [ "x${abstraction}" = "x" ] ; then : ; else
140 echo "insmod ${abstraction}"
143 # If there's a filesystem UUID that GRUB is capable of identifying, use it;
144 # otherwise set root as per value in device.map.
145 echo "set root=`${grub_probe} --device ${device} --target=drive`"
146 if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
147 echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
153 for dir in ${pkgdatadir} /boot/grub /usr/share/grub ; do
154 # FIXME: We prefer ascii because loading complete fonts is too slow (and
155 # we don't yet provide the gettext magic that would make unicode useful).
156 for basename in ascii unicode unifont ; do
157 path="${dir}/${basename}.pf2"
158 if is_path_readable_by_grub ${path} > /dev/null ; then
168 grub_file_is_not_garbage ()
170 if test -f "$1" ; then
172 *.dpkg-dist|*.dpkg-old|*.dpkg-tmp) return 1 ;; # debian dpkg