-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAMPP.nsi
495 lines (386 loc) · 15.8 KB
/
AMPP.nsi
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
; general
; name and file
Name "AMPP"
OutFile "ampp.exe"
Caption "AMPP"
;Icon "icon\icon.ico"
;UninstallIcon "icon\un-icon.ico"
BrandingText "AMPP"
; the default installation directory
InstallDir "$PROGRAMFILES\AMPP\"
CRCCheck on
ShowInstDetails hide
SetCompress off
SetCompressor bzip2
; request application privileges for Windows Vista and Windows 7
RequestExecutionLevel admin
; includes
!include "Registry.nsh"
!include "FileFunc.nsh"
!include "Sections.nsh"
!include "LogicLib.nsh"
!include "nsDialogs.nsh"
!include "StrFunc.nsh"
!include "TextReplace.nsh"
!include "ZipDLL.nsh"
!include "StrRep.nsh"
!include "Ports.nsh"
; interface settings
;--------------------------------
; pages
page license
page components
page directory
page custom apache2_config_adv_one get_val_apache2_config_adv_one
page custom mysql_config_adv_one get_val_mysql_config_adv_one
page custom mysql_config_adv_two get_val_mysql_config_adv_two
page instfiles
uninstpage uninstConfirm
uninstpage instfiles
; Languages
;--------------------------------
; variables
; global for ns dialog plugin
var dialog
var text0
var text1
var text2
; custom pages
var checkbox_log_general
var checkbox_log_slow
var checkbox_log_bin
; mysql variables
var mysql_passwdfile
var mysql_service_name
var mysql_port
var mysql_passwd
var mysql_passwd_rep
var mysql_datadir_path
var mysql_basedir_path
var mysql_log_general
var mysql_log_slow
var mysql_log_bin
; apache2 variables
var apache_domain
var apache_server_name
var apache_server_name_w_domain
var apache_admin_email
;--------------------------------
; installer Sections
${StrCase}
Function .onVerifyInstDir
FunctionEnd
Function add_remove
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"DisplayName" "AMPP - Apache2, MySQL, PHP, phpMyAdmin"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"DisplayIcon" "$INSTDIR\un-ampp.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"Publisher" ""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"HelpLink" "https://github.com/motoko-kusanagi/ampp"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"URLInfoAbout" "https://github.com/motoko-kusanagi/ampp/blob/master/README.md"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"HelpTelephone" ""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"DisplayVersion" "1.0"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\AMPP" \
"UninstallString" "$\"$INSTDIR\un-ampp.exe$\""
FunctionEnd
Section "Express" section_one
SectionEnd
Section /o "Advanced" section_two
SectionEnd
Section "" main ; default section
SetShellVarContext all
CreateDirectory "$INSTDIR\Logs"
call apache_install
call php_install
call phpmyadmin_install
call create_www
call dotnet_install
call mysql_install
call add_remove
; start memnu shortcuts
CreateDirectory "$SMPROGRAMS\AMPP"
CreateShortCut "$SMPROGRAMS\AMPP\PHP.ini.lnk" "$INSTDIR\PHP\php.ini" "" ""
CreateShortCut "$SMPROGRAMS\AMPP\MySQL.ini.lnk" "$INSTDIR\MySQL\my.ini" "" ""
CreateShortCut "$SMPROGRAMS\AMPP\Uninstaller.lnk" "$INSTDIR\un-ampp.exe" "" ""
WriteUninstaller "$INSTDIR\un-ampp.exe"
SectionEnd
Function .onSelChange
!insertmacro StartRadioButtons $1
!insertmacro RadioButton ${section_one}
!insertmacro RadioButton ${section_two}
!insertmacro EndRadioButtons
FunctionEnd
Function detect_apache_settings
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\services\Tcpip\Parameters" "Domain"
StrCpy $apache_domain $0
${If} $apache_domain == ""
${EndIf}
ReadRegStr $0 HKLM "System\CurrentControlSet\Control\ComputerName\ActiveComputerName" "ComputerName"
StrCpy $apache_server_name $0
${StrCase} "$apache_server_name" "$apache_server_name" "L"
StrCpy "$apache_server_name_w_domain" "$apache_server_name.$apache_domain"
System::Call "advapi32::GetUserName(t .r0, *i ${NSIS_MAX_STRLEN} r1) i.r2"
StrCpy $apache_admin_email $0
StrCpy $apache_admin_email "$apache_admin_email@$apache_domain"
FunctionEnd
Function apache_install
${If} ${SectionIsSelected} ${section_one}
call detect_apache_settings
${EndIf}
${If} ${TCPPortOpen} 80
MessageBox MB_YESNO|MB_ICONQUESTION "port 80 is used... apache won't work. continue?" IDYES yes IDNO no
no:
MessageBox MB_OK|MB_ICONEXCLAMATION "bye bye!"
Quit
yes:
Pop $0
${EndIf}
SetOutPath "$TEMP\ampp\"
File "inst-files\httpd-2.2.25-win32-x86-openssl-0.9.8y.msi"
DetailPrint "Install Apache HTTP Server..."
ExecWait 'msiexec /i "$TEMP\ampp\httpd-2.2.25-win32-x86-openssl-0.9.8y.msi" /qb! INSTALLDIR="$INSTDIR\Apache2" SERVERNAME=$apache_server_name SERVERADMIN="$apache_admin_email" ALLUSERS=1 RebootYesNo=No /L*V "$INSTDIR\Logs\apache2.log"'
DetailPrint "Configure apache HTTP Server..."
${textreplace::ReplaceInFile} "$INSTDIR\apache2\conf\httpd.conf" "$INSTDIR\apache2\conf\httpd.conf" "htdocs" "www-root" "/S=1 /C=1 /AO=1" $0
${textreplace::ReplaceInFile} "$INSTDIR\apache2\conf\httpd.conf" "$INSTDIR\apache2\conf\httpd.conf" "index.html" "index.html index.php" "/S=1 /C=1 /AO=1" $0
ExecWait '"$INSTDIR\apache2\bin\httpd.exe" -k restart'
Delete "$TEMP\ampp\httpd-2.2.25-win32-x86-openssl-0.9.8y.msi"
FunctionEnd
Function php_install
SetOutPath "$TEMP\ampp\"
File "inst-files\php-5.3.28-Win32-VC9-x86.msi"
DetailPrint "Install PHP..."
ExecWait 'msiexec /i "$TEMP\ampp\php-5.3.28-Win32-VC9-x86.msi" /qb! INSTALLDIR="$INSTDIR\PHP" apacheDIR="$INSTDIR\apache2\conf" ADDLOCAL="ScriptExecutable,cgi,apache22,ext_php_mysqli,ext_php_mysql,ext_php_mbstring" /L*V "$INSTDIR\Logs\php.log"'
DetailPrint "Restart Apache HTTP Server..."
ExecWait '"$INSTDIR\apache2\bin\httpd.exe" -k restart'
Delete "$TEMP\ampp\php-5.3.28-Win32-VC9-x86.msi"
FunctionEnd
Function create_www
SetOutPath "$INSTDIR\apache2\www-root\"
File "inst-files\index.php"
FunctionEnd
Function phpmyadmin_install
CreateDirectory "$INSTDIR\apache2\www-root\"
SetOutPath "$TEMP\ampp\"
File "inst-files\phpMyAdmin-4.0.9-english.zip"
DetailPrint "Install phpMyAdmin..."
!insertmacro ZIPDLL_EXTRACT "$TEMP\ampp\phpMyAdmin-4.0.9-english.zip" "$INSTDIR\apache2\www-root" "<ALL>"
Delete "$TEMP\ampp\phpMyAdmin-4.0.9-english.zip"
FunctionEnd
Function mysql_install
${If} ${SectionIsSelected} ${section_one}
StrCpy $mysql_service_name "MySQL56"
StrCpy $mysql_port "3306"
StrCpy $mysql_log_general "1"
StrCpy $mysql_log_slow "1"
StrCpy $mysql_log_bin "1"
${EndIf}
${If} ${TCPPortOpen} 3306
MessageBox MB_YESNO|MB_ICONQUESTION "port 3306 is used... mysql won't work. continue?" IDYES yes IDNO no
no:
MessageBox MB_OK|MB_ICONEXCLAMATION "bye bye!"
Quit
yes:
Pop $0
${EndIf}
SetOutPath "$TEMP\ampp\"
File "inst-files\mysql-5.6.15-win32.zip"
DetailPrint "Install MySQL Server..."
!insertmacro ZIPDLL_EXTRACT "$TEMP\ampp\mysql-5.6.15-win32.zip" "$INSTDIR\MySQL" "<ALL>"
DetailPrint "Configure MySQL Server..."
Delete "$INSTDIR\MySQL\my-default.ini"
SetOutPath "$INSTDIR\MySQL"
File "mysql-conf\my.ini"
${StrReplace} "$INSTDIR\MySQL" "\" "\\"
StrCpy $mysql_basedir_path $0
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "basedir-path" "$mysql_basedir_path" "/S=1 /C=1 /AO=1" $0 ; replaces basedir path in my.ini config
${StrReplace} "$INSTDIR\MySQL\data" "\" "\\"
StrCpy $mysql_datadir_path $0
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "datadir-path" "$mysql_datadir_path" "/S=1 /C=1 /AO=1" $0 ; replaces datadir path in my.ini config
; mysql logs...
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "error.log" "$apache_server_name.err" "/S=1 /C=1 /AO=1" $0
${If} $mysql_log_general == "1"
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "general-log=0" "general-log=1" "/S=1 /C=1 /AO=1" $0 ; turns on general log
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "general.log" "$apache_server_name.log" "/S=1 /C=1 /AO=1" $0
${EndIf}
${If} $mysql_log_slow == "1"
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "slow-query-log=0" "slow-query-log=1" "/S=1 /C=1 /AO=1" $0 ; turns on slow log
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "slow.log" "$apache_server_name-slow.log" "/S=1 /C=1 /AO=1" $0
${EndIf}
${If} $mysql_log_bin == "1"
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "bin.log" "$apache_server_name-bin.log" "/S=1 /C=1 /AO=1" $0 ; turns on slow log
${Else}
${textreplace::ReplaceInFile} "$INSTDIR\MySQL\my.ini" "$INSTDIR\MySQL\my.ini" "log-bin" "# log-bin" "/S=1 /C=1 /AO=1" $0 ; turns on slow log
${EndIf}
FileOpen $4 "$INSTDIR\MySQL\service.info" w
FileWrite $4 "$mysql_service_name"
FileClose $4
DetailPrint "Instauj MySQL Server jako serwis..."
ExecWait '"$INSTDIR\MySQL\bin\mysqld.exe" --install $mysql_service_name' ; mysql as a service
DetailPrint "Run service $mysql_service_name..."
ExecWait '"net" start $mysql_service_name' ; starts mysql service
SetOutPath "$TEMP\ampp"
File "mysql-conf\passwd.sql"
${textreplace::ReplaceInFile} "$TEMP\ampp\passwd.sql" "$TEMP\ampp\passwd.sql" "my-new-password" "$mysql_passwd" "/S=1 /C=1 /AO=1" $0 ; replaces my-new-password with specific user password
sleep 6000
StrCpy $mysql_passwdfile "$TEMP\ampp\passwd.sql"
ExecWait '"cmd.exe" /C "$INSTDIR\MySQL\bin\mysql.exe" -uroot < $mysql_passwdfile' $0 ; changes root password
; MessageBox MB_OK $0
Delete "$TEMP\ampp\passwd.sql"
Delete "$TEMP\ampp\mysql-5.6.15-win32.zip"
FunctionEnd
Function dotnet_install
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" 'TargetVersion'
${If} $0 != "4.0.0"
SetOutPath "$TEMP\ampp\"
File "inst-files\dotNetFx40_Full_x86_x64.exe"
DetailPrint "Install .NET Framework v.4.0..."
ExecCmd::exec '"$TEMP\ampp\dotNetFx40_Full_x86_x64.exe" /passive /norestart'
Delete "$TEMP\ampp\dotNetFx40_Full_x86_x64.exe"
${EndIf}
FunctionEnd
Function apache2_config_adv_one
${If} ${SectionIsSelected} ${section_two}
call detect_apache_settings
nsDialogs::Create /NOUNLOAD 1018
Pop $dialog
${If} $dialog == error
abort
${EndIf}
${NSD_CreateLabel} 0 0 200 20 "Apache2 settings."
${NSD_CreateLabel} 0 30 200 20 "Domain name:"
${NSD_CreateText} 0 50 200 20 "$apache_domain"
Pop $text0
${NSD_CreateLabel} 0 80 200 20 "Server name:"
${NSD_CreateText} 0 100 200 20 "$apache_server_name"
Pop $text1
${NSD_CreateLabel} 0 130 200 20 "Administrator e-mail address:"
${NSD_CreateText} 0 150 200 20 "$apache_admin_email"
Pop $text2
nsDialogs::Show
${EndIf}
FunctionEnd
Function get_val_apache2_config_adv_one
${NSD_GetText} $text0 $apache_domain
${NSD_GetText} $text1 $apache_server_name
${NSD_GetText} $text2 $apache_admin_email
StrCmp $apache_domain "" mustcomplete
StrCmp $apache_server_name "" mustcomplete
StrCmp $apache_admin_email "" mustcomplete
goto exit
mustcomplete:
MessageBox MB_OK|MB_ICONEXCLAMATION "please fill all fields!"
Abort
exit:
Pop $0
FunctionEnd
Function mysql_config_adv_one
${If} ${SectionIsSelected} ${section_two}
nsDialogs::Create /NOUNLOAD 1018
Pop $dialog
${If} $dialog == error
abort
${EndIf}
${NSD_CreateLabel} 0 0 200 20 "MySQL settings."
${NSD_CreateLabel} 0 30 200 20 "Service name:"
${NSD_CreateText} 0 50 200 20 "MySQL56"
Pop $text0
${NSD_CreateLabel} 0 80 200 20 "Server port:"
${NSD_CreateNumber} 0 100 200 20 "3306"
Pop $text1
${NSD_CreateCheckbox} 0 140 100% 8u "General log"
Pop $checkbox_log_general
${NSD_CreateCheckbox} 0 160 100% 8u "Slow query log"
Pop $checkbox_log_slow
${NSD_CreateCheckbox} 0 180 100% 8u "Bin log"
Pop $checkbox_log_bin
nsDialogs::Show
${EndIf}
FunctionEnd
Function get_val_mysql_config_adv_one
${NSD_GetText} $text0 $mysql_service_name
${NSD_GetText} $text1 $mysql_port
${NSD_GetState} $checkbox_log_general $mysql_log_general
${NSD_GetState} $checkbox_log_slow $mysql_log_slow
${NSD_GetState} $checkbox_log_bin $mysql_log_bin
StrCmp $mysql_service_name "" mustcomplete
StrCmp $mysql_port "" mustcomplete
goto exit
mustcomplete:
MessageBox MB_OK|MB_ICONEXCLAMATION "please fill all fields!"
Abort
exit:
Pop $0
FunctionEnd
Function mysql_config_adv_two
${If} ${SectionIsSelected} ${section_two}
nsDialogs::Create /NOUNLOAD 1018
Pop $dialog
${If} $dialog == error
abort
${EndIf}
${NSD_CreateLabel} 0 0 200 20 "MySQL settings."
${NSD_CreateLabel} 0 30 200 20 "root password:"
${NSD_CreatePassword} 0 50 200 20 ""
Pop $text0
${NSD_CreateLabel} 0 80 200 20 "repeat password:"
${NSD_CreatePassword} 0 100 200 20 ""
Pop $text1
nsDialogs::Show
${EndIf}
FunctionEnd
Function get_val_mysql_config_adv_two
${NSD_GetText} $text0 $mysql_passwd
${NSD_GetText} $text1 $mysql_passwd_rep
${If} $mysql_passwd != $mysql_passwd_rep
MessageBox MB_OK|MB_ICONEXCLAMATION "blah password is incorrect!"
Abort
${EndIf}
StrCmp $mysql_passwd "" mustcomplete
StrCmp $mysql_passwd_rep "" mustcomplete
goto exit
mustcomplete:
MessageBox MB_OK|MB_ICONEXCLAMATION "damn! password can't be empty!"
Abort
exit:
Pop $0
FunctionEnd
Section "Uninstall"
SetShellVarContext all ; menu start from all users
; apache2
DetailPrint "Uninstall Apache HTTP Server..."
ExecCmd::exec 'msiexec /X{85262A06-2D8C-4BC1-B6ED-5A705D09CFFC} /norestart /qb! ALLUSERS=1 REMOVE="ALL" >ExecCmd.log'
; php5
DetailPrint "Uninstall PHP..."
ExecCmd::exec 'msiexec /X{F1294EED-6F8E-4C87-B34A-AB045356531D} /norestart /qb! ALLUSERS=1 REMOVE="ALL" >ExecCmd.log'
; mysql
FileOpen $4 "$INSTDIR\MySQL\service.info" r
FileRead $4 $1
StrCpy $mysql_service_name $1
FileClose $4
DetailPrint "Stop MySQL service..."
ExecWait '"net" stop $mysql_service_name'
DetailPrint "Remove MySQL service..."
ExecWait '"MySQL\bin\mysqld.exe" --remove $mysql_service_name'
; start menu shortcuts
Delete "$SMPROGRAMS\AMPP\php.ini"
Delete "$SMPROGRAMS\AMPP\my.ini"
Delete "$SMPROGRAMS\AMPP\un-ampp.exe"
RMDIR /r "$SMPROGRAMS\AMPP"
RMDir /r "$INSTDIR\PHP"
RMDir /r "$INSTDIR\Apache2"
RMDir /r "$INSTDIR\MySQL"
RMDir /r "$INSTDIR\Logs"
Delete "$INSTDIR\un-ampp.exe"
SectionEnd
Function un.onInit ; uninstaller init
SetRebootFlag true
FunctionEnd
Function .onInit ; podczas inicjacji okna
SetRebootFlag true
SectionSetSize ${main} 1289000
FunctionEnd