#! /bin/bash set -ex ORIGIN="$1" VM_NAME=win10 # from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/ wget --continue https://az792536.vo.msecnd.net/vms/VMBuild_20180425/VMWare/MSEdge/MSEdge.Win10.VMWare.zip -O MSEdge.Win10.VMWare.zip # from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ wget --continue https://download.microsoft.com/download/F/8/A/F8AF50AB-3C3A-4BC4-8773-DC27B32988DD/MicrosoftWebDriver.exe -O MicrosoftWebDriver.exe wget --continue http://javadl.oracle.com/webapps/download/AutoDL?BundleId=233172_512cd62ec5174c3487ac17c61aaa89e8 -O java-installer.exe # from https://selenium-release.storage.googleapis.com/ wget --continue https://selenium-release.storage.googleapis.com/3.13/selenium-server-standalone-3.13.0.jar -O selenium.jar wget --continue https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.141-1/virtio-win.iso -O virtio-win.iso [ -e disk.vmdk ] || unzip -o MSEdge.Win10.VMWare.zip cat <<'EOF' > Autorun.inf [autorun] open=install.bat label=Selenium installer EOF cat <<'EOF' > selenium.bat powershell -Command "while (!(Get-NetIPAddress -AddressFamily ipv4 | Where-Object IPAddress -eq '10.111.112.10')) { sleep 2 }" timeout 10 START "hub" java -jar C:\selenium\selenium.jar -role hub timeout 20 java -Dwebdriver.edge.driver=c:\selenium\MicrosoftWebDriver.exe -jar C:\selenium\selenium.jar -role node -hub http://localhost:4444/grid/register -browser browserName="MicrosoftEdge",platform=WINDOWS timeout 50 EOF cat <<'EOF' > install.bat net file 1>nul 2>nul && goto :run || powershell -ex unrestricted -Command "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c %~fnx0 %*'" goto :eof :run netsh advfirewall firewall add rule name="Open Port 4444" dir=in action=allow protocol=TCP localport=4444 netsh advfirewall firewall add rule name="Open Port 5555" dir=in action=allow protocol=TCP localport=5555 netsh advfirewall set allprofiles state off pnputil.exe -i -a E:\qxldod\w10\amd64\qxldod.inf mkdir c:\selenium echo f | xcopy /f /y d:\selenium.jar c:\selenium\selenium.jar echo f | xcopy /f /y d:\selenium.bat c:\selenium\selenium.bat echo f | xcopy /f /y d:\MicrosoftWebDriver.exe c:\selenium\MicrosoftWebDriver.exe REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "Selenium Hub" /t REG_SZ /F /D "C:\selenium\selenium.bat" d:\java-installer.exe /s timeout 30 shutdown -s -t 0 EOF CR=$(printf '\r') sed -i "s/\$/$CR/" *.bat Autorun.inf genisoimage -output wininit.iso -volid cidata -joliet *.bat *.exe selenium.jar Autorun.inf echo "Converting vmdk to qcow2..." qemu-img convert -f vmdk -O qcow2 disk.vmdk "$ORIGIN" virsh destroy "$VM_NAME" || true virsh undefine --nvram "$VM_NAME" || true virt-install -n "$VM_NAME" -r 4000 --vcpus=4 --os-variant=win10 \ --disk "$ORIGIN",device=disk --network user --boot uefi \ --noautoconsole --wait=-1 --noreboot \ --disk wininit.iso,device=cdrom \ --disk virtio-win.iso,device=cdrom virsh start "$VM_NAME" echo "Manual part of installation, open graphics console and run D:\install.bat" set +x while [[ $(virsh domstate "$VM_NAME") =~ 'running' ]]; do sleep 2 done set -x echo "Installation finished"