]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/winbacula.nsi.in
ab50bb552fca53472b222191f091c2667506d6fe
[bacula/bacula] / bacula / src / win32 / winbacula.nsi.in
1 ; winbacula.nsi
2 ;
3 ; written by Michel Meyers (michel@tcnnet.dyndns.org)
4 ;
5 ; ChangeLog
6 ; v0.1 - initial release (still a lot to do)
7
8 ;!define TEMP1 $R0 ;Temp variable
9 !define VERSION '@VERSION@-@LSMDATE@'
10
11 SetCompressor lzma
12 SetCompressorDictSize 32
13
14 ; The name of the installer
15 Name "Bacula Client"
16
17 ; The file to write
18 OutFile "winbacula-${VERSION}.exe"
19
20 ; The default installation directory
21 InstallDir "c:\bacula"
22
23 DirText "Setup will install the Bacula Client v${VERSION} to the directory specified below. To install in a different folder, click Browse and select another folder.$\n$\nNote to CYGWIN users: please choose your CYGWIN root directory."
24 Page directory
25 Page instfiles
26 UninstPage uninstConfirm
27 UninstPage instfiles
28
29 ;Icon "${NSISDIR}\Contrib\Icons\modern-install.ico"
30 ;UninstallIcon "${NSISDIR}\Contrib\Icons\modern-uninstall.ico"
31 ;CheckBitmap "${NSISDIR}\Contrib\Icons\modern.bmp"
32
33 ; The text to prompt the user to enter a directory
34 ;ComponentText "This will extract the temporary files needed for controlling your PC remotely."
35 ; The stuff to install
36
37 ; -- written by Alexis de Valence --
38 ; GetONEParameter
39
40 ; Usage:
41 ;   Push 3                 ; to get the 3rd parameter of the command line
42 ;   Call GetONEParameter
43 ;   Pop $R0                ; saves the result in $R0
44 ; returns an empty string if not found
45
46 Function GetONEParameter
47    Exch $R0
48    Push $R1
49    Push $R2
50    Push $R3
51    Push $R4
52    Push $R5
53    Push $R6
54
55 ; init variables
56    IntOp $R5 $R0 + 1
57    StrCpy $R2 0
58    StrCpy $R4 1
59    StrCpy $R6 0
60
61    loop3: ; looking for a char that's not a space
62      IntOp $R2 $R2 + 1
63      StrCpy $R0 $CMDLINE 1 $R2
64      StrCmp $R0 " " loop3
65      StrCpy $R3 $R2   ; found the begining of the current parameter
66
67
68    loop:          ; scanning for the end of the current parameter
69
70      StrCpy $R0 $CMDLINE 1 $R2
71      StrCmp $R0 " " loop2
72      StrCmp $R0 "" last
73      IntOp $R2 $R2 + 1
74      Goto loop
75
76    last: ; there will be no other parameter to extract
77    StrCpy $R6 1
78
79    loop2: ; found the end of the current parameter
80
81    IntCmp $R4 $R5 0 NextParam end
82    StrCpy $R6 1 ; to quit after this process
83
84    IntOp $R1 $R2 - $R3 ;number of letter of current parameter
85    StrCpy $R0 $CMDLINE $R1 $R3        ; stores the result in R0
86
87    NextParam:
88    IntCmp $R6 1 end ; leave if found or if not enough parameters
89
90    ; process the next parameter
91    IntOp $R4 $R4 + 1
92
93    Goto loop3
94
95    end:
96
97    Pop $R6  ; restore R0 - R6 to their initial value
98    Pop $R5
99    Pop $R4
100    Pop $R3
101    Pop $R2
102    Pop $R1
103
104    Exch $R0    ;Puts the result on the stack
105
106  FunctionEnd
107
108 ; -- written by Michel Meyers --
109 ; ParameterGiven - checks first 9 parameters on the command line
110 ; Usage:
111 ;   Push "/parameter"                 ; to check command line for /parameter
112 ;   Call ParameterGiven
113 ;   Pop $R0                ; saves the result in $R0 (result = true or false)
114
115  Function ParameterGiven
116    Exch $R0
117    Push $R1
118    Push $R2
119    Push $R3
120    
121    StrCpy $R1 0
122    StrCpy $R3 0
123    loopme:
124    StrCmp $R1 9 AllChecked
125    IntOp $R1 $R1 + 1
126    Push $R1
127    Call GetONEParameter
128    Pop $R2                ; saves the result in $R2
129    StrCmp $R0 $R2 Found
130    Goto loopme
131    
132    Found:
133    StrCpy $R3 1
134    Goto loopme
135    
136    AllChecked:
137    Exch $R3
138   
139  FunctionEnd
140
141 Section "Install"
142
143   ; /cygwin on command line forces install dir to c:\cygwin\bacula (useful for silent install)
144   Push "/cygwin"
145   Call ParameterGiven
146   Pop $6
147   StrCmp $6 0 NoCygwin
148   StrCpy $INSTDIR "c:\cygwin\bacula"
149   NoCygwin:
150
151   ; Check for existing installation
152   StrCpy $7 0
153   IfFileExists "$INSTDIR\bin\bacula-fd.conf" Upgrade NoUpgrade
154   Upgrade:
155     StrCpy $7 1
156     ; Shutdown any baculas that could be running
157     ExecWait '"$INSTDIR\bin\bacula-fd.exe" /kill'
158   NoUpgrade:
159
160   ; Set output path to the installation directory.
161   SetOutPath "$INSTDIR\bin"
162   CreateDirectory "$INSTDIR"
163   CreateDirectory "$INSTDIR\bin"
164   CreateDirectory "$INSTDIR\working"
165   CreateDirectory "c:\tmp"
166   ; Put files there
167   File baculafd\Release\bacula-fd.exe
168   File pthreads\pthreadVCE.dll
169   IfFileExists "$INSTDIR\bacula-fd.conf" newconf 
170   File bacula-fd.conf
171   goto do_service
172   newconf:
173   File /oname=bacula-fd.conf.new bacula-fd.conf
174        
175
176   ; If /service was given jump to the service install part
177   do_service:
178   Push "/service"
179   Call ParameterGiven
180   Pop $5
181   StrCmp $5 1 Service
182   
183   ; If silent install and not /service don't ask questions and goto NoService...
184   IfSilent NoService
185
186   ; If already installed as service skip it too
187   ReadRegDWORD $9 HKLM "Software\Bacula" "InstalledService"
188   StrCmp $9 "1" NoService  
189
190   ; Install as service?
191   MessageBox MB_YESNO|MB_ICONQUESTION "Do you want to install the Bacula Client as a service (automatically starts with your PC)?" IDNO NoService
192   Service:
193     ExecWait '"$INSTDIR\bin\bacula-fd.exe" /install'
194     StrCpy $9 "1"
195     WriteRegDWORD HKLM "Software\Bacula" "InstalledService" "1"
196   NoService:
197
198   ; Write the uninstall keys for Windows
199   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "DisplayName" "Bacula Client"
200   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula" "UninstallString" '"$INSTDIR\uninstall.exe"'
201   SetOutPath "$INSTDIR"
202   WriteUninstaller "uninstall.exe"
203
204   ; Create bacula-fd.conf and have the user edit it (skipped if silent)
205   IfSilent NoReminder
206   StrCmp $7 "1" NoReminder  ; skip if it is an upgrade
207   MessageBox MB_OK "Please edit $INSTDIR\bin\bacula-fd.conf according to your requirements/installation! Also remember to put a shortcut into your start menu if you didn't install the client as a service."
208   CopyFiles /SILENT "$INSTDIR\bin\bacula-fd.conf.new" "$INSTDIR\bin\bacula-fd.conf"
209   Exec 'write "$INSTDIR\bin\bacula-fd.conf"'  ; spawn wordpad with the file to be edited
210   NoReminder:
211
212   ; Start the client? (default skipped if silent, use /start to force starting)
213   Push "/start"
214   Call ParameterGiven
215   Pop $8
216   StrCmp $8 "1" Start
217   IfSilent NoStart
218   MessageBox MB_YESNO|MB_ICONQUESTION  "Would you like to start the Bacula Client now?" IDNO NoStart
219   Start:
220     Exec '"$INSTDIR\bin\bacula-fd.exe" -c "$INSTDIR\bin\bacula-fd.conf"'
221   NoStart:
222
223 SectionEnd
224
225
226 ; Uninstall section
227
228 UninstallText "This will uninstall the Bacula Client. Hit next to continue."
229
230 Section "Uninstall"
231   
232   ; Shutdown any baculas that could be running
233   ExecWait '"$INSTDIR\bin\bacula-fd.exe" /kill'
234
235   ReadRegDWORD $9 HKLM "Software\Bacula" "InstalledService"
236   StrCmp $9 "" NoService
237   ; Remove bacula service
238   ExecWait '"$INSTDIR\bin\bacula-fd.exe" /remove'
239   NoService:
240   
241   ; remove registry keys
242   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Bacula"
243   DeleteRegKey HKLM "Software\Bacula"
244
245   ; remove files and uninstaller (preserving config for now)
246   CopyFiles /SILENT "$INSTDIR\bin\bacula-fd.conf" "$INSTDIR\bacula-fd.conf"
247   Delete /REBOOTOK "$INSTDIR\bin\*.*"
248   CopyFiles /SILENT "$INSTDIR\bacula-fd.conf" "$INSTDIR\bin\bacula-fd.conf"
249   Delete /REBOOTOK "$INSTDIR\bacula-fd.conf"
250   Delete /REBOOTOK "$INSTDIR\uninstall.exe"
251
252   ; Check for existing installation
253   MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to delete the current configuration file ($INSTDIR\bin\bacula-fd.conf)?" IDNO LeaveConfig
254   Delete /REBOOTOK "$INSTDIR\bin\bacula-fd.conf"
255   ; remove directories used
256   RMDir "$INSTDIR\bin"
257   RMDir "$INSTDIR\working"
258   RMDir "$INSTDIR"
259   RMDir "C:\tmp"
260   LeaveConfig:
261   
262   ; If we need to reboot we'll ask
263   IfRebootFlag Reboot Continue
264   Reboot:
265   MessageBox MB_YESNO|MB_ICONQUESTION "Some files will only be deleted after restarting. Reboot now?" IDNO Continue
266     Reboot
267   Continue:
268
269 SectionEnd
270
271 ; eof