summaryrefslogtreecommitdiff
path: root/win32/installer/gen-nsis.php
blob: 7e9938f4c63248cb79747e5bccd745f557ee2ae1 (plain)
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
; PHP Installer for NSIS
; Based on Welcome/Finish Page Example Script (Written by Joost Verburg)
; Author: Wez Furlong <wez@thebrainroom.com>
; $Id$
<?php

define('PHPVERSION', phpversion());
define('SOURCEDIR',	 dirname(__FILE__) . "\\..\\..\\");
define('DISTDIR',	 getcwd());

/* for testing, install system files in a safe dir */

if (false) {
	$SYSDIR = "\$INSTDIR\\system";
} else {
	$SYSDIR = "\$SYSDIR";
}

$sections = array(
	"core" => array(
		"label" => "-PHP Core (Required)",
		"files" => array(
			"$SYSDIR" => array(
				"dlls\\*.dll",
				"php4ts.dll",
			),
			"\$INSTDIR" => array(
				"*.txt",
				"php.gif",
				"php.ini-*",
			),
		),
		"extras" => "Call CopyPHPIni\nWriteUninstaller \"\$INSTDIR\\Uninstall.exe\""
	),
 
	"cgi" => array(
		"group" => "SAPI",
		"label" => "CGI",
		"description" => "CGI Interface - should work with most web servers",
	  	"files" => array(
	  		"\$INSTDIR" => array(
	  			"php.exe"
	  		),
			"\$INSTDIR\\sapi" => array(
				"sapi\\pws-php4cgi.reg"
			),
	  	),
	),

	/* CLI is required by the installer */
	"cli" => array(
		"group" => "SAPI",
		"label" => "-CLI",
		"description" => "Command Line Interface for running PHP scripts as batch files",
		"files" => array(
			"\$INSTDIR\\cli" => array(
				"cli\\php.exe"
			),
		),
	),

    "embed" => array(
		"group" => "SAPI",
		"label" => "Embed",
		"description" => "Libraries for embedding PHP into your own projects",
		"files" => array(
			"\$INSTDIR" => array(
				"*.lib"
			),
		),
	),

	"mibs" => array(
		"group" => "Extras",
		"label" => "MIBS for SNMP",
		"description" => "MIB information for the SNMP extension",
		"files" => array(
			"\$INSTDIR\\mibs" => array(
				"mibs\\*"
			),
		),
	),

	"pdfstuff" => array(
		"group" => "Extras",
		"label" => "PDF support files",
		"description" => "Fonts and codepage data files for the PDF extensions",
		"files" => array(
			"\$INSTDIR\\pdf-related" => array(
				"pdf-related\\*"
			),
		),
	),

	"mimemagic" => array(
		"group" => "Extras",
		"label" => "Mime Magic",
		"description" => "The magic information file for the mimemagic extension",
		"files" => array(
			"\$INSTDIR" => array(
				"magic.mime"
			),
		),
	),

	"openssl" => array(
		"group" => "Extras",
		"label" => "OpenSSL",
		"description" => "OpenSSL configuration information which you must read if you plan to use PHP as a Certificate Authority",
		"files" => array(
			"\$INSTDIR\\openssl" => array(
				"openssl\\*"
			),
		),
	),

          

);

$groups = array(
	'SAPI'	=> array("SAPI", "Select which Server API's to install."),
	'EXT'	=> array("Extensions", "Select which extensions to install."),
	'XSAPI' => array("Experimental SAPI", "Experimental Server API's - use at your own risk!"),
	'XEXT'	=> array("Experimental Extensions", "Experimental Extensions - use at your own risk!"),
	'Extras'	=> array("Extras", "Supplemental Files"),
	);

function xglob($pattern)
{
	if (strpos($pattern, '*') === false) {
		return array($pattern);
	}
	$dir = dirname($pattern);
	$pattern = basename($pattern);

	$pattern = str_replace(array('*', '.'), array('.*', '\.'), $pattern);

	$files = array();

	$d = opendir($dir);
	while ($f = readdir($d)) {
		if ($f == '.' || $f == '..' || preg_match('/^\..*\.swp$/', $f))
			continue;
		if (preg_match('@' . $pattern . '@i', $f)) {
			$files[] = $dir . '\\' . $f;
		}
	}
	
	return $files;
}

/* Look for extensions and determine their info based on the source tree.
 * We can determine the name and author from the CREDITS file.
 * We can determine experimental status from the EXPERIMENTAL file.
 * It would be nice to have a standard description line in the CREDITS too.
 */
$extension_abbreviations = array(
	'ifx' => 'informix',
	'gd2' => 'gd',
	);

