|
1 | | -new-module -name FusionAuth -scriptblock { |
2 | | - function Install-FusionAuth() |
3 | | - { |
4 | | - param (# This must come first |
5 | | - [bool]$includeSearch = 0 |
6 | | - ) |
| 1 | +param (# This must come first |
| 2 | + [bool]$IncludeSearch = 0 |
| 3 | +) |
7 | 4 |
|
8 | | - # Get current setting |
9 | | - $old_erroractionpreference = $erroractionpreference |
10 | | - $erroractionpreference = 'stop' # quit if anything goes wrong |
| 5 | +function DownloadAndExpandZip($uri, $tempFile, $destination) |
| 6 | +{ |
| 7 | + Write-Output "Downloading archive, destination $destination" |
| 8 | + Invoke-WebRequest -Uri $uri -OutFile $tempFile |
11 | 9 |
|
12 | | - # Try importing BitsTransfer |
13 | | - if (!(Get-module BitsTransfer)) |
14 | | - { |
15 | | - Import-Module BitsTransfer -ErrorAction SilentlyContinue |
16 | | - } |
17 | | - |
18 | | - if (($PSVersionTable.PSVersion.Major) -lt 5) |
19 | | - { |
20 | | - Write-Output "PowerShell 5 or greater is required to run this installer." |
21 | | - Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" |
22 | | - break |
23 | | - } |
24 | | - |
25 | | - function DownloadAndExpandZip($uri, $tempFile, $destination) |
26 | | - { |
27 | | - Write-Output "Downloading archive, destination ${destination}" |
28 | | - |
29 | | - if (Get-module BitsTransfer) |
30 | | - { |
31 | | - Start-BitsTransfer -Source $uri -Destination $tempFile |
32 | | - } |
33 | | - else |
34 | | - { |
35 | | - (New-Object System.Net.WebClient).DownloadFile($uri, $tempFile) |
36 | | - } |
37 | | - |
38 | | - Write-Output "Expanding archive" |
39 | | - |
40 | | - if (Test-Path "$env:Temp/fusionauth") |
41 | | - { |
42 | | - Remove-Item -Force -Recurse "$env:Temp/fusionauth" |
43 | | - } |
44 | | - |
45 | | - New-Item "$env:Temp/fusionauth" -ItemType Directory |
46 | | - |
47 | | - Expand-Archive -Path $tempFile -DestinationPath "$env:Temp/fusionauth" |
48 | | - |
49 | | - New-Item $destination -ItemType Directory -ea 0 |
50 | | - |
51 | | - robocopy "$env:Temp/fusionauth" $destination /E /XC /XN /XO /NFL /NDL /NJH /NS /NC |
52 | | - } |
53 | | - |
54 | | - $BASE_URL = "https://files.fusionauth.io/products/fusionauth" |
55 | | - $VERSION = Invoke-WebRequest -UseBasicParsing -Uri https://metrics.fusionauth.io/api/latest-version |
56 | | - # Trim the trailing \ since we add it when we set the destination directory, and it may come back on the FullName property |
57 | | - # > C:\> (Get-Item -Path ".\").FullName => C:\ |
58 | | - # > C:\foo> (Get-Item -Path ".\").FullName => C:\foo |
59 | | - $CURRENT_DIRECTORY = (Get-Item -Path ".\").FullName.TrimEnd("\") |
60 | | - |
61 | | - Write-Output "Install FusionAuth version ${VERSION}" |
| 10 | + Write-Output "Expanding archive" |
| 11 | + Expand-Archive -Force -Path $tempFile -DestinationPath "$destination" |
| 12 | +} |
62 | 13 |
|
63 | | - if (Test-Path "$CURRENT_DIRECTORY\fusionauth\fusionauth-app") |
64 | | - { |
65 | | - Remove-Item -Force -Recurse "$CURRENT_DIRECTORY\fusionauth\fusionauth-app" |
66 | | - } |
67 | | - if (Test-Path "$CURRENT_DIRECTORY\fusionauth\fusionauth-search") |
68 | | - { |
69 | | - Remove-Item -Force -Recurse "$CURRENT_DIRECTORY\fusionauth\fusionauth-search" |
70 | | - } |
71 | | - if (Test-Path "$CURRENT_DIRECTORY\fusionauth\bin") |
72 | | - { |
73 | | - Remove-Item -Force -Recurse "$CURRENT_DIRECTORY\fusionauth\bin" |
74 | | - } |
| 14 | +# Get current setting |
| 15 | +$old_erroractionpreference = $erroractionpreference |
| 16 | +$erroractionpreference = 'stop' # quit if anything goes wrong |
75 | 17 |
|
76 | | - echo "Installing zip packages" |
| 18 | +if (($PSVersionTable.PSVersion.Major) -lt 5) |
| 19 | +{ |
| 20 | + Write-Output "PowerShell 5 or greater is required to run this installer." |
| 21 | + Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell" |
| 22 | + break |
| 23 | +} |
77 | 24 |
|
78 | | - # Install search first so that we get the search version of fusionauth.properties (which enables search) |
79 | | - if ($includeSearch) |
80 | | - { |
81 | | - DownloadAndExpandZip "${BASE_URL}/${VERSION}/fusionauth-search-${VERSION}.zip" "$env:Temp\fusionauth-search.zip" "$CURRENT_DIRECTORY\fusionauth" |
82 | | - } |
83 | | - DownloadAndExpandZip "${BASE_URL}/${VERSION}/fusionauth-app-${VERSION}.zip" "$env:Temp\fusionauth-app.zip" "$CURRENT_DIRECTORY\fusionauth" |
| 25 | +$BaseURL = "https://files.fusionauth.io/products/fusionauth" |
| 26 | +$Version = Invoke-WebRequest -UseBasicParsing -Uri https://metrics.fusionauth.io/api/latest-version |
| 27 | +# Trim the trailing \ since we add it when we set the destination directory, and it may come back on the FullName property |
| 28 | +# > C:\> (Get-Item -Path ".\").FullName => C:\ |
| 29 | +# > C:\foo> (Get-Item -Path ".\").FullName => C:\foo |
| 30 | +$CurrentDirectory = (Get-Item -Path ".\").FullName.TrimEnd("\") |
| 31 | + |
| 32 | +# Handle POSIX compliant operating systems that use the variable TMPDIR instead (i.e. macOS, Linux, Unix) |
| 33 | +$TempDir = $env:Temp |
| 34 | +if (!$TempDir) |
| 35 | +{ |
| 36 | + $TempDir = $env:TMPDIR |
| 37 | +} |
84 | 38 |
|
85 | | - Write-Output "" |
86 | | - Write-Output "Install is complete. Time for tacos." |
87 | | - Write-Output "" |
88 | | - Write-Output " 1. To start FusionAuth run the following command" |
89 | | - Write-Output " .\fusionauth\bin\startup.ps1" |
90 | | - Write-Output "" |
91 | | - Write-Output " 2. To begin, access FusionAuth by opening a browser to http://localhost:9011" |
92 | | - Write-Output "" |
93 | | - Write-Output " 3. If you're looking for documentation, open your browser and navigate to https://fusionauth.io/docs" |
94 | | - Write-Output "" |
95 | | - Write-Output "Thank you have a nice day." |
| 39 | +Write-Output "Install FusionAuth version ${Version}" |
96 | 40 |
|
97 | | - # Restore old setting |
98 | | - $erroractionpreference = $old_erroractionpreference # Reset $erroractionpreference to original value |
99 | | - } |
| 41 | +if (Test-Path "$CurrentDirectory\fusionauth\fusionauth-app") |
| 42 | +{ |
| 43 | + Remove-Item -Force -Recurse "$CurrentDirectory\fusionauth\fusionauth-app" |
| 44 | +} |
| 45 | +if (Test-Path "$CurrentDirectory\fusionauth\fusionauth-search") |
| 46 | +{ |
| 47 | + Remove-Item -Force -Recurse "$CurrentDirectory\fusionauth\fusionauth-search" |
| 48 | +} |
| 49 | +if (Test-Path "$CurrentDirectory\fusionauth\bin") |
| 50 | +{ |
| 51 | + Remove-Item -Force -Recurse "$CurrentDirectory\fusionauth\bin" |
| 52 | +} |
100 | 53 |
|
101 | | - set-alias install -value Install-FusionAuth |
| 54 | +Write-Output "Installing zip packages" |
102 | 55 |
|
103 | | - export-modulemember -function Install-FusionAuth -alias install |
| 56 | +# Install search first so that we get the search version of fusionauth.properties (which enables search) |
| 57 | +if ($IncludeSearch) |
| 58 | +{ |
| 59 | + DownloadAndExpandZip "$BaseURL/$Version/fusionauth-search-$Version.zip" "$TempDir\fusionauth-search.zip" "$CurrentDirectory\fusionauth" |
104 | 60 | } |
| 61 | +DownloadAndExpandZip "$BaseURL/$Version/fusionauth-app-$Version.zip" "$TempDir\fusionauth-app.zip" "$CurrentDirectory\fusionauth" |
| 62 | + |
| 63 | +Write-Output "" |
| 64 | +Write-Output "Install is complete. Time for tacos." |
| 65 | +Write-Output "" |
| 66 | +Write-Output " 1. To start FusionAuth run the following command" |
| 67 | +Write-Output " .\fusionauth\bin\startup.ps1" |
| 68 | +Write-Output "" |
| 69 | +Write-Output " 2. To begin, access FusionAuth by opening a browser to http://localhost:9011" |
| 70 | +Write-Output "" |
| 71 | +Write-Output " 3. If you're looking for documentation, open your browser and navigate to https://fusionauth.io/docs" |
| 72 | +Write-Output "" |
| 73 | +Write-Output "Thank you have a nice day." |
| 74 | + |
| 75 | +# Restore old setting |
| 76 | +$erroractionpreference = $old_erroractionpreference # Reset $erroractionpreference to original value |
0 commit comments