summaryrefslogtreecommitdiff
path: root/win-guest-tools.nsis
blob: 400e551d4ddb9b939afec48605718caf441df440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
#!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 <lveyde@redhat.com>
# Copyright (c) 2012 Grant Williamson <grant.williamson@gmail.com>
#
# 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=<version> 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