$sapi_abbreviations = array(
	'apache2'	=>	'apache2filter',
	'srvlt'	=>	'servlet',
);

function add_sections($pattern, $groupname, $abbrev, &$sections, $sourcedirs, $instdir)
{
	$avail = xglob($pattern);

	foreach ($avail as $extname) {
		/* mangle name */
		if (preg_match('/(php_|php4|php)([^_].*)\.dll/', basename($extname), $matches)) {
			$ext = $matches[2];
		} else {
			$ext = basename($extname);
		}

		if (isset($abbrev[$ext])) {
			$ext = $abbrev[$ext];
		}

		$extdir = null;
		
		foreach ($sourcedirs as $sourcedir) {
			// Allow absolute path for separate PECL checkout
			if ($sourcedir{0} == '\\' || $sourcedir{1} == ':')
				$extdir = $sourcedir;
			else
				$extdir = SOURCEDIR . $sourcedir . '/' . $ext . '/';
				
			if (is_dir($extdir))
				break;

			$extdir = null;
		}

		if ($extdir === null || !is_dir($extdir)) {
			echo ";  WARNING: could not find source dir for extension $extname -> $extdir ($ext)\n";
		}

		$exp = file_exists($extdir . 'EXPERIMENTAL');
		if (file_exists($extdir . 'CREDITS')) {
			list($title, $authors, $description) = file($extdir . 'CREDITS');
			$title = trim($title);
			$authors = trim($authors);
			$description = trim($description);

			if (strlen($title) == 0)
				$title = $ext;

		} else {
			$title = $ext;
			$authors = "Unknown, or uncredited";
			$description = "";
		}

		/* build list of support files.
		 * in theory, only needed for the srvlt sapi, but useful to keep this
		 * generic */
		$filepat = preg_replace('/\.[^\.]+$/', '.*', $extname);

		if ($groupname == 'EXT') {
		}

		$sections['ext_' . $ext] = array(
				'group' => ($exp ? 'X' : '') . $groupname,
				'label' => $title,
				'description' => $title . ".\$\\nAuthors: $authors",
				'files' => array(
					"\$INSTDIR\\" . $instdir => array(
						$filepat
						),
					),
/*				'extras' => $groupname == 'EXT' ? "Push \"extension=" . basename($extname) . "\"\nCall AddIniSetting\n\n" : "" */
				);

	}


}

add_sections('extensions\\*.dll', 'EXT', $extension_abbreviations, $sections, array('ext'), 'extensions');
add_sections('sapi\\*.dll', 'SAPI', $sapi_abbreviations, $sections, array('sapi'), 'sapi');

 



$SECTIONS = "";
$sections_stage1 = array();

/* list of files to uninstall */
$uninstall = array();
$rmdirs = array();
/* description texts */
$descriptions = array();

$dirs_no_delete = array("\$SYSDIR", "\$INSTDIR");

foreach ($sections as $sectionid => $sectiondata) {
	$descriptions[] = "\t!insertmacro MUI_DESCRIPTION_TEXT \${Sec$sectionid} \"" . $sectiondata['description'] . "\"";

	if (isset($sectiondata['group'])) {
		$sub = "Sub";
		$group = $sectiondata['group'];
	} else {
		$sub = "";
		$group = '_top_';
	}

	$body = "Section \"" . $sectiondata['label'] . "\" Sec$sectionid\n";
	
	foreach ($sectiondata['files'] as $outputdir => $filelist) {
		$body .= "\tSetOutPath \"$outputdir\"\n";
		foreach ($filelist as $pattern) {
			$files = xglob($pattern);
			foreach ($files as $filename) {
				$uninstall[] = "\tDelete \"$outputdir\\" . basename($filename) . "\"";
				
				$body .= "\tFile \"$filename\"\n";
			}
		}
		if (!in_array($outputdir, $dirs_no_delete) && !isset($rmdirs[$outputdir])) {
			$rmdirs[$outputdir] = "\tRMDir \"$outputdir\"";
		}
	}

	$body .= $sectiondata['extras'];

	$body .= "\nSectionEnd\n";

	$sections_stage1[$group] .= $body . "\n\n";
}

foreach ($sections_stage1 as $group => $data)
{
	if ($group == '_top_') {
		$SECTIONS .= $data . "\n";
	} else {
		$descriptions[] = "\t!insertmacro MUI_DESCRIPTION_TEXT \${SecGroup$group} \"" . $groups[$group][1] . "\"";
		$SECTIONS .= "SubSection /e \"" . $groups[$group][0] . "\" SecGroup$group\n$data\nSubSectionEnd\n\n";
	}
}

