Skip to content

Commit 5814473

Browse files
authored
feat: Improve OS detection (#1219)
1 parent bfb9c4b commit 5814473

File tree

2 files changed

+129
-76
lines changed

2 files changed

+129
-76
lines changed

src/define.sh

Lines changed: 128 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ addFolder() {
13851385
prepareInstall() {
13861386

13871387
local pid=""
1388+
local file=""
13881389
local dir="$2"
13891390
local desc="$3"
13901391
local driver="$4"
@@ -1436,17 +1437,19 @@ prepareInstall() {
14361437
cp -L "$drivers/NetKVM/$driver/$arch/netkvm.inf" "$dir/\$OEM\$/\$1/Drivers/NetKVM" || return 1
14371438
cp -L "$drivers/NetKVM/$driver/$arch/netkvm.sys" "$dir/\$OEM\$/\$1/Drivers/NetKVM" || return 1
14381439

1439-
if [ ! -f "$target/TXTSETUP.SIF" ]; then
1440+
file=$(find "$target" -maxdepth 1 -type f -iname TXTSETUP.SIF -print -quit)
1441+
1442+
if [ -z "$file" ]; then
14401443
error "The file TXTSETUP.SIF could not be found!" && return 1
14411444
fi
14421445

1443-
sed -i '/^\[SCSI.Load\]/s/$/\nviostor=viostor.sys,4/' "$target/TXTSETUP.SIF"
1444-
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\nviostor.sys=1,,,,,,4_,4,1,,,1,4/' "$target/TXTSETUP.SIF"
1445-
sed -i '/^\[SCSI\]/s/$/\nviostor=\"Red Hat VirtIO SCSI Disk Device\"/' "$target/TXTSETUP.SIF"
1446-
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00000000=\"viostor\"/' "$target/TXTSETUP.SIF"
1447-
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00020000=\"viostor\"/' "$target/TXTSETUP.SIF"
1448-
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00021AF4=\"viostor\"/' "$target/TXTSETUP.SIF"
1449-
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00000000=\"viostor\"/' "$target/TXTSETUP.SIF"
1446+
sed -i '/^\[SCSI.Load\]/s/$/\nviostor=viostor.sys,4/' "$file"
1447+
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\nviostor.sys=1,,,,,,4_,4,1,,,1,4/' "$file"
1448+
sed -i '/^\[SCSI\]/s/$/\nviostor=\"Red Hat VirtIO SCSI Disk Device\"/' "$file"
1449+
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00000000=\"viostor\"/' "$file"
1450+
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00020000=\"viostor\"/' "$file"
1451+
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00021AF4=\"viostor\"/' "$file"
1452+
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_1AF4\&DEV_1001\&SUBSYS_00000000=\"viostor\"/' "$file"
14501453

14511454
if [ ! -d "$drivers/sata/xp/$arch" ]; then
14521455
error "Failed to locate required SATA drivers!" && return 1
@@ -1456,49 +1459,104 @@ prepareInstall() {
14561459
cp -Lr "$drivers/sata/xp/$arch/." "$dir/\$OEM\$/\$1/Drivers/sata" || return 1
14571460
cp -Lr "$drivers/sata/xp/$arch/." "$target" || return 1
14581461

1459-
sed -i '/^\[SCSI.Load\]/s/$/\niaStor=iaStor.sys,4/' "$target/TXTSETUP.SIF"
1460-
sed -i '/^\[FileFlags\]/s/$/\niaStor.sys = 16/' "$target/TXTSETUP.SIF"
1461-
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.cat = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
1462-
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.inf = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
1463-
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.sys = 1,,,,,,4_,4,1,,,1,4/' "$target/TXTSETUP.SIF"
1464-
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.sys = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
1465-
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaahci.cat = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
1466-
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaAHCI.inf = 1,,,,,,,1,0,0/' "$target/TXTSETUP.SIF"
1467-
sed -i '/^\[SCSI\]/s/$/\niaStor=\"Intel\(R\) SATA RAID\/AHCI Controller\"/' "$target/TXTSETUP.SIF"
1468-
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_8086\&DEV_2922\&CC_0106=\"iaStor\"/' "$target/TXTSETUP.SIF"
1462+
sed -i '/^\[SCSI.Load\]/s/$/\niaStor=iaStor.sys,4/' "$file"
1463+
sed -i '/^\[FileFlags\]/s/$/\niaStor.sys = 16/' "$file"
1464+
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.cat = 1,,,,,,,1,0,0/' "$file"
1465+
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.inf = 1,,,,,,,1,0,0/' "$file"
1466+
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.sys = 1,,,,,,4_,4,1,,,1,4/' "$file"
1467+
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaStor.sys = 1,,,,,,,1,0,0/' "$file"
1468+
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaahci.cat = 1,,,,,,,1,0,0/' "$file"
1469+
sed -i '/^\[SourceDisksFiles.'"$arch"'\]/s/$/\niaAHCI.inf = 1,,,,,,,1,0,0/' "$file"
1470+
sed -i '/^\[SCSI\]/s/$/\niaStor=\"Intel\(R\) SATA RAID\/AHCI Controller\"/' "$file"
1471+
sed -i '/^\[HardwareIdsDatabase\]/s/$/\nPCI\\VEN_8086\&DEV_2922\&CC_0106=\"iaStor\"/' "$file"
14691472

14701473
rm -rf "$drivers"
14711474

14721475
fi
14731476

1474-
local setup
1477+
local key setup
14751478
setup=$(find "$target" -maxdepth 1 -type f -iname setupp.ini -print -quit)
14761479

1477-
if [ -n "$setup" ]; then
1480+
if [ -n "$setup" ] && [ -z "$KEY" ]; then
14781481

14791482
pid=$(<"$setup")
14801483
pid="${pid%$'\r'}"
14811484

1482-
case "$pid" in
1483-
*"000" | *"270" | *"OEM" ) ;;
1484-
* ) warn "unknown PID found in image: \"${pid:(-3)}\"" ;;
1485-
esac
1486-
14871485
if [[ "$driver" == "2k" ]]; then
14881486

14891487
echo "${pid:0:$((${#pid})) - 3}270" > "$setup"
14901488

14911489
else
14921490

1493-
if [[ "$pid" != *"270" ]]; then
1494-
echo "${pid:0:$((${#pid})) - 3}000" > "$setup"
1495-
else
1491+
if [[ "$pid" == *"270" ]]; then
1492+
14961493
warn "this version of $desc requires a volume license key (VLK), it will ask for one during installation."
1497-
fi
14981494

1495+
else
1496+
1497+
file=$(find "$target" -maxdepth 1 -type f -iname PID.INF -print -quit)
1498+
1499+
if [ -n "$file" ]; then
1500+
1501+
if [[ "$driver" == "2k3" ]]; then
1502+
1503+
key=$(grep -i -A 2 "StagingKey" "$file" | tail -n 2 | head -n 1)
1504+
1505+
else
1506+
1507+
key="${pid:$((${#pid})) - 8:5}"
1508+
if [[ "${pid^^}" == *"OEM" ]]; then
1509+
key=$(grep -i -A 2 "$key" "$file" | tail -n 2 | head -n 1)
1510+
else
1511+
key=$(grep -i -m 1 -A 2 "$key" "$file" | tail -n 2 | head -n 1)
1512+
fi
1513+
key="${key#*= }"
1514+
1515+
fi
1516+
1517+
key="${key%$'\r'}"
1518+
[[ "${#key}" == "29" ]] && KEY="$key"
1519+
1520+
fi
1521+
1522+
if [ -z "$KEY" ]; then
1523+
1524+
# These are NOT pirated keys, they come from official MS documentation.
1525+
1526+
case "${driver,,}" in
1527+
"xp" )
1528+
1529+
if [[ "${arch,,}" == "x86" ]]; then
1530+
# Windows XP Professional x86 generic trial key (no activation)
1531+
KEY="DR8GV-C8V6J-BYXHG-7PYJR-DB66Y"
1532+
else
1533+
# Windows XP Professional x64 generic trial key (no activation)
1534+
KEY="B2RBK-7KPT9-4JP6X-QQFWM-PJD6G"
1535+
fi ;;
1536+
1537+
"2k3" )
1538+
1539+
if [[ "${arch,,}" == "x86" ]]; then
1540+
# Windows Server 2003 Standard x86 generic trial key (no activation)
1541+
KEY="QKDCQ-TP2JM-G4MDG-VR6F2-P9C48"
1542+
else
1543+
# Windows Server 2003 Standard x64 generic trial key (no activation)
1544+
KEY="P4WJG-WK3W7-3HM8W-RWHCK-8JTRY"
1545+
fi ;;
1546+
1547+
esac
1548+
1549+
echo "${pid:0:$((${#pid})) - 3}000" > "$setup"
1550+
1551+
fi
1552+
1553+
fi
14991554
fi
1555+
15001556
fi
15011557

1558+
[ -n "$KEY" ] && KEY="ProductID=$KEY"
1559+
15021560
mkdir -p "$dir/\$OEM\$"
15031561

15041562
if ! addFolder "$dir"; then
@@ -1527,36 +1585,6 @@ prepareInstall() {
15271585
local ip="20.20.20.1"
15281586
[ -n "${VM_NET_IP:-}" ] && ip="${VM_NET_IP%.*}.1"
15291587

1530-
if [ -z "$KEY" ] && [[ "$pid" != *"270" ]]; then
1531-
1532-
# These are not pirated keys, they come from the official MS documentation.
1533-
case "${driver,,}" in
1534-
"xp" )
1535-
1536-
if [[ "${arch,,}" == "x86" ]]; then
1537-
# Windows XP Professional x86 generic key (no activation, trial-only)
1538-
KEY="DR8GV-C8V6J-BYXHG-7PYJR-DB66Y"
1539-
else
1540-
# Windows XP Professional x64 generic key (no activation, trial-only)
1541-
KEY="B2RBK-7KPT9-4JP6X-QQFWM-PJD6G"
1542-
fi ;;
1543-
1544-
"2k3" )
1545-
1546-
if [[ "${arch,,}" == "x86" ]]; then
1547-
# Windows Server 2003 Standard x86 generic key (no activation, trial-only)
1548-
KEY="QKDCQ-TP2JM-G4MDG-VR6F2-P9C48"
1549-
else
1550-
# Windows Server 2003 Standard x64 generic key (no activation, trial-only)
1551-
KEY="P4WJG-WK3W7-3HM8W-RWHCK-8JTRY"
1552-
fi ;;
1553-
1554-
esac
1555-
1556-
fi
1557-
1558-
[ -n "$KEY" ] && KEY="ProductID=$KEY"
1559-
15601588
find "$target" -maxdepth 1 -type f -iname winnt.sif -exec rm {} \;
15611589

