40grub 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/sh
  2. . /usr/share/os-prober/common.sh
  3. set -e
  4. partition="$1"
  5. bootpart="$2"
  6. mpoint="$3"
  7. type="$4"
  8. found_item=0
  9. entry_result () {
  10. if [ "$ignore_item" = 0 ] && \
  11. [ -n "$kernel" ] && \
  12. [ -e "$mpoint/$kernel" ]; then
  13. result "$rootpart:$bootpart:$title:$kernel:$initrd:$parameters"
  14. found_item=1
  15. fi
  16. kernel=""
  17. parameters=""
  18. initrd=""
  19. title=""
  20. ignore_item=0
  21. }
  22. parse_grub_menu () {
  23. mpoint="$1"
  24. rootpart="$2"
  25. bootpart="$3"
  26. kernel=""
  27. parameters=""
  28. initrd=""
  29. title=""
  30. ignore_item=0
  31. while read line; do
  32. #debug "parsing: $line"
  33. set -f
  34. set -- $line
  35. set +f
  36. case "$1" in
  37. title)
  38. entry_result
  39. shift 1
  40. title="$(echo "$@" | sed 's/://g')"
  41. if echo "$title" | grep -q '(on /dev/[^)]*)$'; then
  42. log "Skipping entry '$title':"
  43. log "appears to be an automatic reference taken from another menu.lst"
  44. ignore_item=1
  45. fi
  46. ;;
  47. kernel)
  48. # Hack alert: sed off any (hdn,n) but
  49. # assume the kernel is on the same
  50. # partition.
  51. kernel="$(echo "$2" | sed 's/(.*)//')"
  52. shift 2
  53. parameters="$@"
  54. # Systems with a separate /boot will not have
  55. # the path to the kernel in menu.lst.
  56. if [ "$partition" != "$bootpart" ]; then
  57. kernel="/boot$kernel"
  58. fi
  59. ;;
  60. initrd)
  61. # Hack alert take 2: sed off any (hdn,n)
  62. # See #566102
  63. initrd="$(echo "$2" | sed 's/(.*)//')"
  64. # Initrd same.
  65. if [ "$partition" != "$bootpart" ]; then
  66. initrd="/boot$initrd"
  67. fi
  68. ;;
  69. boot)
  70. entry_result
  71. ;;
  72. module)
  73. log "Skipping entry '$title':"
  74. log "parsing of entries containing 'module' lines is currently not supported"
  75. ignore_item=1
  76. ;;
  77. esac
  78. done
  79. entry_result
  80. }
  81. grubconf=
  82. if [ -e "$mpoint/boot/grub/menu.lst" ]; then
  83. grubconf="menu.lst"
  84. elif [ -e "$mpoint/boot/grub/grub.conf" ]; then
  85. grubconf="grub.conf"
  86. fi
  87. if [ "$grubconf" ] && \
  88. ([ ! -e "$mpoint/boot/grub/grub.cfg" ] || \
  89. [ "$mpoint/boot/grub/$grubconf" -nt "$mpoint/boot/grub/grub.cfg" ]); then
  90. debug "parsing $grubconf"
  91. parse_grub_menu "$mpoint" "$partition" "$bootpart" < "$mpoint/boot/grub/$grubconf"
  92. fi
  93. if [ "$found_item" = 0 ]; then
  94. exit 1
  95. else
  96. exit 0
  97. fi