Debian Codegraph @

builds/install/arch-specific/win32/test_installer/fbit.ps1

raw
1 <#
2 .SYNOPSIS
3
4 fbit - test the firebird binary installer on windows
5
6 .DESCRIPTION
7
8 fbit {PARAM [...]]
9
10 Parameters may be passed in any order except for one special case:
11
12 fbit -realclean
13
14 will clean up from previous broken installs. -realclean must the first
15 parameter and subsequent parameters are ignored. Note: - It will run
16 silently and will force cleanup, even if the uninstaller no longer exists.
17
18 By default fbit installs Firebird according to the parameters passed and then immediately
19 uninstalls it. A copy of the install is made, along with the install and uninstall logs.
20
21 REQUIREMENTS
22 ============
23
24 Some knowledge of InnoSetup will be useful. See $FIREBIRD/doc/installation_scripted.txt
25 for more info.
26
27 FBIT Specific Parameters
28 ========================
29 Param Name Value Passed to fbit Comment
30 ---------- -------------------- -------
31 -help - Displays this screen
32 -dryrun - Show what will be done. No changes are made
33 -noarchive - Disables copying of install dir to %USERPROFILE%\fbit
34 Logs and inf files are always saved.
35 -nouninstall - Disable automatic uninstall for this test run
36 -scripted - Sets VERYSILENT, SP and nomsg
37 -testname NameOfTestRun Optional. No spaces allowed. Used for storing test run details.
38
39 -fbinst_exec Path and filename of Installer Will be dynamically determined if not set.
40
41 -config A file name Pass parameters in a config file.
42 Overrides params passed on the command-line.
43
44 The following parameters are set by default. They are unset
45 automatically when a conflicting parameter is passed:
46
47 DefaultParam Default Value set by fbit Unset by
48 ------------- ------------------------- ----------
49 -interactive True -scripted
50 -installtype ServerInstall -client or -devinst
51 -service_task True -apptask
52 -superserver True -classicserver or -superclassic
53
54 Firebird Installer specific Parameters
55 ======================================
56 Param Name Value passed to installer Action when set
57 ---------- ------------------------- ---------------
58 -copygdslib CopyFbClientAsGds32Task Copy fbclient to <SYS> and rename to gds32
59 -force FORCE Force installation
60 -noautostart - Does not set AutoStartTask
61 -nocopyfblib - Does not copy fbclient to <SYS>
62 -password /SYSDBAPASSWORD=%PASSWORD% Changes SYSDBA password from masterkey
63 If -password is not passed on the command-line and
64 ISC_PASSWORD is set then ISC_PASSWORD will be used.
65 -legacy_auth EnableLegacyClientAuth Adds support for legacy authentication
66
67 Installation Tasks
68 ==================
69 Param Name Value passed to /TASKS Comment
70 ------------- ---------------------- ---------------
71 -apptask UseApplicationTask Will not install as a service
72 -classicserver UseClassicServerTask Will configure classic server
73 -superclassic UseSuperClassicTask Will configure super classic
74
75 Installation Types
76 ==================
77 Param Name Value passed to /TYPE Comment
78 ------------ --------------------- -------
79 -client ClientInstall Minimal working client install
80 -devinst DeveloperInstall Everything but the server.
81 -server_install ServerInstall
82
83 Uninstallation
84 ==============
85 Param Name Value passed to uninstaller Comment
86 -------------- --------------------------- -------
87 -clean CLEAN Completely remove an existing firebird install.
88 Assumes installed version of Firebird matches
89 $firebirdrootdir\$firebird_base_ver set in fbit script.
90
91 -realclean Calls uninstaller if it exists.
92 Deletes the $firebirdrootdir\$firebird_base_ver dir
93 Removes the list of firebird shared dll's in the registry.
94 BEWARE - this should only be used when normal CLEAN is no
95 longer working correctly.
96
97 -realclean -force Do not prompt during clean up. (Currently not implemented.)
98
99 Generic InnoSetup parameters
100 ============================
101 Param Name Value passed to installer Comment
102 ---------- ------------------------- -------
103 -nomsg SUPPRESSMSGBOXES Suppress message boxes
104 -nocancel NOCANCEL Prevents user cancelling install
105 -silent SILENT
106 -sp SP- Disables the 'This will install...' prompt
107 -verysilent VERYSILENT
108
109
110 .PARAMETER help
111 Outputs this help screen and quits.
112
113 .INPUTS
114
115 None.
116
117 .OUTPUTS
118
119 None.
120
121 .EXAMPLE
122
123 fbit -scripted
124
125 (Run a scripted server install followed immediately by a scripted uninstall.
126 Adding -verbose is recommended.)
127
128 .EXAMPLE
129
130 fbit -realclean
131
132 (Clean up previous firebird install)
133
134 .EXAMPLE
135
136 fbit -scripted -client
137
138 (Test scripted install of firebird client)
139
140 #>
141
142
143 [CmdletBinding(DefaultParameterSetName = "StandardParams" )]
144 param(
145
146 # Load a configuration file
147 [string]$config,
148
149 [Parameter(Mandatory = $true, ParameterSetName = "classic")]
150 [switch]$classicserver,
151
152 [Parameter(Mandatory = $true, ParameterSetName = "superclassic")]
153 [switch]$superclassic,
154
155 # is the default. No need to set.
156 [switch]$superserver,
157 # use scripted install instead of default interactive
158 [switch]$scripted,
159 # uninstall an existing install. (install is the default.)
160 [switch]$uninstall,
161 # Ignore errors as far as possible. Used for -realclean
162 [switch]$force,
163 # install firebird. This is the default.
164 [switch]$install,
165 # Remove as many traces of Firebird as possible from the system.
166 [switch]$realclean,
167 # Print generated command to screen before execution.
168 [switch]$show_final_command,
169 # Just install. Default behaviour is to install and uninstall.
170 [switch]$nouninstall,
171 # verify current install
172 [switch]$check_install,
173 # verify current install
174 [switch]$check_uninstall,
175
176 # parameters specific to this script
177 [string]$inno_params_from_cmdline,
178 [string]$fbinst_exec,
179 [string]$testname = "fbit_test",
180
181 # ### Params to control InnoSetup
182
183 [switch]$apptask,
184 [switch]$clean,
185 [switch]$client_install,
186 [string]$components = "",
187 [switch]$copygdslib,
188 [switch]$dev_install,
189 [switch]$noarchive,
190 [switch]$noautostart,
191 [switch]$nocancel,
192 [switch]$nocopyfblib,
193 [switch]$nomsg,
194 [string]$password = "masterkey",
195 [switch]$server_install,
196 [switch]$silent,
197 [switch]$sp,
198 # install Firebird as a service. This is the default. See also apptask.
199 [switch]$service_task,
200 [string]$task_list = "",
201 [switch]$verysilent,
202
203 # General parameters. Do not add anything after help
204
205 [switch]$dryrun,
206 [switch]$help
207
208
209
210 )
211
212
213 # Vars available to all functions in script
214 $TAB = ' '
215 $ErrorCount = 0
216 [string]$action = ""
217 # Full Install/Uninstall command that will be executed
218 [string]$finalcmd
219 # The actual list of commands that will be passed to the installer/uninstaller
220 [string]$full_cmdline = ""
221 # Override timestamp
222 [string]$run_timestamp
223
224 [boolean]$IsVerbose = $false
225 [boolean]$IsDebug = $false
226
227 [string]$uninst_cmdline = ""
228 [string]$inno_silent = ""
229
230
231 [System.ConsoleColor]$fgcol = "Black"
232 [System.ConsoleColor]$fgred = "Red"
233 [System.ConsoleColor]$fggreen = "Green"
234
235 Import-Module .\fbit-functions.psm1
236
237 <#
238 TO DO list
239
240 #>
241
242
243 <#
244 .SYNOPSIS
245 Load a simple config file and assign key-value pairs to $key variables
246
247 .DESCRIPTION
248
249
250 .EXAMPLE
251 # Comment lines may start with # or //
252 # Variables are strings by default
253 avar="AValue"
254 # Booleans must be passed as 0 or 1 and are converted to boolean types
255 aboolean=$true
256 # Switches may be set by passing the switch name prefixed with a hyphen
257 -aswitch
258 # Or just passed 'as is'
259 aswitch
260
261 .NOTES
262 General notes
263 #>
264 function LoadConfig( [string] $_conffile ) {
265 Write-Debug "Entering function $($MyInvocation.MyCommand.Name)"
266 Write-Debug "_conffile is $_conffile"
267 foreach ($i in $(Get-Content $_conffile)) {
268 # Trim any lead/trailing whitespace
269 # Include value in quotes if you need trailing whitespace!
270 $local:line = $i.trim()
271 if ($local:line -ne '') {
272 if ( -not ($line.startswith( '#' ) -or $line.startswith( '//' )) ) {
273 Write-Verbose "Processing $local:line"
274
275 $local:avalue = $null
276 $local:akey = $null
277
278 $local:akey = $i.split('=')[0]
279 if ( $null -ne $local:akey ) { $local:akey = $local:akey.trim() }
280
281 # Check if key is a switch.
282 if ( $local:akey.StartsWith('-') ) {
283 Write-Debug "$local:akey is a switch"
284 Set-Variable -Scope global -Name $local:akey.TrimStart('-') -Value $true
285 Set-Variable -Scope Script -Name $local:akey.TrimStart('-') -Value $true
286 continue
287 }
288
289 try {
290 $local:avalue = $i.split('=', 2)[1]
291 } catch {
292 Write-Debug "Setting $local:akey to true"
293 Set-Variable -Scope global -Name $local:akey -Value $true
294 Set-Variable -Scope Script -Name $local:akey -Value $true
295 continue
296 }
297
298 if ( $null -ne $local:avalue ) { $local:avalue = $local:avalue.trim() }
299 Write-Debug "akey is $local:akey and avalue is $local:avalue"
300 # Test avalue and change type to boolean if necessary
301 switch ( $local:avalue ) {
302 { $_ -eq "1" } {
303 Write-Debug "Setting $local:akey to true"
304 Set-Variable -Scope Global -Name $local:akey -Value $true
305 Set-Variable -Scope Script -Name $local:akey -Value $true
306 }
307 { $_ -eq "0" } {
308 Write-Debug "Setting $local:akey to false"
309 Set-Variable -Scope Global -Name $local:akey -Value $false
310 Set-Variable -Scope Script -Name $local:akey -Value $false }
311 { $_ -eq $null } {
312 Write-Debug "Setting $local:akey to true"
313 Set-Variable -Scope Global -Name $local:akey -Value $true
314 Set-Variable -Scope Script -Name $local:akey -Value $true
315 }
316 Default {
317 Set-Variable -Scope global -Name $local:akey -Value $local:avalue
318 Set-Variable -Scope Script -Name $local:akey -Value $local:avalue
319 }
320 }
321 } else {
322 Write-Debug "NOT processing commented $local:line"
323
324 }
325 }
326 }
327 # Set-PSDebug -Off
328 # Get-ChildItem Variable:
329 # Pause "In $($MyInvocation.MyCommand.Name) called from line $($MyInvocation.ScriptLineNumber)"
330 Write-Debug "Leaving function $($MyInvocation.MyCommand.Name)"
331 }
332
333
334 function print_vars( [string]$_action ) {
335 Write-Debug "Entering function $($MyInvocation.MyCommand.Name)"
336
337 $local:varfile = "$fbinstalllogdir/${testname}-${_action}-$run_timestamp.vars"
338 if ( $script:IsDebug ) {
339 Get-ChildItem Variable:
340 Pause "In $($MyInvocation.MyCommand.Name) called from line $($MyInvocation.ScriptLineNumber)"
341 }
342 if ( $script:IsVerbose ) {
343 spacer > $local:varfile
344 if ( check_file_exists "fb_build_vars_${env:PROCESSOR_ARCHITECTURE}.txt" ) {
345 spacer "Firebird Build Environment" >> $local:varfile
346 Get-Content fb_build_vars_${env:PROCESSOR_ARCHITECTURE}.txt >> $local:varfile
347 spacer "Firebird Build Environment END" >> $local:varfile
348 spacer >> $local:varfile
349 }
350 spacer 'Global Vars' >> $local:varfile
351 Get-Variable -Scope global >> $local:varfile
352 spacer 'Global Vars END' >> $local:varfile
353 spacer >> $local:varfile
354 spacer 'Env Vars' >> $local:varfile
355 env | grep '^FB' >> $local:varfile
356 env | grep '^ISC' >> $local:varfile
357 spacer 'Env Vars END' >> $local:varfile
358 spacer 'Script Vars' >> $local:varfile
359 Get-Variable -Scope script | Format-Table -AutoSize -Wrap >> $local:varfile
360 spacer 'Script Vars END' >> $local:varfile
361 spacer >> $local:varfile
362 spacer 'Local Vars' >> $local:varfile
363 Get-Variable -Scope local >> $local:varfile
364 spacer 'Local Vars END' >> $local:varfile
365 spacer >> $local:varfile
366 }
367 Write-Debug "Leaving $($MyInvocation.MyCommand.Name)"
368
369 }
370
371 function show-help() {
372 Get-Help $PSCommandPath -ShowWindow
373 }
374
375
376
377
378
379 <#
380 .SYNOPSIS
381 Set defaults based on lack of supplied arguments
382 #>
383 function check_params() {
384
385 if ( $(Test-Path variable:$script:MyInvocation.BoundParameters['Verbose'] ) ) {
386 $script:IsVerbose = $script:MyInvocation.BoundParameters['Verbose'].IsPresent
387 }
388
389 if ( $(Test-Path variable:$script:MyInvocation.BoundParameters['Debug'] ) ){
390 $script:IsDebug = $script:MyInvocation.BoundParameters['Debug'].IsPresent
391 }
392
393 if ( $script:config ) {
394 Write-Output "script:config is $script:config"
395 LoadConfig $script:config
396 } else {
397 Write-Output "$($MyInvocation.MyCommand.Name) Not calling script:config $script:config"
398 }
399
400 if ( $script:IsDebug ) {
401 Get-ChildItem Variable:
402 Pause "In $($MyInvocation.MyCommand.Name) called from line $($MyInvocation.ScriptLineNumber ) After testing script:config $script:config"
403 }
404
405 # ### fbit related param checks. These control what gets executed. ### #
406 # By default the script is designed to install, check install and uninstall.
407 # Those defaults are over-ridden by "realclean", "uninstall", and "check_install"
408
409 # If realclean is set then we must try to uninstall/cleanup.
410 # fbit will exit after "clean" or "realclean" has finished.
411 if ( $script:realclean ) { $script:uninstall = $true }
412
413 # Default to install if uninstall not set. uninstall is run automatically after.
414 # Pass nouninstall if the intention is to keep the installation for further testing
415 $script:install = !$script:uninstall
416
417 # By default we install unless uninstall has been set.
418 # If realclean has been set then we really clean up and then exit.
419 # If check_install has been set then we check the install and exit.
420 # If check_uninstall has been set then we check the install and exit.
421 if ( $script:install ) { $script:action = "install" }
422 if ( $script:uninstall ) { $script:action = "uninstall" }
423 if ( $script:realclean) { $script:action = "realclean" }
424 if ( $script:check_install -and !$realclean ) { $script:action = "check_install" }
425 if ( $script:check_uninstall ) { $script:action = "check_uninstall" }
426
427
428 # ### InnoSetup related param checks ### #
429
430 $script:interactive = !$script:scripted
431
432
433 # default to superserver if neither of classic nor superclassic are set
434 $script:superserver = !($script:classicserver -or $script:superclassic)
435
436 # default to server install if neither of dev nor client install are set
437 $script:server_install = !($script:dev_install -or $script:client_install )
438
439 # Install Firebird as a service if $apptask not set
440 $script:service_task = !($script:apptask)
441
442 # If ISC_PASSWORD is set and password defaults to masterkey then set password
443 # to ISC_PASSWORD.
444 # If password != masterkey then we over-ride the value of $env:ISC_PASSWORD
445 if ( $env:ISC_PASSWORD -and ($script:password -eq "masterkey" ) ) {
446 $script:password = $env:ISC_PASSWORD
447 }
448
449 # ### END of InnoSetup related param checks ### #
450
451 if ( $script:IsDebug ) {
452 Get-ChildItem Variable:
453 Pause "In $($MyInvocation.MyCommand.Name) called from line $($MyInvocation.ScriptLineNumber ) Before leaving function."
454 }
455 }
456
457
458
459 <#
460 .SYNOPSIS
461 Check registry for shared dlls
462
463 .NOTES
464 Currently checks for all references to firebirdin the list of sharedDlls.
465 Perhaps this should be limited to include a firebird major version check.
466 #>
467 function check_shared_dlls() {
468
469 $local:shareddlls = (reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs)
470 $local:count = (Select-String -InputObject "$local:shareddlls" -Pattern "firebird" -AllMatches).Matches.Count
471
472 if ( $local:count -gt 0 ) {
473 $script:ErrorCount += 1
474 Write-Output "$script:TAB Shared firebird dlls found in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs"
475 } else {
476 Write-Output "$script:TAB No shared firebird dlls found in registry"
477 }
478
479 }
480
481
482 <#
483 .SYNOPSIS
484 Make a copy of the install
485 #>
486 function copy_install() { # ( [string]$_sourceFolder, [string]$_targetFolder ) {
487
488 $_source_folder = $script:FIREBIRD
489 $_target_folder = $script:copy_install_target
490
491 Write-Verbose "Saving Firebird Installation to $_target_folder"
492
493 if ( ! ( Test-Path -Path $_target_folder ) ) { mkdir $_target_folder }
494 Copy-Item -Path $_source_folder\* -Destination $_target_folder -Recurse -Force | Out-Null
495 if ( Test-Path $script:install_log_file -PathType leaf ) {
496 Copy-Item -Path $script:install_log_file -Destination $_target_folder -Force | Out-Null
497 }
498 if ( Test-Path $script:install_inf_file -PathType leaf ) {
499 Copy-Item -Path $script:install_inf_file -Destination $_target_folder -Force | Out-Null
500 }
501
502 }
503
504 <#
505 .SYNOPSIS
506 Check that the sec db has been initialised
507 .DESCRIPTION
508 Check that the sec db has been initialised.
509 Also check if masterkey is used for the SYSDBA password.
510
511 .NOTES
512
513 if user has specified a password and it is not masterkey then
514 verify that
515 - the password works
516 - that masterkey does not work.
517
518
519 #>
520 function check_server_sec_db() {
521
522 # Check that the security db exists
523 $local:retval = check_file_exists "$script:FIREBIRD\security${script:fbmajver}.fdb"
524 if ( !$local:retval ) {
525 $script:fgcol = ( $script:action | Select-String -Pattern "un" -NotMatch -Quiet ) ? $script:fgred : $script:fggreen
526 Write-Host -ForegroundColor $script:fgcol "${TAB}$script:FIREBIRD\security${script:fbmajver}.fdb not found."
527 return
528 }
529
530 # Now check that isql is available
531 $local:retval = check_file_exists "$script:FIREBIRD/isql.exe"
532 if ( !$local:retval ) {
533 $script:fgcol = ( $script:action | Select-String -Pattern "un" -NotMatch -Quiet ) ? $script:fgred : $script:fggreen
534 Write-Host -ForegroundColor $script:fgcol "${TAB}$FIREBIRD\isql.exe does not exist. Cannot check security db"
535 return
536 }
537
538 #Write-Output "${TAB}Test the password we used during the install..."
539
540 Write-Output "exit;" > $env:Temp\infile.txt
541
542 foreach ( $apw in "$script:password", "masterkey", "masterke" ) {
543 Exec_SQL "localhost:employee" "SYSDBA" "$apw"
544 if ( $apw -eq "$script:password") {
545 $local:found_str_is_fail = $true
546 } else {
547 $local:found_str_is_fail = $false
548 }
549 $local:teststr = "Your user name and password are not defined. Ask your database administrator to set up a Firebird login."
550 $local:retval = $(check_file_output "$env:Temp\outfile.txt" "$local:teststr")
551
552 print_output "${TAB}Password test with $apw " $local:retval $local:found_str_is_fail "PASSED" "FAILED"
553
554 }
555
556 }
557
558 <#
559 .SYNOPSIS
560 Use the $FIREBIRD variable to check the current firebird installation
561
562 .DESCRIPTION
563 Long description
564
565 .EXAMPLE
566 An example
567
568 .NOTES
569 General notes
570 #>
571 function check_firebird_installed() {
572
573 $local:retval = check_file_exists $script:FIREBIRD -_isdir
574 if ( ! $local:retval ) {
575 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fgred : $script:fggreen
576 Write-Host -ForegroundColor $script:fgcol "${TAB}$script:FIREBIRD directory does not exist."
577 return
578 }
579
580 $local:retval = check_file_exists "${script:FIREBIRD}\firebird.exe"
581 if ( $local:retval ) {
582 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fggreen : $script:fgred
583 Write-Host -ForegroundColor $script:fgcol "${TAB}Firebird Server appears to be installed."
584 $script:server_installed = $true
585 } else {
586 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fgred : $script:fggreen
587 Write-Host -ForegroundColor $script:fgcol "${TAB}Firebird Server does NOT appear to be installed."
588 }
589
590
591 $local:retval = check_file_exists "$script:FIREBIRD/isql.exe"
592 if ( $local:retval ) {
593 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fggreen : $script:fgred
594 Write-Host -ForegroundColor $script:fgcol "${TAB}Firebird Dev Tools appears to be installed."
595 $script:devtools_installed = $true
596 } else {
597 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fgred : $script:fggreen
598 Write-Host -ForegroundColor $script:fgcol "${TAB}Firebird Dev Tools do NOT appear to be installed."
599 }
600 $local:retval = check_file_exists "$script:FIREBIRD/fbclient.dll"
601 if ( $local:retval ) {
602 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fggreen : $script:fgred
603 Write-Host -ForegroundColor $script:fgcol "${TAB}Firebird Client appears to be installed."
604 $script:client_installed = $true
605 } else {
606 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fgred : $script:fggreen
607 Write-Host -ForegroundColor $script:fgcol "${TAB}Firebird Client does NOT appear to be installed."
608 }
609
610 }
611
612
613 function check_service_installed( [string]$_servicename ) {
614
615 $local:ExpectedServiceName = "FirebirdServerDefaultInstance"
616
617 $local:ActualServiceName = Get-Service -ErrorAction ignore -Name $local:ExpectedServiceName | Select-Object -ExpandProperty Name
618 if (check_result $local:ExpectedServiceName $local:ActualServiceName $true ) {
619 $script:fgcol = ( $script:action -eq "check_install" ) ? $script:fggreen : $script:fgred
620 Write-Host -ForegroundColor $script:fgcol "${TAB}$local:ExpectedServiceName is installed. "
621 } else {
622 $script:fgcol = ( $script:action -eq "check_uninstall" ) ? $script:fggreen : $script:fgred
623 Write-Host -ForegroundColor $script:fgcol "${TAB}$local:ExpectedServiceName is NOT installed. "
624 }
625 }
626
627
628 function load_fb_build_env() {
629 Write-Debug "Entering function $($MyInvocation.MyCommand.Name)"
630
631 # Build_All.bat should generate fb_build_vars_${env:PROCESSOR_ARCHITECTURE}.txt
632 $local:fbbuild_vars_file = Get-Content "fb_build_vars_${env:PROCESSOR_ARCHITECTURE}.txt"
633
634 $script:fbbuild_vars = @{}
635 # $local:fbbuild_vars_file | Sort-Object -Property key | ForEach-Object {
636 $local:fbbuild_vars_file | ForEach-Object {
637 $s = $_ -split "="
638 $s[1] = $s[1].Trim()
639 $script:fbbuild_vars.Add($s[0], $s[1] )
640 }
641 if ( $script:IsDebug ) {
642 Get-ChildItem Variable:
643 Pause "In $($MyInvocation.MyCommand.Name) called from line $($MyInvocation.ScriptLineNumber) "
644 }
645
646 # Check that we have fbmajver and fix it if not.
647 # Normally this should not happen if we have just built firebird
648 if ( ! $script:fbbuild_vars.ContainsKey('FB_MAJOR_VER') ) {
649 # Try to locate build_no.h
650 $local:fb_root_path= $script:fbbuild_vars.'FB_ROOT_PATH'
651 if ( Test-Path "${local:fb_root_path}\src\jrd\build_no.h" -PathType Leaf ) {
652
653 foreach ($aline in $(Get-Content Z:\FB30\FB3-dev\src\jrd\build_no.h | grep "#define FB_")) {
654 $s = $aline.split(" ")
655 $s[2] = $s[2].Trim('"')
656 $script:fbbuild_vars.Add($s[1], $s[2] )
657 }
658 $script:fbmajver = $script:fbbuild_vars.'FB_MAJOR_VER'
659 $script:fbpackageNum = $script:fbbuild_vars.ContainsKey('FB_PACKAGE_NUMBER') ? $script:fbbuild_vars.'FB_PACKAGE_NUMBER' : 0
660
661 $script:fbbuild_vars.'FBBUILD_FILE_ID' = $script:fbbuild_vars.'FB_MAJOR_VER' + "." +
662 $script:fbbuild_vars.'FB_MINOR_VER' + "." +
663 $script:fbbuild_vars.'FB_REV_NO' + "." +
664 $script:fbbuild_vars.'FB_BUILD_NO' + "-" +
665 $script:fbpackageNum + "-" +
666 $script:fbbuild_vars.'FB_TARGET_PLATFORM'
667 }
668 }
669
670 $script:fbbuild_vars = [System.Collections.SortedList] $script:fbbuild_vars
671
672 $script:fbbuild_vars.GetEnumerator() | ForEach-Object {
673 Write-Verbose "$($_.Key): $($_.Value)"
674 }
675
676 Write-Debug "Leaving function $($MyInvocation.MyCommand.Name)"
677
678 }
679
680
681 <#
682 .SYNOPSIS
683 Analyse the installation and environment. Set some variables.
684 #>
685 function check_environment() {
686 Write-Debug "Entering function $($MyInvocation.MyCommand.Name)"
687
688 # If passed via command line
689 if ( $script:fbinst_exec -ne "" ) {
690 Write-Debug "Determine build env from $script:fbinst_exec"
691 # Set-PSDebug -Trace 2
692 $path_file = @{}
693 $path_file = $script:fbinst_exec -split "\\", -2
694 $path_file = $path_file[1] -split ".exe" , 2
695 $script:FirebirdInstallVer = $path_file[0]
696 $_astr = $script:FirebirdInstallVer -split "\."
697 $_astr = $_astr[0] -split "-"
698 $script:fbmajver = $_astr[1]
699 # Set-PSDebug -Trace 0
700 } else {
701 Write-Debug "Determine build env dynamically"
702 load_fb_build_env
703 switch ( $script:fbmajver ) {
704 "3" {
705 $local:fb_file_id = $script:fbbuild_vars.'FBBUILD_FILE_ID' -replace "-", "_"
706 }
707 Default {
708 $local:fb_file_id = $script:fbbuild_vars.'FBBUILD_FILE_ID'
709 }
710 }
711
712 if ( $local:fb_file_id -eq "" ) {
713 Write-Output "Unable to set fbinst_exec."
714 } else {
715 $script:FirebirdInstallVer = "Firebird-${local:fb_file_id}"
716 $script:fbinst_exec = -join ($script:fbbuild_vars.'FB_ROOT_PATH', "\builds\install_images\", $script:FirebirdInstallVer , '.exe' )
717 Write-Verbose "Setting fbinst_exec to $script:fbinst_exec"
718 }
719
720 }
721 if ( $script:IsDebug ) {
722 Pause "In $($MyInvocation.MyCommand.Name) called from line $($MyInvocation.ScriptLineNumber)"
723 }
724
725 # Set-PSDebug -Trace 2
726 $script:fbinstalllogdir = "$env:userprofile\fbit-tests\logs"
727 $script:fbinstallcopydir = "$env:userprofile\fbit-tests\install_archive"
728
729
730 #This is just the default root directory for all versions of firebird
731 $script:firebirdrootdir = "$env:ProgramFiles\Firebird"
732 $script:firebird_base_ver = "Firebird_" + $script:fbmajver + "_0"
733
734 # ### FIXME - allow assigning a non-default dir
735 $script:FIREBIRD = "$script:firebirdrootdir\$script:firebird_base_ver"
736
737 $script:uninstallexe = "${script:FIREBIRD}\unins000.exe"
738
739 if ( ! $(Test-Path variable:run_timestamp) ) {
740 $script:run_timestamp = runtimestamp
741 }
742
743 $script:install_inf_file = "${script:fbinstalllogdir}\${script:testname}-install-$script:FirebirdInstallVer-$script:run_timestamp-saved.inf"
744 $script:install_log_file = "$script:fbinstalllogdir\${script:testname}-install-$script:FirebirdInstallVer-$script:run_timestamp.log"
745 $script:uninstall_log_file = "$script:fbinstalllogdir\${script:testname}-uninstall-$script:FirebirdInstallVer-$script:run_timestamp.log"
746 $script:copy_install_target = "$script:fbinstallcopydir\$script:testname-install-$script:FirebirdInstallVer-$script:run_timestamp"
747
748 $script:boiler_plate_install = " /DIR=`"$script:FIREBIRD`" /LOG=`"$script:install_log_file`" /SAVEINF=`"$script:install_inf_file`" "
749 $script:boiler_plate_uninstall = " /LOG=`"$script:uninstall_log_file`" "
750
751 if ( $script:IsDebug ) {
752 # Set-PSDebug -Trace 0
753 Get-ChildItem Variable:
754 Pause "In $($MyInvocation.MyCommand.Name) called from line $($MyInvocation.ScriptLineNumber)"
755 }
756 Write-Debug "Leaving function $($MyInvocation.MyCommand.Name)"
757
758 }
759
760
761 function check_innosetup_params() {
762 Write-Debug "Entering function $($MyInvocation.MyCommand.Name)"
763
764 if ( ! $script:dryrun ) {
765 $local:patharray = "$script:fbinstalllogdir", "$script:fbinstallcopydir"
766 foreach ($apath in $local:patharray) {
767 if ( check_file_exists "$apath" $true ) {
768 if ($? -eq $false) { mkdir -Path "$apath" }
769 }
770 }
771 }
772
773 if ( $script:scripted ) {
774 $script:inno_verysilent = " /VERYSILENT "
775 $script:inno_sp = " /SP- "
776 $script:inno_nomsg = " /SUPPRESSMSGBOXES "
777 }
778
779
780 if ( $script:uninstall) {
781 if ( $script:realclean ) { $script:clean = $true }
782 } else {
783
784 # check params for install
785 if ( $script:client_install) {
786 $script:task_list = ""
787 $script:inno_installtype = "ClientInstall"
788 $script:inno_devinst = ""
789 $script:inno_server_install = ""
790 $script:inno_classicserver = ""
791 $script:inno_superclassic = ""
792 $script:inno_superserver = ""
793 }
794
795 if ( $script:dev_install) {
796 $script:task_list = ""
797 $script:inno_installtype = "DeveloperInstall"
798 $script:inno_client = ""
799 $script:inno_server_install = ""
800 $script:inno_classicserver = ""
801 $script:inno_superclassic = ""
802 $script:inno_superserver = ""
803 }
804
805 # FIXME - CODE REVIEW REQUIRED
806 if ( $script:server_install ) {
807
808 $script:inno_installtype = "ServerInstall"
809 $script:inno_client = ""
810 $script:inno_devinst = ""
811
812 if ( $cscript:lassicserver ) {
813 $script:task_list = " UseClassicServerTask "
814 $script:inno_classicserver = 1
815 $script:inno_superserver = ""
816 $script:inno_superclassic = ""
817 } else {
818 if ( $script:superclassic ) {
819 $script:task_list = " UseSuperClassicTask "
820 $script:inno_superserver = ""
821 $script:inno_classicserver = ""
822 $script:inno_superclassic = 1
823 } else {
824 $script:task_list = " UseSuperServerTask "
825 $script:inno_superclassic = ""
826 $script:inno_classicserver = ""
827 $script:inno_superserver = 1
828 }
829 }
830
831 $script:inno_sysdbapassword = " /SYSDBAPASSWORD=`"$script:password`" "
832
833 } # end if ( $server_install )
834
835 # Now start building our task list
836
837 # At this stage, if task_list is not defined then we are not doing a server install
838 if ( $script:task_list ) {
839 if ( $script:apptask ) {
840 $script:task_list += ", UseApplicationTask "
841 $script:inno_installtype = "CustomInstall"
842 $script:inno_service_task = ""
843 } else {
844 $script:task_list += ", UseServiceTask "
845 }
846
847 if ( ! $script:noautostart ) {
848 $script:task_list += ", AutoStartTask "
849 # $script:inno_installtype="CustomInstall"
850 }
851
852 # ### FIXME - we need to integrate /MERGE_TASKS and use it here
853 if ( ! $script:nocopyfblib ) {
854 $script:task_list += ", CopyFbClientToSysTask "
855 # $script:inno_installtype="CustomInstall"
856 }
857
858 if ( $script:copygdslib ) {
859 $script:task_list += ", CopyFbClientAsGds32Task"
860 $script:inno_installtype = "CustomInstall"
861 }
862
863 if ( ! $(Test-Path variable:legacy_auth) ) {
864 $script:task_list += ", EnableLegacyClientAuth"
865 $script:inno_installtype = "CustomInstall"
866 }
867 }
868
869 } # End check innosetup params for install
870
871 spacer
872 Write-Debug "Leaving function $($MyInvocation.MyCommand.Name)"
873 }
874
875
876 function clean_registry() {
877
878 # Loop through HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
879 # and search for "The Firebird Project" and uninstall all ms runtimes
880
881
882 return
883 }
884
885
886 function build_inno_cmd() {
887 Write-Debug "Entering function $($MyInvocation.MyCommand.Name)"
888
889 # set up the command line variables we will use
890
891
892
893 # ### Params shared by install and uninstall actions ###
894
895 if ( $script:force ) {
896 $script:inno_params_from_cmdline += " /FORCE "
897 $script:uninst_cmdline += " /FORCE "
898 }
899
900 if ( $script:inno_nomsg ) {
901 $script:inno_params_from_cmdline += $script:inno_nomsg
902 $script:uninst_cmdline += $script:inno_nomsg
903 }
904
905 if ( $script:inno_sp ) {
906 $script:inno_params_from_cmdline += $script:inno_sp
907 $script:uninst_cmdline += $script:inno_sp
908 }
909
910 if ( $script:inno_verysilent ) {
911 $script:inno_params_from_cmdline += $script:inno_verysilent
912 $script:uninst_cmdline += $script:inno_verysilent
913 }
914
915 # ### Params used exclusively by the uninstall action ###
916 if ( $script:clean ) {
917 $script:uninst_cmdline += " /CLEAN "
918 }
919
920 if ( $script:inno_silent ) { $script:inno_params_from_cmdline += " /SILENT " }
921
922 if ( $script:nocancel ) { $script:inno_params_from_cmdline += " /NOCANCEL " }
923
924 # ### Params used exclusively for install action ###
925
926 if ( $script:install ) {
927 # Setting PASSWORD is only relevant for a server install
928 if ( $script:password -ne "masterkey" ) {
929 $script:inno_params_from_cmdline += " $script:inno_sysdbapassword "
930 $script:inno_installtype = "CustomInstall"
931 }
932
933 if ( $script:inno_installtype -eq "CustomInstall" ) {
934
935 if ( $script:client_install ) { $script:inno_components = "ClientComponent" }
936 if ( $script:dev_install ) { $script:inno_components = "DevAdminComponent,ClientComponent" }
937 if ( $script:server_install ) { $script:inno_components = "ServerComponent,DevAdminComponent,ClientComponent" }
938
939 } else {
940 $script:inno_components = "ServerComponent,DevAdminComponent,ClientComponent"
941 }
942
943 if ( $script:TASK_LIST ) {
944 $script:full_cmdline = " /TYPE=`"$script:inno_installtype`" /TASKS=`"$script:task_list`" /COMPONENTS=`"$script:inno_components`" $script:inno_params_from_cmdline "
945 } else {
946 $script:full_cmdline = "/TYPE=`"$script:inno_installtype`" /COMPONENTS=`"$script:inno_components`" $script:inno_params_from_cmdline "
947 }
948 }
949
950 # Always add on the boiler plate log and inf output to the command
951 $script:full_cmdline += $script:boiler_plate_install
952 $script:uninst_cmdline += $script:boiler_plate_uninstall
953
954 Write-Debug "Leaving function $($MyInvocation.MyCommand.Name)"
955
956 }
957
958
959 function dry_run( [string]$_action, [string]$_exec ) {
960
961 Write-Output "Dry run - not executing $_action with $_exec"
962
963 }
964
965 function run_check_install() {
966
967
968 if ( $script:action | Select-String -Pattern "un" -SimpleMatch -Quiet ) {
969 $script:action = "check_uninstall"
970 Write-Output "Checking uninstallation..."
971 } else {
972 $script:action = "check_install"
973 Write-Output "Checking installation..."
974 }
975 # What is the most reliable way?
976 check_firebird_installed
977
978 check_service_installed
979 check_server_sec_db
980
981 }
982
983 function run_installer() {
984 [OutputType([int])]
985 [cmdletbinding()]
986 Param()
987 begin {
988 Write-Debug "Entering function $($MyInvocation.MyCommand.Name)"
989 $local:retval = 0
990 }
991
992 # We use BEGIN..PROCESS..END here so that we can mask the output of copyinstall and
993 # allow the function to return an integer instean of an object.
994 process {
995 build_inno_cmd
996 print_vars "$script:action"
997
998 if ( ! ( check_file_exists "$script:fbinst_exec" ) ) {
999 Write-Error "fbinst_exec does not exist. Quitting."
1000 $local:retval = 1
1001 return
1002 }
1003
1004 Write-Verbose "Cmdline to execute is $script:fbinst_exec $script:full_cmdline"
1005
1006 if ( $dryrun ) {
1007 dry_run $script:action $script:fbinst_exec
1008 } else {
1009
1010 $errorActionPreference = "Stop"
1011 $env:SEE_MASK_NOZONECHECKS = 1
1012
1013 $local:retval = Invoke-Command "$script:fbinst_exec" "$script:full_cmdline" "Running Firebird Installer"
1014
1015 if ( $local:retval -ne 0 ) {
1016 iss_error ( $local:retval )
1017 } else {
1018 Write-Verbose "Completed Firebird Installation"
1019
1020 if ( ! $script:noarchive ) {
1021 # Assign output to null here or else returned $local:retval below becomes an object, not an int
1022 $null = copy_install
1023
1024 }
1025 }
1026 }
1027 }
1028 end {
1029 Write-Debug "Leaving function $($MyInvocation.MyCommand.Name)"
1030 return $local:retval
1031 }
1032 }
1033
1034
1035 function run_uninstaller() {
1036
1037 $script:action = "uninstall"
1038 build_inno_cmd
1039 print_vars "$script:action"
1040
1041 Write-Verbose "uninst_cmdline is $script:uninst_cmdline"
1042
1043 if ( $dryrun ) {
1044 dry_run $script:action $script:uninstallexe
1045 } else {
1046
1047 $local:retval = check_file_exists "$script:uninstallexe"
1048 if ( ! $local:retval ) {
1049 Write-Output "$script:uninstallexe does not exist. Quitting."
1050 Write-Output ""
1051 return #$local:retval
1052 }
1053
1054 $errorActionPreference = "Stop"
1055 $local:retval = Invoke-Command "$script:uninstallexe" "$script:uninst_cmdline" "UnInstalling Firebird"
1056 if ( $local:retval -ne 0 ) {
1057 iss_error ( $local:retval )
1058 } else {
1059 Write-Verbose "Firebird should now be uninstalled"
1060
1061 run_check_install
1062
1063 }
1064
1065 # Copy uninstall log to copy_install_target if it exists.
1066 if ( Test-Path -Path $script:copy_install_target ) {
1067 if ( Test-Path $script:uninstall_log_file -PathType leaf ) {
1068 Copy-Item -Path $script:uninstall_log_file -Destination $script:copy_install_target | Out-Null
1069 }
1070 }
1071
1072 }
1073
1074 # return $local:retval
1075
1076 }
1077 function run_cleanup() {
1078
1079 if ( $script:dryrun ) {
1080 Write-Output "Dry run - not executing $($MyInvocation.MyCommand.Name )"
1081 Write-Output "Not uninstalling Firebird"
1082 Write-Output "Not deleting the $env:firebirdrootdir\$env:firebird_base_ver dir"
1083 Write-Output "Not removing the list of firebird shared dll's in the registry."
1084 Write-Output ""
1085 } else {
1086 Write-Verbose "Cleaning up existing Firebird installation"
1087 run_uninstaller
1088
1089 if ( $script:realclean ) {
1090 $local:retval = check_file_exists $script:firebirdrootdir\$script:firebird_base_ver dir $true
1091 if ( $local:retval ) {
1092 Write-Verbose "Removing all files in $script:firebirdrootdir\$script:firebird_base_ver dir"
1093 Remove-Item "$script:firebirdrootdir\$script:firebird_base_ver" -Recurse -Include "*.*" -Confirm
1094 }
1095 Write-Verbose "Removing fbclient and gds32 from $env:SystemRoot\System32"
1096 Remove-Item "$env:SystemRoot\System32" -Include "fbclient.dll", "gds32.dll" -Confirm
1097 Write-Verbose "Removing fbclient and gds32 from $env:SystemRoot\SysWOW64"
1098 Remove-Item "$env:SystemRoot\SysWOW64" -Include "fbclient.dll", "gds32.dll" -Confirm
1099
1100 Write-Verbose "Clean up listing of Shared DLLs in registry"
1101 $RegKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs"
1102 Remove-ItemProperty HKLM:$RegKey -Name "C:\Program\*.*" -Confirm
1103 Remove-ItemProperty HKLM:$RegKey -Name "${script:firebirdrootdir}\${script:firebird_base_ver}\*.*" -Confirm
1104 Remove-ItemProperty HKLM:$RegKey -Name "*\fbclient.dll" -Confirm
1105 Remove-ItemProperty HKLM:$RegKey -Name "*\gds32.dll" -Confirm
1106 }
1107 Write-Verbose "Completed cleanup of Firebird installation"
1108 }
1109
1110 }
1111
1112
1113 function iss_error( [Int32]$_err_code = 0 ) {
1114
1115 switch ($_err_code) {
1116 1 { Write-Output "Setup failed to initialize." }
1117 2 {
1118 Write-Output "The user clicked Cancel in the wizard before the actual installation
1119 started, or chose 'No' on the opening 'This will install...' message box."
1120 }
1121 3 {
1122 Write-Output "A fatal error occurred while preparing to move to the next
1123 installation phase (for example, from displaying the pre-installation
1124 wizard pages to the actual installation process). This should never
1125 happen except under the most unusual of circumstances, such as
1126 running out of memory or Windows resources."
1127 }
1128 4 { Write-Output "A fatal error occurred during the actual installation process." }
1129 5 {
1130 Write-Output "The user clicked Cancel during the actual installation process,
1131 or chose Abort at an Abort-Retry-Ignore box."
1132 }
1133 6 {
1134 Write-Output "The Setup process was forcefully terminated by the debugger
1135 (Run | Terminate was used in the Compiler IDE)."
1136 }
1137 7 {
1138 Write-Output "The Preparing to Install stage determined that Setup cannot proceed
1139 with installation. (First introduced in Inno Setup 5.4.1.)"
1140 }
1141 8 {
1142 Write-Output "The Preparing to Install stage determined that Setup cannot proceed
1143 with installation, and that the system needs to be restarted in
1144 order to correct the problem. (First introduced in Inno Setup 5.4.1.)"
1145 }
1146 Default {}
1147 }
1148
1149 }
1150
1151 function main() {
1152 begin{
1153 # $script:DebugPreference = 'Continue'
1154 # $script:VerbosePreference = 'Continue'
1155
1156 Set-StrictMode -Version 3.0
1157 }
1158
1159 process {
1160 if ( $script:help ) {
1161 show-help
1162 } else {
1163 prompt
1164 spacer
1165 check_params
1166 check_environment
1167 check_innosetup_params
1168
1169 switch ($script:action) {
1170 "realclean" { run_cleanup }
1171 "check_install" { run_check_install }
1172 "uninstall" { run_uninstaller }
1173 "check_uninstall" { run_check_install }
1174 Default {
1175 $local:retval = $( run_installer | Select-Object -Last 1 )
1176 if ( $local:retval -ne 0 ) {
1177 Write-Error "run_installer returned $local:retval"
1178 return
1179 }
1180 run_check_install
1181 if ( ! $script:nouninstall ) {
1182 run_uninstaller
1183 }
1184 }
1185 }
1186 }
1187 }
1188
1189 end{
1190 spacer " Finished "
1191
1192 # this attempt to 'reset' the prompt fails :-(
1193 #prompt -reset
1194
1195 }
1196 }
1197
1198 main $args
1199