/* Now build descriptions */
$DESCRIPTIONS = implode("\n", $descriptions) . "\n";

/* And the uninstallation section */
$UNINSTALL = implode("\n", $uninstall) . "\n" . implode("\n", $rmdirs) . "\n";

?>

!define MUI_PRODUCT "PHP - Hypertext Preprocessor"
!define MUI_VERSION "<?= PHPVERSION ?>"
; The second UI has a wider area for the component names
!define MUI_UI "${NSISDIR}\Contrib\UIs\modern2.exe"	

!include "${NSISDIR}\Contrib\Modern UI\System.nsh"

;--------------------------------
;Configuration

!define MUI_WELCOMEPAGE
!define MUI_LICENSEPAGE
!define MUI_COMPONENTSPAGE
!define MUI_DIRECTORYPAGE
  
!define MUI_FINISHPAGE
;!define MUI_FINISHPAGE_RUN "$INSTDIR\modern.exe"
  
!define MUI_ABORTWARNING
  
!define MUI_UNINSTALLER
!define MUI_UNCONFIRMPAGE
    
;Language
!insertmacro MUI_LANGUAGE "English"

;General
OutFile "InstallPHP<?= PHPVERSION ?>.exe"

SetCompressor bzip2
ShowInstDetails show
;License page
LicenseData "license.txt"

;Folder-selection page
InstallDir "C:\PHP-<?= PHPVERSION ?>"
;define NSIS_CONFIG_LOG "install.log"
;LogSet on

!cd <?= SOURCEDIR ?>win32\installer

;Things that need to be extracted on startup (keep these lines before any File command!)
;Only useful for BZIP2 compression
;Use ReserveFile for your own Install Options ini files too!
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
!insertmacro MUI_RESERVEFILE_SPECIALINI
!insertmacro MUI_RESERVEFILE_SPECIALBITMAP

!cd <?= DISTDIR ?>

!insertmacro MUI_SYSTEM


;--------------------------------
;Installer Sections

Function AddIniSetting
	Pop $R0

	FileOpen $R2 "$INSTDIR\.ini-add" "a"
	FileSeek $R2 0 END
	FileWrite $R2 "$R0$\n"
	FileClose $R2

FunctionEnd

Function CopyPHPIni
	; Ensure that we have a working php.ini to reflect the
	; installation options.
	; Extensions will call a function to activate their entry
	; in the ini file as they are installed.

	Rename "$WINDIR\php.ini" "$WINDIR\php.ini.old"
	CopyFiles "$INSTDIR\php.ini-dist" "$WINDIR\php.ini"

; These files will be deleted during post-installation
	CopyFiles "<?= $SYSDIR ?>\php4ts.dll" "$INSTDIR\php4ts.dll"
	File "<?= dirname(__FILE__) ?>\setini.php"

; Set the extension_dir setting in the php.ini
	Push "extension_dir=$\"$INSTDIR\extensions$\""
	Call AddIniSetting

FunctionEnd

; Generated Section Info
<?= $SECTIONS ?>
; ---------

; Perform final actions after everything has been installed
Section -post
	; Merge ini settings

	Sleep 1000
	
	ExecWait "$\"$INSTDIR\cli\php.exe$\" $\"-n$\" $\"$INSTDIR\setini.php$\" $\"$WINDIR\php.ini$\" $\"$INSTDIR\.ini-add$\""

	Delete "$INSTDIR\.ini-add" ; Created by the AddIniSetting function
	Delete "$INSTDIR\setini.php"
	Delete "$INSTDIR\php4ts.dll"

	; Add to Add/Remove programs list
	WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PHP-<?= PHPVERSION ?>" "UninstallString" "$INSTDIR\Uninstall.exe"
	WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PHP-<?= PHPVERSION ?>" "DisplayName" "PHP-<?= PHPVERSION ?> (Uninstall only)"


SectionEnd

;--------------------------------
;Descriptions

!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
<?= $DESCRIPTIONS ?>
!insertmacro MUI_FUNCTIONS_DESCRIPTION_END

;--------------------------------
;Uninstaller Section

Section "Uninstall"
<?= $UNINSTALL ?>

	Delete "$INSTDIR\Uninstall.exe"
	Delete "$WINDIR\php.ini"
	RMDir "$INSTDIR"
	; Remove from Add/Remove programs list
	DeleteRegKey /ifempty HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PHP-<?= PHPVERSION ?>"

	!insertmacro MUI_UNFINISHHEADER

SectionEnd
; vim:sw=4:ts=4:
; vim600:sw=4:ts=4:noet:fdm=marker