2 ; installer.nsi - NSIS install script for smartmontools
4 ; Copyright (C) 2006 Christian Franke <smartmontools-support@lists.sourceforge.net>
6 ; Project home page is: http://smartmontools.sourceforge.net
8 ; Download and install NSIS from: http://nsis.sourceforge.net/Download
9 ; Process with makensis to create installer (tested with NSIS 2.17).
11 ; $Id: installer.nsi,v 1.2 2006/07/17 20:51:22 chrfranke Exp $
15 ;--------------------------------------------------------------------
16 ; Command line arguments:
17 ; makensis /DINPDIR=<input-dir> /DOUTFILE=<output-file> installer.nsi
24 !define OUTFILE "smartmontools.win32-setup.exe"
27 ;--------------------------------------------------------------------
33 SetCompressor /solid lzma
36 InstallColors /windows
38 InstallDir "$PROGRAMFILES\smartmontools"
39 InstallDirRegKey HKLM "Software\smartmontools" "Install_Dir"
41 LicenseData "${INPDIR}\doc\COPYING.txt"
43 ;--------------------------------------------------------------------
51 UninstPage uninstConfirm
55 InstType "Extract files only"
58 ;--------------------------------------------------------------------
61 SectionGroup "Program files"
67 SetOutPath "$INSTDIR\bin"
68 File "${INPDIR}\bin\smartctl.exe"
76 SetOutPath "$INSTDIR\bin"
77 File "${INPDIR}\bin\smartd.exe"
79 IfFileExists "$INSTDIR\bin\smartd.conf" 0 +2
80 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Replace existing configuration file$\n$INSTDIR\bin\smartd.conf ?" IDYES 0 IDNO +2
81 File "${INPDIR}\doc\smartd.conf"
83 IfFileExists "$WINDIR\system32\cmd.exe" 0 +2
84 File /nonfatal "${INPDIR}\bin\syslogevt.exe"
90 Section "Documentation"
94 SetOutPath "$INSTDIR\doc"
95 File "${INPDIR}\doc\AUTHORS.txt"
96 File "${INPDIR}\doc\CHANGELOG.txt"
97 File "${INPDIR}\doc\COPYING.txt"
98 File "${INPDIR}\doc\INSTALL.txt"
99 File "${INPDIR}\doc\NEWS.txt"
100 File "${INPDIR}\doc\README.txt"
101 File "${INPDIR}\doc\TODO.txt"
102 File "${INPDIR}\doc\WARNINGS.txt"
103 File "${INPDIR}\doc\smartctl.8.html"
104 File "${INPDIR}\doc\smartctl.8.txt"
105 File "${INPDIR}\doc\smartd.8.html"
106 File "${INPDIR}\doc\smartd.8.txt"
107 File "${INPDIR}\doc\smartd.conf"
108 File "${INPDIR}\doc\smartd.conf.5.html"
109 File "${INPDIR}\doc\smartd.conf.5.txt"
113 Section "Uninstaller"
118 CreateDirectory "$INSTDIR"
120 ; Save installation location
121 WriteRegStr HKLM "Software\smartmontools" "Install_Dir" "$INSTDIR"
123 ; Write uninstall keys and program
124 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "DisplayName" "smartmontools"
125 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "UninstallString" '"$INSTDIR\uninst-smartmontools.exe"'
126 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoModify" 1
127 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" "NoRepair" 1
128 WriteUninstaller "uninst-smartmontools.exe"
132 Section "Start Menu Shortcuts"
136 CreateDirectory "$SMPROGRAMS\smartmontools"
139 IfFileExists "$INSTDIR\bin\smartctl.exe" 0 noctl
140 SetOutPath "$INSTDIR\bin"
141 DetailPrint "Create file: $INSTDIR\bin\smartctl-run.bat"
142 FileOpen $0 "$INSTDIR\bin\smartctl-run.bat" "w"
143 FileWrite $0 "@echo off$\r$\necho smartctl %1 %2 %3 %4 %5$\r$\nsmartctl %1 %2 %3 %4 %5$\r$\npause$\r$\n"
145 CreateDirectory "$SMPROGRAMS\smartmontools\smartctl Examples"
146 FileOpen $0 "$SMPROGRAMS\smartmontools\smartctl Examples\!Read this first!.txt" "w"
147 FileWrite $0 "All the example commands in this directory$\r$\napply to the first IDE/ATA/SATA drive (hda).$\r$\n"
149 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\All info (-a).lnk" "$INSTDIR\bin\smartctl-run.bat" "-a hda"
150 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Identify drive (-i).lnk" "$INSTDIR\bin\smartctl-run.bat" "-i hda"
151 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART attributes (-A).lnk" "$INSTDIR\bin\smartctl-run.bat" "-A hda"
152 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART capabilities (-c).lnk" "$INSTDIR\bin\smartctl-run.bat" "-c hda"
153 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART health status (-H).lnk" "$INSTDIR\bin\smartctl-run.bat" "-H hda"
154 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART error log (-l error).lnk" "$INSTDIR\bin\smartctl-run.bat" "-l error hda"
155 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\SMART selftest log (-l selftest).lnk" "$INSTDIR\bin\smartctl-run.bat" "-l selftest hda"
156 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start long selftest (-t long).lnk" "$INSTDIR\bin\smartctl-run.bat" "-t long hda"
157 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start offline test (-t offline).lnk" "$INSTDIR\bin\smartctl-run.bat" "-t offline hda"
158 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Start short selftest (-t short).lnk" "$INSTDIR\bin\smartctl-run.bat" "-t short hda"
159 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Stop(Abort) selftest (-X).lnk" "$INSTDIR\bin\smartctl-run.bat" "-X hda"
160 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART off (-s off).lnk" "$INSTDIR\bin\smartctl-run.bat" "-s off hda"
161 CreateShortCut "$SMPROGRAMS\smartmontools\smartctl Examples\Turn SMART on (-s on).lnk" "$INSTDIR\bin\smartctl-run.bat" "-s on hda"
165 IfFileExists "$INSTDIR\bin\smartd.exe" 0 nod
166 SetOutPath "$INSTDIR\bin"
167 DetailPrint "Create file: $INSTDIR\bin\smartd-run.bat"
168 FileOpen $0 "$INSTDIR\bin\smartd-run.bat" "w"
169 FileWrite $0 "@echo off$\r$\necho smartd %1 %2 %3 %4 %5$\r$\nsmartd %1 %2 %3 %4 %5$\r$\npause$\r$\n"
171 CreateDirectory "$SMPROGRAMS\smartmontools\smartd Examples"
172 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, log to smartd.log.lnk" "$INSTDIR\bin\smartd-run.bat" "-l local0"
173 IfFileExists "$WINDIR\system32\cmd.exe" 0 +2
174 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon start, log to eventlog.lnk" "$INSTDIR\bin\smartd-run.bat" ""
175 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Daemon stop.lnk" "$INSTDIR\bin\smartd-run.bat" "stop"
176 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Do all tests once (-q onecheck).lnk" "$INSTDIR\bin\smartd-run.bat" "-q onecheck"
177 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Debug mode (-d).lnk" "$INSTDIR\bin\smartd-run.bat" "-d"
178 IfFileExists "$WINDIR\notepad.exe" 0 nopad
179 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Edit smartd.conf.lnk" "$WINDIR\notepad.exe" "$INSTDIR\bin\smartd.conf"
180 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\View smartd.log.lnk" "$WINDIR\notepad.exe" "$INSTDIR\bin\smartd.log"
183 ; smartd service (not on 9x/ME)
184 IfFileExists "$WINDIR\system32\cmd.exe" 0 nosvc
185 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, log to eventlog.lnk" "$INSTDIR\bin\smartd-run.bat" "install"
186 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service install, log to smartd.log.lnk" "$INSTDIR\bin\smartd-run.bat" "install -l local0"
187 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service remove.lnk" "$INSTDIR\bin\smartd-run.bat" "remove"
188 DetailPrint "Create file: $INSTDIR\bin\net-run.bat"
189 FileOpen $0 "$INSTDIR\bin\net-run.bat" "w"
190 FileWrite $0 "@echo off$\r$\necho net %1 %2 %3 %4 %5$\r$\nnet %1 %2 %3 %4 %5$\r$\npause$\r$\n"
192 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service start.lnk" "$INSTDIR\bin\net-run.bat" "start smartd"
193 CreateShortCut "$SMPROGRAMS\smartmontools\smartd Examples\Service stop.lnk" "$INSTDIR\bin\net-run.bat" "stop smartd"
198 IfFileExists "$INSTDIR\doc\README.TXT" 0 nodoc
199 SetOutPath "$INSTDIR\doc"
200 CreateDirectory "$SMPROGRAMS\smartmontools\Documentation"
201 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (html).lnk" "$INSTDIR\doc\smartctl.8.html"
202 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (html).lnk" "$INSTDIR\doc\smartd.8.html"
203 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (html).lnk" "$INSTDIR\doc\smartd.conf.5.html"
204 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartctl manual page (txt).lnk" "$INSTDIR\doc\smartctl.8.txt"
205 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd manual page (txt).lnk" "$INSTDIR\doc\smartd.8.txt"
206 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf manual page (txt).lnk" "$INSTDIR\doc\smartd.conf.5.txt"
207 IfFileExists "$WINDIR\notepad.exe" 0 +2
208 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\smartd.conf sample.lnk" "$WINDIR\notepad.exe" "$INSTDIR\doc\smartd.conf"
209 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\AUTHORS.lnk" "$INSTDIR\doc\AUTHORS.txt"
210 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\CHANGELOG.lnk" "$INSTDIR\doc\CHANGELOG.txt"
211 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\COPYING.lnk" "$INSTDIR\doc\COPYING.txt"
212 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\INSTALL.lnk" "$INSTDIR\doc\INSTALL.txt"
213 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\NEWS.lnk" "$INSTDIR\doc\NEWS.txt"
214 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\README.lnk" "$INSTDIR\doc\README.txt"
215 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\TODO.lnk" "$INSTDIR\doc\TODO.txt"
216 CreateShortCut "$SMPROGRAMS\smartmontools\Documentation\WARNINGS.lnk" "$INSTDIR\doc\WARNINGS.txt"
220 CreateShortCut "$SMPROGRAMS\smartmontools\smartmontools Home Page.lnk" "http://smartmontools.sourceforge.net/"
223 IfFileExists "$INSTDIR\uninst-smartmontools.exe" 0 +2
224 CreateShortCut "$SMPROGRAMS\smartmontools\Uninstall smartmontools.lnk" "$INSTDIR\uninst-smartmontools.exe"
228 Section "Add install dir to PATH" PATH_IDX
232 IfFileExists "$WINDIR\system32\cmd.exe" 0 +3
238 ;--------------------------------------------------------------------
242 ; Remove registry keys
243 DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools"
244 DeleteRegKey HKLM "Software\smartmontools"
246 IfFileExists "$INSTDIR\bin\smartd.conf" 0 noconf
247 ; Assume unchanged if timestamp is equal to sample file
248 GetFileTime "$INSTDIR\bin\smartd.conf" $0 $1
249 GetFileTime "$INSTDIR\doc\smartd.conf" $2 $3
250 StrCmp "$0:$1" "$2:$3" +2 0
251 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete configuration file$\n$INSTDIR\bin\smartd.conf ?" IDYES 0 IDNO noconf
252 Delete "$INSTDIR\bin\smartd.conf"
255 IfFileExists "$INSTDIR\bin\smartd.log" 0 +3
256 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete log file$\n$INSTDIR\bin\smartd.log ?" IDYES 0 IDNO +2
257 Delete "$INSTDIR\bin\smartd.log"
260 Delete "$INSTDIR\bin\smartctl.exe"
261 Delete "$INSTDIR\bin\smartd.exe"
262 Delete "$INSTDIR\bin\syslogevt.exe"
263 Delete "$INSTDIR\bin\smartctl-run.bat"
264 Delete "$INSTDIR\bin\smartd-run.bat"
265 Delete "$INSTDIR\bin\net-run.bat"
266 Delete "$INSTDIR\doc\AUTHORS.txt"
267 Delete "$INSTDIR\doc\CHANGELOG.txt"
268 Delete "$INSTDIR\doc\COPYING.txt"
269 Delete "$INSTDIR\doc\INSTALL.txt"
270 Delete "$INSTDIR\doc\NEWS.txt"
271 Delete "$INSTDIR\doc\README.txt"
272 Delete "$INSTDIR\doc\TODO.txt"
273 Delete "$INSTDIR\doc\WARNINGS.txt"
274 Delete "$INSTDIR\doc\smartctl.8.html"
275 Delete "$INSTDIR\doc\smartctl.8.txt"
276 Delete "$INSTDIR\doc\smartd.8.html"
277 Delete "$INSTDIR\doc\smartd.8.txt"
278 Delete "$INSTDIR\doc\smartd.conf"
279 Delete "$INSTDIR\doc\smartd.conf.5.html"
280 Delete "$INSTDIR\doc\smartd.conf.5.txt"
281 Delete "$INSTDIR\uninst-smartmontools.exe"
284 Delete "$SMPROGRAMS\smartmontools\*.*"
285 Delete "$SMPROGRAMS\smartmontools\Documentation\*.*"
286 Delete "$SMPROGRAMS\smartmontools\smartctl Examples\*.*"
287 Delete "$SMPROGRAMS\smartmontools\smartd Examples\*.*"
290 RMDir "$SMPROGRAMS\smartmontools\Documentation"
291 RMDir "$SMPROGRAMS\smartmontools\smartctl Examples\"
292 RMDir "$SMPROGRAMS\smartmontools\smartd Examples\"
293 RMDir "$SMPROGRAMS\smartmontools"
298 ; Remove install dir from PATH
299 IfFileExists "$WINDIR\system32\cmd.exe" 0 +3
301 Call un.RemoveFromPath
303 ; Check for still existing files
304 IfFileExists "$INSTDIR\bin\smartd.exe" 0 +3
305 MessageBox MB_OK|MB_ICONEXCLAMATION "$INSTDIR\bin\smartd.exe could not be removed.$\nsmartd is possibly still running."
307 IfFileExists "$INSTDIR" 0 +2
308 MessageBox MB_OK "Note: $INSTDIR could not be removed."
312 ;--------------------------------------------------------------------
316 ; Hide "Add install dir to PATH" on 9x/ME
317 IfFileExists "$WINDIR\system32\cmd.exe" +2 0
318 SectionSetText ${PATH_IDX} ""
323 ;--------------------------------------------------------------------
326 ; Based on example from:
327 ; http://nsis.sourceforge.net/Path_Manipulation
331 !include "WinMessages.nsh"
333 ; Registry Entry for environment (NT4,2000,XP)
335 ;!define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
337 !define Environ 'HKCU "Environment"'
340 ; AddToPath - Appends dir to PATH
341 ; (does not work on Win9x/ME)
353 ReadRegStr $1 ${Environ} "PATH"
365 DetailPrint "Add to PATH: $0"
368 StrCpy $1 $1 -1 ; remove trailing ';'
369 StrCmp $1 "" +2 ; no leading ';'
371 WriteRegExpandStr ${Environ} "PATH" $0
372 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
382 ; RemoveFromPath - Removes dir from PATH
386 ; Call RemoveFromPath
388 Function un.RemoveFromPath
397 ReadRegStr $1 ${Environ} "PATH"
400 StrCpy $1 "$1;" ; ensure trailing ';'
404 Pop $2 ; pos of our dir
407 DetailPrint "Remove from PATH: $0"
410 StrCpy $5 $1 -$4 ; $5 is now the part before the path to remove
411 StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove
415 StrCpy $3 $3 -1 ; remove trailing ';'
416 WriteRegExpandStr ${Environ} "PATH" $3
417 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
430 ; StrStr - find substring in a string
433 ; Push "this is some string"
436 ; Pop $0 ; "some string"
440 Exch $R1 ; $R1=substring, stack=[old$R1,string,...]
441 Exch ; stack=[string,old$R1,...]
442 Exch $R2 ; $R2=string, stack=[old$R2,old$R1,...]
448 ; $R1=substring, $R2=string, $R3=strlen(substring)
451 StrCpy $R5 $R2 $R3 $R4
457 StrCpy $R1 $R2 "" $R4
462 Exch $R1 ; $R1=old$R1, stack=[result,...]
465 !insertmacro StrStr ""
466 !insertmacro StrStr "un."