refactor windows version detection (adding ver 12)
Philip Hands
1 year, 7 months ago
5 | 5 | partition="$1" |
6 | 6 | mpoint="$2" |
7 | 7 | type="$3" |
8 | ||
9 | # this function interleaves a string with dots, thus: | |
10 | # "Windows 11" --> "W.i.n.d.o.w.s. .1.1" | |
11 | dotify() { | |
12 | echo $1 | sed 's/./&./g;s/.$//' | |
13 | } | |
8 | 14 | |
9 | 15 | # This script looks for legacy BIOS bootloaders only. Skip if running UEFI |
10 | 16 | if [ -d /sys/firmware/efi ] && [ ! -f /var/lib/partman/ignore_uefi ]; then |
30 | 36 | for boot in $(item_in_dir boot "$2"); do |
31 | 37 | bcd=$(item_in_dir bcd "$2/$boot") |
32 | 38 | if [ -n "$bcd" ]; then |
33 | if grep -aqs "W.i.n.d.o.w.s. .1.1" "$2/$boot/$bcd"; then | |
34 | long="Windows 11" | |
35 | elif grep -aqs "W.i.n.d.o.w.s. .1.0" "$2/$boot/$bcd"; then | |
36 | long="Windows 10" | |
37 | elif grep -aqs "W.i.n.d.o.w.s. .8" "$2/$boot/$bcd"; then | |
38 | long="Windows 8" | |
39 | elif grep -aqs "W.i.n.d.o.w.s. .7" "$2/$boot/$bcd"; then | |
40 | long="Windows 7" | |
41 | elif grep -aqs "W.i.n.d.o.w.s. .V.i.s.t.a" "$2/$boot/$bcd"; then | |
42 | long="Windows Vista" | |
43 | 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 | |
44 | long="Windows Server 2008 R2" | |
45 | elif grep -aqs "W.i.n.d.o.w.s. .S.e.r.v.e.r. .2.0.0.8." "$2/$boot/$bcd"; then | |
46 | long="Windows Server 2008" | |
47 | 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 | |
48 | long="Windows Recovery Environment" | |
49 | elif grep -aqs "W.i.n.d.o.w.s. .S.e.t.u.p" "$2/$boot/$bcd"; then | |
50 | long="Windows Recovery Environment" | |
51 | else | |
52 | long="Windows Vista" | |
53 | fi | |
39 | found=true | |
54 | 40 | short=Windows |
55 | 41 | |
56 | found=true | |
57 | ||
42 | for v in 12 11 10 8 7 Vista "Server 2008 R2" "Server 2008" "Recovery Environment" "Setup"; do | |
43 | win_v="Windows $v" | |
44 | if grep -aqs "$(dotify "$win_v")" "$2/$boot/$bcd"; then | |
45 | long="$win_v" | |
46 | # Windows Setup is a special case, rename it: | |
47 | [ "$v" != "Setup" ] || long="Windows Recovery Environment" | |
48 | break | |
49 | fi | |
50 | done | |
51 | # if no match found, call it Vista | |
52 | : ${long:="Windows Vista"} | |
58 | 53 | break |
59 | 54 | fi |
60 | 55 | done |