20microsoft 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #!/bin/sh
  2. # Detects all Microsoft OSes on a collection of partitions.
  3. . /usr/share/os-prober/common.sh
  4. partition="$1"
  5. mpoint="$2"
  6. type="$3"
  7. # This script looks for legacy BIOS bootloaders only. Skip if running UEFI
  8. if [ -d /sys/firmware/efi ] && [ ! -f /var/lib/partman/ignore_uefi ] && [ -z "$WINOSDATA" ]; then
  9. debug "Skipping legacy bootloaders on UEFI system"
  10. exit 1
  11. fi
  12. # Weed out stuff that doesn't apply to us
  13. case "$type" in
  14. ntfs|ntfs-3g) debug "$1 is a NTFS partition" ;;
  15. vfat) debug "$1 is a FAT32 partition" ;;
  16. msdos) debug "$1 is a FAT16 partition" ;;
  17. fat) debug "$1 is a FAT partition (mounted by GRUB)" ;;
  18. fuse|fuseblk) debug "$1 is a FUSE partition" ;; # might be ntfs-3g
  19. *) debug "$1 is not a MS partition: exiting"; exit 1 ;;
  20. esac
  21. found=
  22. # Vista (previously Longhorn)
  23. if item_in_dir -q bootmgr "$2"; then
  24. # there might be different boot directories in different case as:
  25. # boot Boot BOOT
  26. for boot in $(item_in_dir boot "$2"); do
  27. bcd=$(item_in_dir bcd "$2/$boot")
  28. if [ -n "$bcd" ]; then
  29. if grep -aqs "W.i.n.d.o.w.s. .1.0" "$2/$boot/$bcd"; then
  30. long="Windows 10"
  31. elif grep -aqs "W.i.n.d.o.w.s. .8" "$2/$boot/$bcd"; then
  32. long="Windows 8"
  33. elif grep -aqs "W.i.n.d.o.w.s. .7" "$2/$boot/$bcd"; then
  34. long="Windows 7"
  35. elif grep -aqs "W.i.n.d.o.w.s. .V.i.s.t.a" "$2/$boot/$bcd"; then
  36. long="Windows Vista"
  37. elif grep -aqs "W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8. .R.2." "$2/$boot/$bcd"; then
  38. long="Windows Server 2008 R2"
  39. elif grep -aqs "W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8." "$2/$boot/$bcd"; then
  40. long="Windows Server 2008"
  41. elif grep -aqs "W.i.n.d.o.w.s. .R.e.c.o.v.e.r.y. .E.n.v.i.r.o.n.m.e.n.t" "$2/$boot/$bcd"; then
  42. long="Windows Recovery Environment"
  43. elif grep -aqs "W.i.n.d.o.w.s. .S.e.t.u.p" "$2/$boot/$bcd"; then
  44. long="Windows Recovery Environment"
  45. else
  46. long="Windows Vista"
  47. fi
  48. short=Windows
  49. found=true
  50. break
  51. fi
  52. done
  53. fi
  54. # 2000/XP/NT4.0
  55. if [ -z "$found" ] && item_in_dir -q ntldr "$2" && item_in_dir -q ntdetect.com "$2"; then
  56. long="Windows NT/2000/XP"
  57. short=Windows
  58. ini=$(item_in_dir boot.ini "$2")
  59. if [ -n "$ini" ]; then
  60. multicount="$(grep -e "^multi" "$2/$ini" | wc -l)"
  61. scsicount="$(grep -e "^scsi" "$2/$ini" | wc -l)"
  62. msoscount="$(expr "${multicount}" + "${scsicount}")"
  63. if [ "$msoscount" -eq 1 ]; then
  64. # We need to remove a Carriage Return at the end of
  65. # the line...
  66. defaultmspart="$(grep -e "^default=" "$2/$ini" | cut -d '=' -f2 | tr -d '\r')"
  67. # Escape any backslashes in defaultmspart
  68. grepexp="^$(echo "$defaultmspart" | sed -e 's/\\/\\\\/')="
  69. # Colons not allowed; replace by spaces
  70. # Accented characters (non UTF-8) cause debconf to
  71. # hang, so we fall back to the default if the name
  72. # contains any weird characters.
  73. long="$(grep -e "$grepexp" "$2/$ini" | cut -d '"' -f2 | \
  74. tr ':' ' ' | LC_ALL=C grep -v '[^a-zA-Z0-9 &()/_-]')"
  75. if [ -z "$long" ]; then
  76. long="Windows NT/2000/XP"
  77. fi
  78. else
  79. long="Windows NT/2000/XP"
  80. fi
  81. found=true
  82. fi
  83. fi
  84. # MS-DOS
  85. if [ -z "$found" ] && item_in_dir -q dos "$2"; then
  86. long="MS-DOS 5.x/6.x/Win3.1"
  87. short=MS-DOS
  88. found=true
  89. fi
  90. # 95/98/Me
  91. if [ -z "$found" ] && item_in_dir -q windows "$2" &&
  92. item_in_dir -q win.com "$2"/"$(item_in_dir windows "$2")"; then
  93. long="Windows 95/98/Me"
  94. short=Windows9xMe
  95. found=true
  96. fi
  97. # Restrict to partitions containing the OS
  98. if [ -n "$WINOSDATA" ]; then
  99. found=
  100. if grep -aqs '^ *MaxVersionTested="10\.0\.[0-9][0-9][0-9][0-9][0-9]\.[0-9]" />' $2/Windows/SystemApps/Microsoft.Windows.FileExplorer_*/AppxManifest.xml; then
  101. long=${long:-"Windows 10 (data)"}
  102. short=${short:-"Windows"}
  103. found=true
  104. elif [ -d "$2/ProgramData/Microsoft/Windows/Start Menu/Programs/StartUp" ]; then
  105. long=${long:-"Windows 8 (data)"}
  106. short=${short:-"Windows"}
  107. found=true
  108. elif [ -d "$2/ProgramData/Microsoft/Windows/Start Menu/Programs/Startup" ]; then
  109. long=${long:-"Windows 7 (data)"}
  110. short=${short:-"Windows"}
  111. found=true
  112. elif [ -d "$2/Documents and Settings/All Users/Start Menu/Programs/Startup" ]; then
  113. long=${long:-"Windows XP/Vista (data)"}
  114. short=${short:-"Windows"}
  115. found=true
  116. elif [ -d "$2/Winnt/Profiles/All Users/Start Menu/Programs/Startup" ]; then
  117. long=${long:-"Windows NT (data)"}
  118. short=${short:-"Windows"}
  119. found=true
  120. fi
  121. fi
  122. if [ -z "$found" ]; then
  123. exit 1
  124. fi
  125. label="$(count_next_label "$short")"
  126. result "${partition}:${long}:${label}:chain"
  127. exit 0