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