]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/installer.nsi
import smartmontools 7.0
[mirror_smartmontools-debian.git] / os_win32 / installer.nsi
1 ;
2 ; os_win32/installer.nsi - smartmontools install NSIS script
3 ;
4 ; Home page of code is: http://www.smartmontools.org
5 ;
6 ; Copyright (C) 2006-17 Christian Franke
7 ;
8 ; SPDX-License-Identifier: GPL-2.0-or-later
9 ;
10 ; $Id: installer.nsi 4760 2018-08-19 18:45:53Z chrfranke $
11 ;
12
13
14 ;--------------------------------------------------------------------
15 ; Command line arguments:
16 ; makensis -DINPDIR=<input-dir> -DINPDIR64=<input-dir-64-bit> \
17 ; -DOUTFILE=<output-file> -DVERSTR=<version-string> installer.nsi
18
19 !ifndef INPDIR
20 !define INPDIR "."
21 !endif
22
23 !ifndef OUTFILE
24 !define OUTFILE "smartmontools.win32-setup.exe"
25 !endif
26
27 ;--------------------------------------------------------------------
28 ; General
29
30 Name "smartmontools"
31 OutFile "${OUTFILE}"
32
33 RequestExecutionLevel admin
34
35 SetCompressor /solid lzma
36
37 XPStyle on
38 InstallColors /windows
39
40 ; Set in .onInit
41 ;InstallDir "$PROGRAMFILES\smartmontools"
42 ;InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation"
43
44 !ifdef VERSION
45 VIProductVersion "${VERSION}"
46 VIAddVersionKey /LANG=1033-English "CompanyName" "www.smartmontools.org"
47 VIAddVersionKey /LANG=1033-English "FileDescription" "SMART Monitoring Tools"
48 VIAddVersionKey /LANG=1033-English "FileVersion" "${VERSION}"
49 !ifdef YY
50 VIAddVersionKey /LANG=1033-English "LegalCopyright" "(C) 2002-20${YY}, Bruce Allen, Christian Franke, www.smartmontools.org"
51 !endif
52 VIAddVersionKey /LANG=1033-English "OriginalFilename" "${OUTFILE}"
53 VIAddVersionKey /LANG=1033-English "ProductName" "smartmontools"
54 VIAddVersionKey /LANG=1033-English "ProductVersion" "${VERSION}"
55 !endif
56
57 Var EDITOR
58
59 !ifdef INPDIR64
60 Var X64
61 Var INSTDIR32
62 Var INSTDIR64
63 !endif
64
65 LicenseData "${INPDIR}\doc\COPYING.txt"
66
67 !include "FileFunc.nsh"
68 !include "LogicLib.nsh"
69 !include "Sections.nsh"
70
71
72 ;--------------------------------------------------------------------
73 ; Pages
74
75 Page license
76 Page components
77 !ifdef INPDIR64
78 Page directory CheckX64
79 !else
80 Page directory
81 !endif
82 Page instfiles
83
84 UninstPage uninstConfirm
85 UninstPage instfiles
86
87 InstType "Full"
88 InstType "Extract files only"
89 InstType "Drive menu"
90 !ifdef INPDIR64
91 InstType "Full (x64)"
92 InstType "Extract files only (x64)"
93 InstType "Drive menu (x64)"
94 !endif
95
96
97 ;--------------------------------------------------------------------
98 ; Sections
99
100 !ifdef INPDIR64
101 Section "64-bit version" X64_SECTION
102 SectionIn 4 5 6
103 ; Handled in Function CheckX64
104 SectionEnd
105
106 !define FULL_TYPES "1 4"
107 !define EXTRACT_TYPES "2 5"
108 !define DRIVEMENU_TYPE "3 6"
109 !else
110 !define FULL_TYPES "1"
111 !define EXTRACT_TYPES "2"
112 !define DRIVEMENU_TYPE "3"
113 !endif
114
115 SectionGroup "!Program files"
116
117 !macro FileExe path option
118 !ifdef INPDIR64
119 ; Use dummy SetOutPath to control archive location of executables
120 ${If} $X64 != ""
121 Goto +2
122 SetOutPath "$INSTDIR\bin64"
123 File ${option} '${INPDIR64}\${path}'
124 ${Else}
125 Goto +2
126 SetOutPath "$INSTDIR\bin"
127 File ${option} '${INPDIR}\${path}'
128 ${EndIf}
129 !else
130 File ${option} '${INPDIR}\${path}'
131 !endif
132 !macroend
133
134 Section "smartctl" SMARTCTL_SECTION
135
136 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
137
138 SetOutPath "$INSTDIR\bin"
139 !insertmacro FileExe "bin\smartctl.exe" ""
140
141 SectionEnd
142
143 Section "smartd" SMARTD_SECTION
144
145 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
146
147 SetOutPath "$INSTDIR\bin"
148
149 ; Stop service ?
150 StrCpy $1 ""
151 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
152 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
153 ${If} $0 != ""
154 ExecWait "net stop smartd" $1
155 ${EndIf}
156 ${EndIf}
157 !insertmacro FileExe "bin\smartd.exe" ""
158
159 IfFileExists "$INSTDIR\bin\smartd.conf" 0 +2
160 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Replace existing configuration file$\n$INSTDIR\bin\smartd.conf ?" /SD IDNO IDYES 0 IDNO +2
161 File "${INPDIR}\doc\smartd.conf"
162
163 File "${INPDIR}\bin\smartd_mailer.ps1"
164 File "${INPDIR}\bin\smartd_mailer.conf.sample.ps1"
165 File "${INPDIR}\bin\smartd_warning.cmd"
166 !insertmacro FileExe "bin\wtssendmsg.exe" ""
167
168 ; Restart service ?
169 ${If} $1 == "0"
170 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Restart smartd service ?" /SD IDNO IDYES 0 IDNO +2
171 ExecWait "net start smartd"
172 ${EndIf}
173
174 SectionEnd
175
176 Section "smartctl-nc (GSmartControl)" SMARTCTL_NC_SECTION
177
178 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
179
180 SetOutPath "$INSTDIR\bin"
181 !insertmacro FileExe "bin\smartctl-nc.exe" ""
182
183 SectionEnd
184
185 Section "drivedb.h (Drive Database)" DRIVEDB_SECTION
186
187 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
188
189 SetOutPath "$INSTDIR\bin"
190 File "${INPDIR}\bin\drivedb.h"
191 File "${INPDIR}\bin\update-smart-drivedb.exe"
192
193 SectionEnd
194
195 SectionGroupEnd
196
197 Section "!Documentation" DOC_SECTION
198
199 SectionIn ${FULL_TYPES} ${EXTRACT_TYPES}
200
201 SetOutPath "$INSTDIR\doc"
202 File "${INPDIR}\doc\AUTHORS.txt"
203 File "${INPDIR}\doc\ChangeLog.txt"
204 File "${INPDIR}\doc\ChangeLog-5.0-6.0.txt"
205 File "${INPDIR}\doc\COPYING.txt"
206 File "${INPDIR}\doc\INSTALL.txt"
207 File "${INPDIR}\doc\NEWS.txt"
208 File "${INPDIR}\doc\README.txt"
209 File "${INPDIR}\doc\TODO.txt"
210 !ifdef INPDIR64
211 ${If} $X64 != ""
212 File "${INPDIR64}\doc\checksums64.txt"
213 ${Else}
214 File "${INPDIR}\doc\checksums32.txt"
215 ${EndIf}
216 !else
217 File "${INPDIR}\doc\checksums??.txt"
218 !endif
219 File "${INPDIR}\doc\smartctl.8.html"
220 File "${INPDIR}\doc\smartctl.8.pdf"
221 Delete "$INSTDIR\doc\smartctl.8.txt" ; TODO: Remove after smartmontools 6.6
222 File "${INPDIR}\doc\smartd.8.html"
223 File "${INPDIR}\doc\smartd.8.pdf"
224 Delete "$INSTDIR\doc\smartd.8.txt" ; TODO: Remove after smartmontools 6.6
225 File "${INPDIR}\doc\smartd.conf"
226 File "${INPDIR}\doc\smartd.conf.5.html"
227 File "${INPDIR}\doc\smartd.conf.5.pdf"
228 Delete "$INSTDIR\doc\smartd.conf.5.txt" ; TODO: Remove after smartmontools 6.6
229
230 SectionEnd
231
232 Section "Uninstaller" UNINST_SECTION
233
234 SectionIn ${FULL_TYPES}
235 AddSize 40
236
237 CreateDirectory "$INSTDIR"
238
239 ; Remove old "Install_Dir" registry entry (smartmontools < r3911/6.3)
240 ; No longer needed for GSmartControl
241 DeleteRegKey HKLM "Software\smartmontools" ; TODO: Remove after smartmontools 6.7
242
243 ; Write uninstall keys and program
244 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayName" "smartmontools"
245 !ifdef VERSTR
246 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayVersion" "${VERSTR}"
247 !endif
248 ; Important: GSmartControl (>= 1.0.0) reads "InstallLocation" to detect location of bin\smartctl-nc.exe
249 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation" "$INSTDIR"
250 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "UninstallString" '"$INSTDIR\uninst-smartmontools.exe"'
251 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "Publisher" "smartmontools.org"
252 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "URLInfoAbout" "https://www.smartmontools.org/"
253 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "HelpLink" "https://www.smartmontools.org/wiki/Help"
254 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "URLUpdateInfo" "https://builds.smartmontools.org/"
255 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoModify" 1
256 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoRepair" 1
257 WriteUninstaller "uninst-smartmontools.exe"
258
259 SectionEnd
260
261 Section "Start Menu Shortcuts" MENU_SECTION
262
263 SectionIn ${FULL_TYPES}
264
265 SetShellVarContext all
266
267 CreateDirectory "$SMPROGRAMS\smartmontools"
268
269 !macro CreateAdminShortCut link target args
270 CreateShortCut '${link}' '${target}' '${args}'
271 push '${link}'
272 Call ShellLinkSetRunAs
273 !macroend
274
275 ; runcmdu
276 ${If} ${FileExists} "$INSTDIR\bin\smartctl.exe"
277 ${OrIf} ${FileExists} "$INSTDIR\bin\smartd.exe"
278 SetOutPath "$INSTDIR\bin"
279 !insertmacro FileExe "bin\runcmdu.exe" ""
280 ${EndIf}
281
282 ; smartctl
283 ${If} ${FileExists} "$INSTDIR\bin\smartctl.exe"
284 SetOutPath "$INSTDIR\bin"
285 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl (Admin CMD).lnk" "$WINDIR\system32\cmd.exe" '/k PATH=$INSTDIR\bin;%PATH%&cd /d "$INSTDIR\bin"'
286 CreateDirectory "$SMPROGRAMS\smartmontools\smartctl Examples"
287 FileOpen $0 "$SMPROGRAMS\smartmontools\smartctl Examples\!Read this first!.txt" "w"
288 FileWrite $0 "All the example commands in this directory$\r$\napply to the first drive (sda).$\r$\n"
289 FileClose $0
290 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\All info (-x).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -x sda"
291 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Identify drive (-i).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -i sda"
292 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART attributes (-A -f brief).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -A -f brief sda"
293 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART capabilities (-c).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -c sda"
294 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART health status (-H).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -H sda"
295 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART error log (-l error).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -l error sda"
296 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART selftest log (-l selftest).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -l selftest sda"
297 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start long selftest (-t long).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -t long sda"
298 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start offline test (-t offline).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -t offline sda"
299 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start short selftest (-t short).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -t short sda"
300 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Stop(Abort) selftest (-X).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -X sda"
301 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART off (-s off).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -s off sda"
302 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART on (-s on).lnk" "$INSTDIR\bin\runcmdu.exe" "smartctl -s on sda"
303 ${EndIf}
304
305 ; smartd
306 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
307 SetOutPath "$INSTDIR\bin"
308 CreateDirectory "$SMPROGRAMS\smartmontools\smartd Examples"
309 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, smartd.log.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd -l local0"
310 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, eventlog.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd"
311 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon stop.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd stop"
312 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Do all tests once (-q onecheck).lnk" "$INSTDIR\bin\runcmdu.exe" "smartd -q onecheck"
313 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Debug mode (-d).lnk" "$INSTDIR\bin\runcmdu.exe" "smartd -d"
314 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd.conf (edit).lnk" "$EDITOR" '"$INSTDIR\bin\smartd.conf"'
315 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd.conf (view).lnk" "$EDITOR" '"$INSTDIR\bin\smartd.conf"'
316 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd.log (view).lnk" "$EDITOR" '"$INSTDIR\bin\smartd.log"'
317 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd_mailer.conf.sample.ps1 (view).lnk" "$EDITOR" '"$INSTDIR\bin\smartd_mailer.conf.sample.ps1"'
318 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\smartd_mailer.conf.ps1 (create, edit).lnk" "$EDITOR" '"$INSTDIR\bin\smartd_mailer.conf.ps1"'
319
320 ; smartd service
321 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, eventlog, 30min.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd install"
322 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, smartd.log, 10min.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd install -l local0 -i 600"
323 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, smartd.log, 30min.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd install -l local0"
324 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service remove.lnk" "$INSTDIR\bin\runcmdu.exe" "smartd remove"
325 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service start.lnk" "$INSTDIR\bin\runcmdu.exe" "net start smartd"
326 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service stop.lnk" "$INSTDIR\bin\runcmdu.exe" "net stop smartd"
327 ${EndIf}
328
329 ; Documentation
330 ${If} ${FileExists} "$INSTDIR\doc\README.TXT"
331 SetOutPath "$INSTDIR\doc"
332 CreateDirectory "$SMPROGRAMS\smartmontools\Documentation"
333 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (html).lnk" "$INSTDIR\doc\smartctl.8.html"
334 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (html).lnk" "$INSTDIR\doc\smartd.8.html"
335 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (html).lnk" "$INSTDIR\doc\smartd.conf.5.html"
336 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (pdf).lnk" "$INSTDIR\doc\smartctl.8.pdf"
337 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (pdf).lnk" "$INSTDIR\doc\smartd.8.pdf"
338 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (pdf).lnk" "$INSTDIR\doc\smartd.conf.5.pdf"
339 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf sample.lnk" "$EDITOR" '"$INSTDIR\doc\smartd.conf"'
340 ${If} ${FileExists} "$INSTDIR\bin\drivedb.h"
341 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\drivedb.h (view).lnk" "$EDITOR" '"$INSTDIR\bin\drivedb.h"'
342 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\Documentation\drivedb-add.h (create, edit).lnk" "$EDITOR" '"$INSTDIR\bin\drivedb-add.h"'
343 ${EndIf}
344 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\ChangeLog.lnk" "$INSTDIR\doc\ChangeLog.txt"
345 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\COPYING.lnk" "$INSTDIR\doc\COPYING.txt"
346 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\NEWS.lnk" "$INSTDIR\doc\NEWS.txt"
347 ${EndIf}
348
349 ; Homepage
350 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Home Page.lnk" "https://www.smartmontools.org/"
351 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Daily Builds.lnk" "https://builds.smartmontools.org/"
352
353 ; drivedb.h update
354 ${If} ${FileExists} "$INSTDIR\bin\update-smart-drivedb.exe"
355 SetOutPath "$INSTDIR\bin"
356 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\drivedb.h update.lnk" "$INSTDIR\bin\update-smart-drivedb.exe" ""
357 ${EndIf}
358
359 ; Uninstall
360 ${If} ${FileExists} "$INSTDIR\uninst-smartmontools.exe"
361 SetOutPath "$INSTDIR"
362 !insertmacro CreateAdminShortCut "$SMPROGRAMS\smartmontools\Uninstall smartmontools.lnk" "$INSTDIR\uninst-smartmontools.exe" ""
363 ${EndIf}
364
365 SectionEnd
366
367 Section "Add install dir to PATH" PATH_SECTION
368
369 SectionIn ${FULL_TYPES}
370
371 Push "$INSTDIR\bin"
372 Call AddToPath
373
374 SectionEnd
375
376 SectionGroup "Add smartctl to drive menu"
377
378 !macro DriveMenuRemove
379 DetailPrint "Remove drive menu entries"
380 DeleteRegKey HKCR "Drive\shell\smartctl0"
381 DeleteRegKey HKCR "Drive\shell\smartctl1"
382 DeleteRegKey HKCR "Drive\shell\smartctl2"
383 DeleteRegKey HKCR "Drive\shell\smartctl3"
384 DeleteRegKey HKCR "Drive\shell\smartctl4"
385 DeleteRegKey HKCR "Drive\shell\smartctl5"
386 !macroend
387
388 Section "Remove existing entries first" DRIVE_REMOVE_SECTION
389 SectionIn ${DRIVEMENU_TYPE}
390 !insertmacro DriveMenuRemove
391 SectionEnd
392
393 !macro DriveSection id name args
394 Section 'smartctl ${args} ...' DRIVE_${id}_SECTION
395 SectionIn ${DRIVEMENU_TYPE}
396 Call CheckRunCmdA
397 DetailPrint 'Add drive menu entry "${name}": smartctl ${args} ...'
398 WriteRegStr HKCR "Drive\shell\smartctl${id}" "" "${name}"
399 WriteRegStr HKCR "Drive\shell\smartctl${id}\command" "" '"$INSTDIR\bin\runcmda.exe" "$INSTDIR\bin\smartctl.exe" ${args} %L'
400 SectionEnd
401 !macroend
402
403 !insertmacro DriveSection 0 "SMART all info" "-x"
404 !insertmacro DriveSection 1 "SMART status" "-Hc"
405 !insertmacro DriveSection 2 "SMART attributes" "-A -f brief"
406 !insertmacro DriveSection 3 "SMART short selftest" "-t short"
407 !insertmacro DriveSection 4 "SMART long selftest" "-t long"
408 !insertmacro DriveSection 5 "SMART continue selective selftest" '-t "selective,cont"'
409
410 SectionGroupEnd
411
412 ;--------------------------------------------------------------------
413
414 Section "Uninstall"
415
416 ; Stop & remove service
417 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
418 ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath"
419 ${If} $0 != ""
420 ExecWait "net stop smartd"
421 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Remove smartd service ?" /SD IDNO IDYES 0 IDNO +2
422 ExecWait "$INSTDIR\bin\smartd.exe remove"
423 ${EndIf}
424 ${EndIf}
425
426 ; Remove installer registry key
427 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools"
428
429 ; Remove conf file ?
430 ${If} ${FileExists} "$INSTDIR\bin\smartd.conf"
431 ; Assume unchanged if timestamp is equal to sample file
432 GetFileTime "$INSTDIR\bin\smartd.conf" $0 $1
433 GetFileTime "$INSTDIR\doc\smartd.conf" $2 $3
434 StrCmp "$0:$1" "$2:$3" +2 0
435 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete configuration file$\n$INSTDIR\bin\smartd.conf ?" /SD IDNO IDYES 0 IDNO +2
436 Delete "$INSTDIR\bin\smartd.conf"
437 ${EndIf}
438
439 ; Remove log file ?
440 ${If} ${FileExists} "$INSTDIR\bin\smartd.log"
441 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete log file$\n$INSTDIR\bin\smartd.log ?" /SD IDNO IDYES 0 IDNO +2
442 Delete "$INSTDIR\bin\smartd.log"
443 ${EndIf}
444
445 ; Remove drivedb-add file ?
446 ${If} ${FileExists} "$INSTDIR\bin\drivedb-add.h"
447 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete local drive database file$\n$INSTDIR\bin\drivedb-add.h ?" /SD IDNO IDYES 0 IDNO +2
448 Delete "$INSTDIR\bin\drivedb-add.h"
449 ${EndIf}
450
451 ; Remove smartd_mailer.conf.ps1 file ?
452 ${If} ${FileExists} "$INSTDIR\bin\smartd_mailer.conf.ps1"
453 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete mailer configuration file$\n$INSTDIR\bin\smartd_mailer.conf.ps1 ?" /SD IDNO IDYES 0 IDNO +2
454 Delete "$INSTDIR\bin\smartd_mailer.conf.ps1"
455 ${EndIf}
456
457 ; Remove files
458 Delete "$INSTDIR\bin\smartctl.exe"
459 Delete "$INSTDIR\bin\smartctl-nc.exe"
460 Delete "$INSTDIR\bin\smartd.exe"
461 Delete "$INSTDIR\bin\smartd_mailer.ps1"
462 Delete "$INSTDIR\bin\smartd_mailer.conf.sample.ps1"
463 Delete "$INSTDIR\bin\smartd_warning.cmd" ; TODO: Check for modifications?
464 Delete "$INSTDIR\bin\drivedb.h"
465 Delete "$INSTDIR\bin\drivedb.h.error"
466 Delete "$INSTDIR\bin\drivedb.h.lastcheck"
467 Delete "$INSTDIR\bin\drivedb.h.old"
468 Delete "$INSTDIR\bin\update-smart-drivedb.exe"
469 Delete "$INSTDIR\bin\runcmda.exe"
470 Delete "$INSTDIR\bin\runcmdu.exe"
471 Delete "$INSTDIR\bin\wtssendmsg.exe"
472 Delete "$INSTDIR\doc\AUTHORS.txt"
473 Delete "$INSTDIR\doc\ChangeLog.txt"
474 Delete "$INSTDIR\doc\ChangeLog-5.0-6.0.txt"
475 Delete "$INSTDIR\doc\COPYING.txt"
476 Delete "$INSTDIR\doc\INSTALL.txt"
477 Delete "$INSTDIR\doc\NEWS.txt"
478 Delete "$INSTDIR\doc\README.txt"
479 Delete "$INSTDIR\doc\TODO.txt"
480 Delete "$INSTDIR\doc\checksums*.txt"
481 Delete "$INSTDIR\doc\smartctl.8.html"
482 Delete "$INSTDIR\doc\smartctl.8.pdf"
483 Delete "$INSTDIR\doc\smartctl.8.txt" ; TODO: Remove after smartmontools 6.6
484 Delete "$INSTDIR\doc\smartd.8.html"
485 Delete "$INSTDIR\doc\smartd.8.pdf"
486 Delete "$INSTDIR\doc\smartd.8.txt" ; TODO: Remove after smartmontools 6.6
487 Delete "$INSTDIR\doc\smartd.conf"
488 Delete "$INSTDIR\doc\smartd.conf.5.html"
489 Delete "$INSTDIR\doc\smartd.conf.5.pdf"
490 Delete "$INSTDIR\doc\smartd.conf.5.txt" ; TODO: Remove after smartmontools 6.6
491 Delete "$INSTDIR\uninst-smartmontools.exe"
492
493 ; Remove shortcuts
494 SetShellVarContext all
495 Delete "$SMPROGRAMS\smartmontools\*.*"
496 Delete "$SMPROGRAMS\smartmontools\Documentation\*.*"
497 Delete "$SMPROGRAMS\smartmontools\smartctl Examples\*.*"
498 Delete "$SMPROGRAMS\smartmontools\smartd Examples\*.*"
499
500 ; Remove folders
501 RMDir "$SMPROGRAMS\smartmontools\Documentation"
502 RMDir "$SMPROGRAMS\smartmontools\smartctl Examples"
503 RMDir "$SMPROGRAMS\smartmontools\smartd Examples"
504 RMDir "$SMPROGRAMS\smartmontools"
505 RMDir "$INSTDIR\bin"
506 RMDir "$INSTDIR\doc"
507 RMDir "$INSTDIR"
508
509 ; Remove install dir from PATH
510 Push "$INSTDIR\bin"
511 Call un.RemoveFromPath
512
513 ; Remove drive menu registry entries
514 !insertmacro DriveMenuRemove
515
516 ; Check for still existing entries
517 ${If} ${FileExists} "$INSTDIR\bin\smartd.exe"
518 MessageBox MB_OK|MB_ICONEXCLAMATION "$INSTDIR\bin\smartd.exe could not be removed.$\nsmartd is possibly still running." /SD IDOK
519 ${ElseIf} ${FileExists} "$INSTDIR"
520 MessageBox MB_OK "Note: $INSTDIR could not be removed." /SD IDOK
521 ${EndIf}
522
523 ${If} ${FileExists} "$SMPROGRAMS\smartmontools"
524 MessageBox MB_OK "Note: $SMPROGRAMS\smartmontools could not be removed." /SD IDOK
525 ${EndIf}
526
527 SectionEnd
528
529 ;--------------------------------------------------------------------
530 ; Functions
531
532 !macro AdjustSectionSize section
533 SectionGetSize ${section} $0
534 IntOp $0 $0 / 2
535 SectionSetSize ${section} $0
536 !macroend
537
538 Function .onInit
539
540 ; Set default install directories
541 ${If} $INSTDIR == "" ; /D=PATH option not specified ?
542 ReadRegStr $INSTDIR HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "InstallLocation"
543 ${If} $INSTDIR == "" ; Not already installed ?
544 StrCpy $INSTDIR "$PROGRAMFILES\smartmontools"
545 !ifdef INPDIR64
546 StrCpy $INSTDIR32 $INSTDIR
547 StrCpy $INSTDIR64 "$PROGRAMFILES64\smartmontools"
548 !endif
549 ${EndIf}
550 ${EndIf}
551
552 !ifdef INPDIR64
553 ; Check for 64-bit unless already installed in 32-bit location
554 ${If} $INSTDIR64 != ""
555 ${OrIf} $INSTDIR != "$PROGRAMFILES\smartmontools"
556 ; $1 = IsWow64Process(GetCurrentProcess(), ($0=FALSE, &$0))
557 System::Call "kernel32::GetCurrentProcess() i.s"
558 System::Call "kernel32::IsWow64Process(i s, *i 0 r0) i.r1"
559 ${If} "$0 $1" == "1 1" ; 64-bit Windows ?
560 !insertmacro SelectSection ${X64_SECTION}
561 ${EndIf}
562 ${EndIf}
563
564 ; Sizes of binary sections include 32-bit and 64-bit executables
565 !insertmacro AdjustSectionSize ${SMARTCTL_SECTION}
566 !insertmacro AdjustSectionSize ${SMARTD_SECTION}
567 !insertmacro AdjustSectionSize ${SMARTCTL_NC_SECTION}
568 !endif
569
570 ; Use 32-bit or 64-bit Notepad++ if installed
571 StrCpy $EDITOR "$PROGRAMFILES\Notepad++\notepad++.exe"
572 ${IfNot} ${FileExists} "$EDITOR"
573 StrCpy $EDITOR "$PROGRAMFILES64\Notepad++\notepad++.exe"
574 ${IfNot} ${FileExists} "$EDITOR"
575 StrCpy $EDITOR "notepad.exe"
576 ${EndIf}
577 ${EndIf}
578
579 Call ParseCmdLine
580
581 !ifdef INPDIR64
582 Call CheckX64
583 !endif
584 FunctionEnd
585
586 ; Check x64 section and update INSTDIR accordingly
587
588 !ifdef INPDIR64
589 Function CheckX64
590 ${IfNot} ${SectionIsSelected} ${X64_SECTION}
591 StrCpy $X64 ""
592 ${If} $INSTDIR32 != ""
593 ${AndIf} $INSTDIR == $INSTDIR64
594 StrCpy $INSTDIR $INSTDIR32
595 ${EndIf}
596 ${Else}
597 StrCpy $X64 "t"
598 ${If} $INSTDIR64 != ""
599 ${AndIf} $INSTDIR == $INSTDIR32
600 StrCpy $INSTDIR $INSTDIR64
601 ${EndIf}
602 ${EndIf}
603 FunctionEnd
604 !endif
605
606 ; Command line parsing
607
608 !macro GetCmdLineOption var name
609 Push ",$opts,"
610 Push ",${name},"
611 Call StrStr
612 Pop ${var}
613 ${If} ${var} != ""
614 StrCpy $nomatch ""
615 ${EndIf}
616 !macroend
617
618 !macro CheckCmdLineOption name section
619 StrCpy $allopts "$allopts,${name}"
620 !insertmacro GetCmdLineOption $0 ${name}
621 ${If} $0 == ""
622 !insertmacro UnselectSection ${section}
623 ${Else}
624 !insertmacro SelectSection ${section}
625 ${EndIf}
626 !macroend
627
628 Function ParseCmdLine
629 ; get /SO option
630 Var /global opts
631 ${GetParameters} $R0
632 ${GetOptions} $R0 "/SO" $opts
633 ${If} ${Errors}
634 Return
635 ${EndIf}
636 Var /global allopts
637 Var /global nomatch
638 StrCpy $nomatch "t"
639 !ifdef INPDIR64
640 ; Change previous 64-bit setting
641 StrCpy $allopts ",x32|x64"
642 !insertmacro GetCmdLineOption $0 "x32"
643 ${If} $0 != ""
644 !insertmacro UnselectSection ${X64_SECTION}
645 ${EndIf}
646 !insertmacro GetCmdLineOption $0 "x64"
647 ${If} $0 != ""
648 !insertmacro SelectSection ${X64_SECTION}
649 ${EndIf}
650 ; Leave other sections unchanged if only "x32" or "x64" is specified
651 ${If} $opts == "x32"
652 ${OrIf} $opts == "x64"
653 Return
654 ${EndIf}
655 !endif
656 ; Turn sections on or off
657 !insertmacro CheckCmdLineOption "smartctl" ${SMARTCTL_SECTION}
658 !insertmacro CheckCmdLineOption "smartd" ${SMARTD_SECTION}
659 !insertmacro CheckCmdLineOption "smartctlnc" ${SMARTCTL_NC_SECTION}
660 !insertmacro CheckCmdLineOption "drivedb" ${DRIVEDB_SECTION}
661 !insertmacro CheckCmdLineOption "doc" ${DOC_SECTION}
662 !insertmacro CheckCmdLineOption "uninst" ${UNINST_SECTION}
663 !insertmacro CheckCmdLineOption "menu" ${MENU_SECTION}
664 !insertmacro CheckCmdLineOption "path" ${PATH_SECTION}
665 !insertmacro CheckCmdLineOption "driveremove" ${DRIVE_REMOVE_SECTION}
666 !insertmacro CheckCmdLineOption "drive0" ${DRIVE_0_SECTION}
667 !insertmacro CheckCmdLineOption "drive1" ${DRIVE_1_SECTION}
668 !insertmacro CheckCmdLineOption "drive2" ${DRIVE_2_SECTION}
669 !insertmacro CheckCmdLineOption "drive3" ${DRIVE_3_SECTION}
670 !insertmacro CheckCmdLineOption "drive4" ${DRIVE_4_SECTION}
671 !insertmacro CheckCmdLineOption "drive5" ${DRIVE_5_SECTION}
672 ${If} $opts != "-"
673 ${If} $nomatch != ""
674 StrCpy $0 "$allopts,-" "" 1
675 MessageBox MB_OK "Usage: smartmontools-VERSION.win32-setup [/S] [/SO component,...] [/D=INSTDIR]$\n$\ncomponents:$\n $0"
676 Abort
677 ${EndIf}
678 ${EndIf}
679 FunctionEnd
680
681 ; Install runcmda.exe only once
682
683 Function CheckRunCmdA
684 Var /global runcmda
685 ${If} $runcmda == ""
686 StrCpy $runcmda "t"
687 SetOutPath "$INSTDIR\bin"
688 !insertmacro FileExe "bin\runcmda.exe" ""
689 ${EndIf}
690 FunctionEnd
691
692
693 ;--------------------------------------------------------------------
694 ; Path functions
695 ;
696 ; Based on example from:
697 ; http://nsis.sourceforge.net/Path_Manipulation
698 ;
699
700
701 !include "WinMessages.nsh"
702
703 ; Registry Entry for environment (NT4,2000,XP)
704 ; All users:
705 ;!define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
706 ; Current user only:
707 !define Environ 'HKCU "Environment"'
708
709
710 ; AddToPath - Appends dir to PATH
711 ; (does not work on Win9x/ME)
712 ;
713 ; Usage:
714 ; Push "dir"
715 ; Call AddToPath
716
717 Function AddToPath
718 Exch $0
719 Push $1
720 Push $2
721 Push $3
722 Push $4
723
724 ; NSIS ReadRegStr returns empty string on string overflow
725 ; Native calls are used here to check actual length of PATH
726
727 ; $4 = RegOpenKey(HKEY_CURRENT_USER, "Environment", &$3)
728 System::Call "advapi32::RegOpenKey(i 0x80000001, t'Environment', *i.r3) i.r4"
729 IntCmp $4 0 0 done done
730 ; $4 = RegQueryValueEx($3, "PATH", (DWORD*)0, (DWORD*)0, &$1, ($2=NSIS_MAX_STRLEN, &$2))
731 ; RegCloseKey($3)
732 System::Call "advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4"
733 System::Call "advapi32::RegCloseKey(i $3)"
734
735 ${If} $4 = 234 ; ERROR_MORE_DATA
736 DetailPrint "AddToPath: original length $2 > ${NSIS_MAX_STRLEN}"
737 MessageBox MB_OK "PATH not updated, original length $2 > ${NSIS_MAX_STRLEN}" /SD IDOK
738 Goto done
739 ${EndIf}
740
741 ${If} $4 <> 0 ; NO_ERROR
742 ${If} $4 <> 2 ; ERROR_FILE_NOT_FOUND
743 DetailPrint "AddToPath: unexpected error code $4"
744 Goto done
745 ${EndIf}
746 StrCpy $1 ""
747 ${EndIf}
748
749 ; Check if already in PATH
750 Push "$1;"
751 Push "$0;"
752 Call StrStr
753 Pop $2
754 StrCmp $2 "" 0 done
755 Push "$1;"
756 Push "$0\;"
757 Call StrStr
758 Pop $2
759 StrCmp $2 "" 0 done
760
761 ; Prevent NSIS string overflow
762 StrLen $2 $0
763 StrLen $3 $1
764 IntOp $2 $2 + $3
765 IntOp $2 $2 + 2 ; $2 = strlen(dir) + strlen(PATH) + sizeof(";")
766 ${If} $2 > ${NSIS_MAX_STRLEN}
767 DetailPrint "AddToPath: new length $2 > ${NSIS_MAX_STRLEN}"
768 MessageBox MB_OK "PATH not updated, new length $2 > ${NSIS_MAX_STRLEN}." /SD IDOK
769 Goto done
770 ${EndIf}
771
772 ; Append dir to PATH
773 DetailPrint "Add to PATH: $0"
774 StrCpy $2 $1 1 -1
775 ${If} $2 == ";"
776 StrCpy $1 $1 -1 ; remove trailing ';'
777 ${EndIf}
778 ${If} $1 != "" ; no leading ';'
779 StrCpy $0 "$1;$0"
780 ${EndIf}
781 WriteRegExpandStr ${Environ} "PATH" $0
782 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
783
784 done:
785 Pop $4
786 Pop $3
787 Pop $2
788 Pop $1
789 Pop $0
790 FunctionEnd
791
792
793 ; RemoveFromPath - Removes dir from PATH
794 ;
795 ; Usage:
796 ; Push "dir"
797 ; Call RemoveFromPath
798
799 Function un.RemoveFromPath
800 Exch $0
801 Push $1
802 Push $2
803 Push $3
804 Push $4
805 Push $5
806 Push $6
807
808 ReadRegStr $1 ${Environ} "PATH"
809 StrCpy $5 $1 1 -1
810 ${If} $5 != ";"
811 StrCpy $1 "$1;" ; ensure trailing ';'
812 ${EndIf}
813 Push $1
814 Push "$0;"
815 Call un.StrStr
816 Pop $2 ; pos of our dir
817 StrCmp $2 "" done
818
819 DetailPrint "Remove from PATH: $0"
820 StrLen $3 "$0;"
821 StrLen $4 $2
822 StrCpy $5 $1 -$4 ; $5 is now the part before the path to remove
823 StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove
824 StrCpy $3 "$5$6"
825 StrCpy $5 $3 1 -1
826 ${If} $5 == ";"
827 StrCpy $3 $3 -1 ; remove trailing ';'
828 ${EndIf}
829 WriteRegExpandStr ${Environ} "PATH" $3
830 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
831
832 done:
833 Pop $6
834 Pop $5
835 Pop $4
836 Pop $3
837 Pop $2
838 Pop $1
839 Pop $0
840 FunctionEnd
841
842
843 ; StrStr - find substring in a string
844 ;
845 ; Usage:
846 ; Push "this is some string"
847 ; Push "some"
848 ; Call StrStr
849 ; Pop $0 ; "some string"
850
851 !macro StrStr un
852 Function ${un}StrStr
853 Exch $R1 ; $R1=substring, stack=[old$R1,string,...]
854 Exch ; stack=[string,old$R1,...]
855 Exch $R2 ; $R2=string, stack=[old$R2,old$R1,...]
856 Push $R3
857 Push $R4
858 Push $R5
859 StrLen $R3 $R1
860 StrCpy $R4 0
861 ; $R1=substring, $R2=string, $R3=strlen(substring)
862 ; $R4=count, $R5=tmp
863 ${Do}
864 StrCpy $R5 $R2 $R3 $R4
865 ${IfThen} $R5 == $R1 ${|} ${ExitDo} ${|}
866 ${IfThen} $R5 == "" ${|} ${ExitDo} ${|}
867 IntOp $R4 $R4 + 1
868 ${Loop}
869 StrCpy $R1 $R2 "" $R4
870 Pop $R5
871 Pop $R4
872 Pop $R3
873 Pop $R2
874 Exch $R1 ; $R1=old$R1, stack=[result,...]
875 FunctionEnd
876 !macroend
877 !insertmacro StrStr ""
878 !insertmacro StrStr "un."
879
880
881 ;--------------------------------------------------------------------
882 ; Set Run As Administrator flag in shortcut
883 ;
884 ; Slightly modified version from:
885 ; http://nsis.sourceforge.net/IShellLink_Set_RunAs_flag
886 ;
887
888 !define IPersistFile {0000010b-0000-0000-c000-000000000046}
889 !define CLSID_ShellLink {00021401-0000-0000-C000-000000000046}
890 !define IID_IShellLinkA {000214EE-0000-0000-C000-000000000046}
891 !define IID_IShellLinkW {000214F9-0000-0000-C000-000000000046}
892 !define IShellLinkDataList {45e2b4ae-b1c3-11d0-b92f-00a0c90312e1}
893 !ifdef NSIS_UNICODE
894 !define IID_IShellLink ${IID_IShellLinkW}
895 !else
896 !define IID_IShellLink ${IID_IShellLinkA}
897 !endif
898
899 Function ShellLinkSetRunAs
900 ; Set archive location of $PLUGINSDIR
901 Goto +2
902 SetOutPath "$INSTDIR"
903
904 System::Store S ; push $0-$9, $R0-$R9
905 pop $9
906 ; $0 = CoCreateInstance(CLSID_ShellLink, 0, CLSCTX_INPROC_SERVER, IID_IShellLink, &$1)
907 System::Call "ole32::CoCreateInstance(g'${CLSID_ShellLink}',i0,i1,g'${IID_IShellLink}',*i.r1)i.r0"
908 ${If} $0 = 0
909 System::Call "$1->0(g'${IPersistFile}',*i.r2)i.r0" ; $0 = $1->QueryInterface(IPersistFile, &$2)
910 ${If} $0 = 0
911 System::Call "$2->5(w '$9',i 0)i.r0" ; $0 = $2->Load($9, STGM_READ)
912 ${If} $0 = 0
913 System::Call "$1->0(g'${IShellLinkDataList}',*i.r3)i.r0" ; $0 = $1->QueryInterface(IShellLinkDataList, &$3)
914 ${If} $0 = 0
915 System::Call "$3->6(*i.r4)i.r0"; $0 = $3->GetFlags(&$4)
916 ${If} $0 = 0
917 System::Call "$3->7(i $4|0x2000)i.r0" ; $0 = $3->SetFlags($4|SLDF_RUNAS_USER)
918 ${If} $0 = 0
919 System::Call "$2->6(w '$9',i1)i.r0" ; $2->Save($9, TRUE)
920 ${EndIf}
921 ${EndIf}
922 System::Call "$3->2()" ; $3->Release()
923 ${EndIf}
924 System::Call "$2->2()" ; $2->Release()
925 ${EndIf}
926 ${EndIf}
927 System::Call "$1->2()" ; $1->Release()
928 ${EndIf}
929 ${If} $0 <> 0
930 DetailPrint "Set RunAsAdmin: $9 failed ($0)"
931 ${Else}
932 DetailPrint "Set RunAsAdmin: $9"
933 ${EndIf}
934 System::Store L ; pop $R9-$R0, $9-$0
935 FunctionEnd