15621590
{ echo "[Data]"
@@ -1786,34 +1814,59 @@ prepareLegacy() {
17861814
detectLegacy() {
17871815

17881816
local dir="$1"
1789-
local find find2
1817+
local find
17901818

1791-
find=$(find "$dir" -maxdepth 1 -type d -iname win95 -print -quit)
1819+
find=$(find "$dir" -maxdepth 1 -type d -iname WIN95 -print -quit)
17921820
[ -n "$find" ] && DETECTED="win95" && return 0
17931821

1794-
find=$(find "$dir" -maxdepth 1 -type d -iname win98 -print -quit)
1822+
find=$(find "$dir" -maxdepth 1 -type d -iname WIN98 -print -quit)
17951823
[ -n "$find" ] && DETECTED="win98" && return 0
17961824

1797-
find=$(find "$dir" -maxdepth 1 -type d -iname win9x -print -quit)
1825+
find=$(find "$dir" -maxdepth 1 -type d -iname WIN9X -print -quit)
17981826
[ -n "$find" ] && DETECTED="win9x" && return 0
17991827

1800-
find=$(find "$dir" -maxdepth 1 -type f -iname cdrom_nt.5 -print -quit)
1801-
[ -n "$find" ] && DETECTED="win2k" && return 0
1828+
find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_W.40 -print -quit)
1829+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_S.40 -print -quit)
1830+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_TS.40 -print -quit)
1831+
[ -n "$find" ] && DETECTED="winnt4" && return 0
18021832

