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