#!Nsis Installer Command Script # @configure_input@ # To build an installer from the script you would normally do: # # makensis -D{SPICE,OVIRT} win-guest-tools.nsis # # which will generate the output file 'spice-guest-tools-$VERSION.exe' or # 'ovirt-guest-tools-setup.exe' which are Windows # installers containing your program. # # # # Copyright (c) 2012-2017 Red Hat, Inc # Copyright (c) 2017 Lev Veyde # Copyright (c) 2012 Grant Williamson # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. # SetCompressor /SOLID lzma !include "driver.nsh" !include "FileFunc.nsh" !include "WinVer.nsh" !include "x64.nsh" !ifdef SPICE !define FILENAME "spice-guest-tools" !define NAME "SPICE Guest Tools" !define PUBLISHER "The SPICE Project" !define REGKEYNAME "SpiceGuestTools" !define URL "http://spice-space.org" !else ifdef OVIRT !define FILENAME "ovirt-guest-tools-setup" !define NAME "oVirt Guest Tools" !define PUBLISHER "The oVirt Project" !define REGKEYNAME "oVirtGuestTools" !define URL "http://www.ovirt.org/Home" !else !error "OVIRT or SPICE symbol should passed to makensis with the -D flag" !endif !ifndef VERSION !error "-DVERSION= should be passed to makensis, see Makefile" !endif !ifndef DISPLAYED_VERSION !define DISPLAYED_VERSION "${VERSION}" !endif Name "${NAME}" Caption "${NAME} Installer" OutFile "${FILENAME}-${VERSION}.exe" InstallDir "$PROGRAMFILES\${NAME}" BrandingText " " # SilentInstall silent ShowInstDetails nevershow # ShowUninstDetails hide !include "MUI2.nsh" !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE win-driver-license.txt !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_WELCOME !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_UNPAGE_FINISH !insertmacro MUI_LANGUAGE "English" !include "DumpLog.nsh" XPStyle on RequestExecutionLevel admin ComponentText "Select which optional components you want to install." DirText "Please select the installation folder." Section "install" SectionIn RO Call StopServices SetOutPath "$INSTDIR" File "version.txt" !ifdef OVIRT File "bin/vcredist_x86.exe" File "bin/OVirtGuestService.exe" File "bin/ovirt-guest-agent.ini" File "bin/default.ini" File "bin/default-logger.ini" CreateDirectory "$INSTDIR\hooks\after_hibernation" CreateDirectory "$INSTDIR\hooks\before_hibernation" CreateDirectory "$INSTDIR\hooks\after_migration" CreateDirectory "$INSTDIR\hooks\before_migration" ExecWait '"$INSTDIR\vcredist_x86.exe" /q' !endif SetOutPath "$INSTDIR\32" File "bin/vdagent_x86/vdagent.exe" File "bin/vdagent_x86/vdservice.exe" SetOutPath "$INSTDIR\64" File "bin/vdagent_x64/vdagent.exe" File "bin/vdagent_x64/vdservice.exe" SetOutPath "$INSTDIR\drivers" File /r /x *.pdb drivers/virtio/ Push "vioserial" Push "vioser" Push "PCI\VEN_1AF4&DEV_1003&SUBSYS_00031AF4" Call InstallDriver Call InstallQemuGuestAgent ${if} ${AtLeastWin8} Push "qxldod" Push "qxldod" ${else} Push "qxl" Push "qxl" ${endif} Push "PCI\VEN_1b36&DEV_0100&SUBSYS_11001af4" Call InstallDriver Push "Balloon" Push "balloon" Push "PCI\VEN_1AF4&DEV_1002&SUBSYS_00051AF4&REV_00" Call InstallBalloonDriver Push "viostor" Push "viostor" Push "PCI\VEN_1AF4&DEV_1001&SUBSYS_00021AF4&REV_00" Call InstallDriver ${If} ${AtLeastWinVista} Push "vioscsi" Push "vioscsi" Push "PCI\VEN_1AF4&DEV_1004&SUBSYS_00081AF4&REV_00" Call InstallDriver ${EndIf} Push "." Push "qemupciserial" Push "PCI\VEN_1B36&DEV_0002" Call InstallDriver Push "." Push "qemupciserial" Push "PCI\VEN_1B36&DEV_0003" Call InstallDriver Push "." Push "qemupciserial" Push "PCI\VEN_1B36&DEV_0003" Call InstallDriver Push "NetKVM" Push "netkvm" Push "PCI\VEN_1AF4&DEV_1000&SUBSYS_00011AF4&REV_00" Call InstallDriver # Install rng driver ${If} ${AtLeastWinVista} Push "viorng" Push "viorng" Push "PCI\VEN_1AF4&DEV_1005" Call InstallDriver ${EndIf} # Install Q35 smbus driver ${If} ${IsWin2008} Push "smbus" Push "smbus" Push "PCI\VEN_8086&DEV_2930&SUBSYS_11001AF4" Call InstallDriver ${EndIf} # Install Q35 qemufwcfg driver ${If} ${IsWin10} ${OrIf} ${IsWin2016} Push "qemufwcfg" Push "qemufwcfg" Push "ACPI\QEMU0002" Call InstallDriver ${EndIf} !ifdef OVIRT Call InstallOVirtAgentService !endif Call InstallVdAgentService WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "DisplayName" "${NAME} ${DISPLAYED_VERSION}" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "DisplayVersion" "${DISPLAYED_VERSION}" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "Publisher" "${PUBLISHER}" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "URLInfoAbout" "${URL}" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "UninstallString" "$\"$INSTDIR\Uninstall ${FILENAME}$\"" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "QuietUninstallString" "$\"$INSTDIR\Uninstall ${FILENAME}$\" /S" WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "NoModify" "1" WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "NoRepair" "1" ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 IntFmt $0 "0x%08X" $0 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" \ "EstimatedSize" "$0" SectionEnd Section "Uninstall" Call un.StopServices Call un.UninstallServices Call un.UninstallQemuGuestAgent SetOutPath "$TEMP" Delete /rebootok "$INSTDIR\version.txt" Delete /rebootok "$INSTDIR\Uninstall ${FILENAME}.exe" Delete /rebootok "$INSTDIR\32\vdagent.exe" Delete /rebootok "$INSTDIR\32\vdservice.exe" RMDir /rebootok "$INSTDIR\32" Delete /rebootok "$INSTDIR\64\vdagent.exe" Delete /rebootok "$INSTDIR\64\vdservice.exe" RMDir /rebootok "$INSTDIR\64" RMDir /rebootok /r "$INSTDIR\drivers" !ifdef OVIRT Delete /rebootok "$INSTDIR\OVirtGuestService.exe" Delete /rebootok "$INSTDIR\default.ini" Delete /rebootok "$INSTDIR\default-logger.ini" Delete /rebootok "$INSTDIR\ovirt-guest-agent.ini" Delete /rebootok "$INSTDIR\vcredist_x86.exe" RMDir /rebootok "$INSTDIR\hooks\after_hibernation" RMDir /rebootok "$INSTDIR\hooks\before_hibernation" RMDir /rebootok "$INSTDIR\hooks\after_migration" RMDir /rebootok "$INSTDIR\hooks\before_migration" RMDir /rebootok "$INSTDIR\hooks" !endif RMDir /rebootok "$INSTDIR" DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGKEYNAME}" SectionEnd Section -post WriteUninstaller "$INSTDIR\Uninstall ${FILENAME}.exe" # for reference: https://stackoverflow.com/questions/2407509/writing-current-date-time-as-file-name-using-nsis !define /date MyTIMESTAMP "%Y-%m-%d-%H-%M-%S" StrCpy $0 "$INSTDIR\install-${MyTIMESTAMP}.log" Push $0 Call DumpLog SectionEnd Function .onInit ${if} ${RunningX64} ${if} ${IsWinXP} MessageBox MB_ICONEXCLAMATION "Windows XP 64 bit is an unsupported Windows version" Abort ; causes installer to quit. ${endif} ${endif} ${if} ${AtMostWin2000} MessageBox MB_ICONEXCLAMATION "Drivers only available for Windows XP or newer" Abort ; causes installer to quit. ${endif} FunctionEnd Function GetDriverSubdir Pop $0 ${If} ${IsWinXP} StrCpy $0 "$0\xp" ${ElseIf} ${IsWinVista} StrCpy $0 "$0\vista" ${ElseIf} ${IsWin2003} StrCpy $0 "$0\2k3" ${ElseIf} ${IsWin7} StrCpy $0 "$0\w7" ${ElseIf} ${IsWin2008} StrCpy $0 "$0\2k8" ${ElseIf} ${IsWin2008R2} StrCpy $0 "$0\2k8R2" ${ElseIf} ${IsWin8} StrCpy $0 "$0\w8" ${ElseIf} ${IsWin2012} StrCpy $0 "$0\2k12" ${ElseIf} ${IsWin8.1} StrCpy $0 "$0\w8.1" ${ElseIf} ${IsWin2012R2} StrCpy $0 "$0\2k12r2" ${ElseIf} ${IsWin10} StrCpy $0 "$0\w10" ${ElseIf} ${IsWin2016} StrCpy $0 "$0\2k16" ${Else} MessageBox MB_ICONEXCLAMATION "Unsupported Windows version" Abort ; causes installer to quit. ${EndIf} ${If} ${RunningX64} StrCpy $0 "$0\amd64" ${Else} StrCpy $0 "$0\x86" ${EndIf} Push $0 FunctionEnd Function InstallBalloonDriver Call InstallDriver Call InstallBalloonService FunctionEnd Function InstallDriver Pop $R0 ; HID Pop $R1 ; driver name Pop $R2 ; driver path Push $R2 Call GetDriverSubdir Pop $0 StrCpy $1 $R1 Push $1 StrCpy $2 "$INSTDIR\drivers\$0" Push $2 StrCpy $3 "$2\$R1.inf" Push $3 Push $R0 DetailPrint "Installing $R1.inf" Call InstallUpgradeDriver FunctionEnd !macro StopServices un Function ${un}StopService pop $R0 SimpleSC::ServiceIsRunning $R0 pop $0 pop $1 ${if} $0 != 0 # error Return ${endif} ${if} $1 == 0 # service not running Return ${endif} DetailPrint "Stopping $R0" SimpleSC::StopService $R0 1 30 pop $0 ${if} $0 != 0 DetailPrint "Failed to stop $R0: $0" Return ${endif} DetailPrint "$R0 stopped" FunctionEnd Function ${un}StopServices push "vdservice" Call ${un}StopService push "BalloonService" Call ${un}StopService !ifdef OVIRT push "OVirtGuestService" Call ${un}StopService !endif FunctionEnd !macroend !insertmacro StopServices "" !insertmacro StopServices "un." Function un.UninstallService pop $R0 SimpleSC::ExistsService $R0 Pop $0 ${if} $0 == 0 SimpleSC::RemoveService $R0 ${endif} FunctionEnd Function un.UninstallServices push "vdservice" Call un.UninstallService push "BalloonService" Call un.UninstallService !ifdef OVIRT push "OVirtGuestService" Call un.UninstallService !endif FunctionEnd Function InstallService pop $R0 #service name pop $R1 #service path pop $R2 #service pretty name SimpleSC::ExistsService $R0 Pop $0 ${if} $0 == 0 DetailPrint "$R2 service already installed" goto InstallService ${endif} DetailPrint "Installing $R2 service" SimpleSC::InstallService $R0 $R2 16 2 '"$R1"' "" "" "" Pop $0 ${if} $0 != 0 DetailPrint "Failed to install $R2 service: $0" Return ${endif} DetailPrint "$R2 service installed" InstallService: DetailPrint "Starting $R2 service" SimpleSC::StartService $R0 "" 30 Pop $0 ${if} $0 != 0 DetailPrint "Failed to start $R2 service: $0" Return ${endif} DetailPrint "$R2 service started" FunctionEnd Function InstallQemuGuestAgent ${if} ${RunningX64} StrCpy $0 "$INSTDIR\drivers\guest-agent\qemu-ga-x64.msi" ${else} StrCpy $0 "$INSTDIR\drivers\guest-agent\qemu-ga-x86.msi" ${endif} ExecWait '"msiexec.exe" /qn /i "$0"' FunctionEnd Function un.UninstallQemuGuestAgent ${if} ${RunningX64} StrCpy $0 "$INSTDIR\drivers\guest-agent\qemu-ga-x64.msi" ${else} StrCpy $0 "$INSTDIR\drivers\guest-agent\qemu-ga-x86.msi" ${endif} ExecWait '"msiexec.exe" /qn /x "$0"' FunctionEnd Function InstallVdAgentService ${if} ${RunningX64} StrCpy $0 "$INSTDIR\64\vdservice.exe" ${else} StrCpy $0 "$INSTDIR\32\vdservice.exe" ${endif} push "SPICE VDAgent" push $0 push "vdservice" Call InstallService FunctionEnd !ifdef OVIRT Function InstallOVirtAgentService StrCpy $0 "$INSTDIR\OVirtGuestService.exe" push "OVirt Guest Service" push $0 push "OVirtGuestService" Call InstallService FunctionEnd !endif Function InstallBalloonService Push "Balloon" Call GetDriverSubdir Pop $0 StrCpy $0 "$INSTDIR\drivers\$0\blnsvr.exe" Push "Balloon Service" Push $0 Push "BalloonService" Call InstallService FunctionEnd