1803-
find=$(find "$dir" -maxdepth 1 -type d -iname win51 -print -quit)
1804-
find2=$(find "$dir" -maxdepth 1 -type f -iname setupxp.htm -print -quit)
1833+
find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_NT.5 -print -quit)
18051834

1806-
if [ -n "$find" ] || [ -n "$find2" ] || [ -f "$dir/WIN51AP" ] || [ -f "$dir/WIN51IC" ]; then
1807-
[ -d "$dir/AMD64" ] && DETECTED="winxpx64" && return 0
1808-
DETECTED="winxpx86" && return 0
1809-
fi
1835+
if [ -n "$find" ]; then
1836+
1837+
find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_IA.5 -print -quit)
1838+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_ID.5 -print -quit)
1839+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_IP.5 -print -quit)
1840+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname CDROM_IS.5 -print -quit)
1841+
[ -n "$find" ] && DETECTED="win2k" && return 0
18101842

1811-
if [ -f "$dir/WIN51IA" ] || [ -f "$dir/WIN51IB" ] || [ -f "$dir/WIN51ID" ] || [ -f "$dir/WIN51IL" ] || [ -f "$dir/WIN51IS" ]; then
1812-
DETECTED="win2003r2" && return 0
18131843
fi
18141844

1815-
if [ -f "$dir/WIN51AA" ] || [ -f "$dir/WIN51AD" ] || [ -f "$dir/WIN51AS" ] || [ -f "$dir/WIN51MA" ] || [ -f "$dir/WIN51MD" ]; then
1816-
DETECTED="win2003r2" && return 0
1845+
find=$(find "$dir" -maxdepth 1 -iname WIN51 -print -quit)
1846+
1847+
if [ -n "$find" ]; then
1848+
1849+
find=$(find "$dir" -maxdepth 1 -type f -iname WIN51AP -print -quit)
1850+
[ -n "$find" ] && DETECTED="winxpx64" && return 0
1851+
1852+
find=$(find "$dir" -maxdepth 1 -type f -iname WIN51IC -print -quit)
1853+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51IP -print -quit)
1854+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname setupxp.htm -print -quit)
1855+
[ -n "$find" ] && DETECTED="winxpx86" && return 0
1856+
1857+
find=$(find "$dir" -maxdepth 1 -type f -iname WIN51IS -print -quit)
1858+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51IA -print -quit)
1859+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51IB -print -quit)
1860+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51ID -print -quit)
1861+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51IL -print -quit)
1862+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51IS -print -quit)
1863+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51AA -print -quit)
1864+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51AD -print -quit)
1865+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51AS -print -quit)
1866+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51MA -print -quit)
1867+
[ -z "$find" ] && find=$(find "$dir" -maxdepth 1 -type f -iname WIN51MD -print -quit)
1868+
[ -n "$find" ] && DETECTED="win2003r2" && return 0
1869+
18171870
fi
18181871

18191872
return 1

src/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ detectCustom() {
266266

267267
! findFile "custom.iso" && return 1
268268
[ -n "$CUSTOM" ] && return 0
269-
269+
270270
! findFile "boot.iso" && return 1
271271
[ -n "$CUSTOM" ] && return 0
272272

0 commit comments

Comments
 (0)