barjac

grub-mkconfig_lib (labels)

Oct 27th, 2010
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. # Helper library for grub-mkconfig
  2. # Copyright (C) 2007,2008,2009 Free Software Foundation, Inc.
  3. #
  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.
  8. #
  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.
  13. #
  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/>.
  16.  
  17. transform="s&^&&;s,grub,grub2,"
  18.  
  19. prefix=/usr
  20. exec_prefix=/usr
  21. datarootdir=${prefix}/share
  22. datadir=/usr/share
  23. bindir=/usr/bin
  24. sbindir=/usr/sbin
  25. pkgdatadir=${datadir}/`echo grub | sed "${transform}"`
  26.  
  27. if test "x$grub_probe" = x; then
  28. grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
  29. fi
  30. if test "x$grub_mkrelpath" = x; then
  31. grub_mkrelpath=${bindir}/`echo grub-mkrelpath | sed ${transform}`
  32. fi
  33.  
  34. grub_warn ()
  35. {
  36. echo "Warning: $@" >&2
  37. }
  38.  
  39. make_system_path_relative_to_its_root ()
  40. {
  41. path="`${grub_mkrelpath} $1`"
  42.  
  43. case "`uname 2>/dev/null`" in
  44. CYGWIN*)
  45. # Cygwin: Check if regular or emulated mount.
  46. if [ -z "$dir" ] || [ "`stat -c %D "$dir/.."`" != 620000 ] ; then
  47. # Reached some mount point not below /cygdrive.
  48. # GRUB does not know Cygwin's emulated mounts,
  49. # convert to Win32 path and remove drive letter.
  50. path=`cygpath -m "$path" | sed -n 's,^[A-Za-z]:,,p'`
  51. test ! -z "$path" || return 1
  52. fi ;;
  53. esac
  54.  
  55. echo "$path"
  56. }
  57.  
  58. is_path_readable_by_grub ()
  59. {
  60. path=$1
  61.  
  62. # abort if path doesn't exist
  63. if test -e $path ; then : ;else
  64. return 1
  65. fi
  66.  
  67. # abort if file is in a filesystem we can't read
  68. if ${grub_probe} -t fs $path > /dev/null 2>&1 ; then : ; else
  69. return 1
  70. fi
  71.  
  72. return 0
  73. }
  74.  
  75. convert_system_path_to_grub_path ()
  76. {
  77. path=$1
  78.  
  79. grub_warn "convert_system_path_to_grub_path() is deprecated. Use prepare_grub_to_access_device() instead."
  80.  
  81. # abort if GRUB can't access the path
  82. if is_path_readable_by_grub ${path} ; then : ; else
  83. return 1
  84. fi
  85.  
  86. if drive=`${grub_probe} -t drive $path` ; then : ; else
  87. return 1
  88. fi
  89.  
  90. if relative_path=`make_system_path_relative_to_its_root $path` ; then : ; else
  91. return 1
  92. fi
  93.  
  94. echo ${drive}${relative_path}
  95. }
  96.  
  97. save_default_entry ()
  98. {
  99. if [ "x${GRUB_SAVEDEFAULT}" = "xtrue" ] ; then
  100. cat << EOF
  101. savedefault
  102. EOF
  103. fi
  104. }
  105.  
  106. prepare_grub_to_access_device ()
  107. {
  108. device=$1
  109.  
  110. # Abstraction modules aren't auto-loaded.
  111. abstraction="`${grub_probe} --device ${device} --target=abstraction`"
  112. for module in ${abstraction} ; do
  113. echo "insmod ${module}"
  114. done
  115.  
  116. fs="`${grub_probe} --device ${device} --target=fs`"
  117. for module in ${fs} ; do
  118. echo "insmod ${module}"
  119. done
  120.  
  121. # If there's a filesystem UUID that GRUB is capable of identifying, use it;
  122. # otherwise set root as per value in device.map.
  123. # If label is available then use label (bcj)
  124. if [ "x${GRUB_DEVICE_LABEL}" != "x" ] && [ "x${GRUB_USE_LABEL}" = "xtrue" ]; then
  125. echo "search --no-floppy --label --set ${GRUB_DEVICE_LABEL}"
  126. else
  127. echo "set root='`${grub_probe} --device ${device} --target=drive`'"
  128. if fs_uuid="`${grub_probe} --device ${device} --target=fs_uuid 2> /dev/null`" ; then
  129. echo "search --no-floppy --fs-uuid --set ${fs_uuid}"
  130. fi
  131. fi
  132. }
  133.  
  134. grub_file_is_not_garbage ()
  135. {
  136. if test -f "$1" ; then
  137. case "$1" in
  138. *.dpkg-*) return 1 ;; # debian dpkg
  139. esac
  140. else
  141. return 1
  142. fi
  143. return 0
  144. }
  145.  
  146. version_test_numeric ()
  147. {
  148. local a=$1
  149. local cmp=$2
  150. local b=$3
  151. if [ "$a" = "$b" ] ; then
  152. case $cmp in
  153. ge|eq|le) return 0 ;;
  154. gt|lt) return 1 ;;
  155. esac
  156. fi
  157. if [ "$cmp" = "lt" ] ; then
  158. c=$a
  159. a=$b
  160. b=$c
  161. fi
  162. if (echo $a ; echo $b) | sort -n | head -n 1 | grep -qx $b ; then
  163. return 0
  164. else
  165. return 1
  166. fi
  167. }
  168.  
  169. version_test_gt ()
  170. {
  171. local a=`echo $1 | sed -e "s/[^-]*-//"`
  172. local b=`echo $2 | sed -e "s/[^-]*-//"`
  173. local cmp=gt
  174. if [ "x$b" = "x" ] ; then
  175. return 0
  176. fi
  177. case $a:$b in
  178. *.old:*.old) ;;
  179. *.old:*) a=`echo -n $a | sed -e s/\.old$//` ; cmp=gt ;;
  180. *:*.old) b=`echo -n $b | sed -e s/\.old$//` ; cmp=ge ;;
  181. esac
  182. version_test_numeric $a $cmp $b
  183. return $?
  184. }
  185.  
  186. version_find_latest ()
  187. {
  188. local a=""
  189. for i in $@ ; do
  190. if version_test_gt "$i" "$a" ; then
  191. a="$i"
  192. fi
  193. done
  194. echo "$a"
  195. }
Add Comment
Please, Sign In to add comment