forked from SorenKlemmensen/AdvaniaGIT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Installation.ps1
104 lines (92 loc) · 5.16 KB
/
Installation.ps1
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
# Make sure to only run this script in Admin Mode
# Get the ID and security principal of the current user account
$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator"
$IsInAdminMode = $myWindowsPrincipal.IsInRole($adminRole)
if (!$IsInAdminMode) {
Write-Host "Starting Script in Admin Mode..."
$ScriptToStart = (Join-path $PSScriptRoot $MyInvocation.MyCommand.Name)
$ArgumentList = "-noprofile -file " + $ScriptToStart
Start-Process powershell -Verb runas -WorkingDirectory $PSScriptRoot -ArgumentList $ArgumentList -WindowStyle Normal -Wait
break
}
Write-Host "Starting AdvaniaGIT Installation/Upgrade..."
Get-Module -Name "AdvaniaGIT" | Remove-Module
$Module = (Get-Module -ListAvailable | Where-Object -Property Name -EQ "AdvaniaGIT")
if ($Module) {
$InstallationPath = Split-Path (Split-Path (Split-Path $Module.Path -Parent) -Parent) -Parent
Write-Host "AdvaniaGIT module found on path $InstallationPath"
Write-Host "Upgrading..."
} else {
$DefaultPath = (Join-Path $env:SystemDrive 'AdvaniaGIT')
Write-Host "This will install AdvaniaGIT on your computer. Please select a local path for the module."
Write-Host "Database, backups and installation media will be stored in this folder."
Write-Host "Close this window to cancel installation/upgrade"
Write-Host ""
$InstallationPath = Read-Host -Prompt "Enter local path for AdvaniaGIT (default = $DefaultPath)"
if ($InstallationPath -eq "") { $InstallationPath = $DefaultPath }
}
New-Item -Path $InstallationPath -ItemType Directory -ErrorAction SilentlyContinue
if (Test-Path -Path $InstallationPath) {
if (!(Test-Path (Join-Path $InstallationPath 'TestDevel.ps1'))) {
Copy-Item -Path (Join-Path $PSScriptRoot 'TestDevel.ps1') -Destination $InstallationPath -ErrorAction SilentlyContinue
}
Copy-Item -Path (Join-Path $PSScriptRoot 'README.md') -Destination $InstallationPath -Force -ErrorAction SilentlyContinue
$DirectoriesToCopy = @('Backup','Database','Demo','License','Log','Source','Workspace','Scripts','SourceTree','Tools')
foreach ($Directory in $DirectoriesToCopy) {
$Source = Join-Path $PSScriptRoot $Directory
$Destination = Join-Path $InstallationPath $Directory
New-Item -Path $Destination -ItemType Directory -ErrorAction SilentlyContinue
$Items = Get-ChildItem -Path $Source
foreach ($Item in $Items) {
Copy-Item -Path $Item.FullName -Destination $Destination -Recurse -Force -ErrorAction SilentlyContinue
}
}
$Destination = Join-Path $InstallationPath 'Data'
New-Item -Path $Destination -ItemType Directory -ErrorAction SilentlyContinue
}
else
{
Write-Host -ForegroundColor Red "$InstallationPath not found!"
$input = Read-Host -Prompt "Press any key to continue..."
break
}
$ScriptToStart = Join-Path $InstallationPath 'Scripts\Install-Modules.ps1'
& $ScriptToStart
Import-Module AdvaniaGIT -DisableNameChecking | Out-Null
foreach ($configFile in (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Data\*.json'))) {
$InstalledConfigFile = (Join-Path (Join-Path $InstallationPath 'Data') $configFile.Name)
if (Test-Path $InstalledConfigFile) {
if ($configFile.BaseName -iin ('DockerSettings','GITSettings')) {
$installedConfig = Get-Content -Path $InstalledConfigFile -Encoding UTF8 | Out-String | ConvertFrom-Json
$newConfig = Get-Content -Path $configFile.FullName -Encoding UTF8 | Out-String | ConvertFrom-Json
$config = Combine-Settings $installedConfig $newconfig
if ($configFile.Name -eq "GITSettings.Json") {
$config.workFolder = (Join-Path $InstallationPath "Workspace")
}
Set-Content -Path $InstalledConfigFile -Encoding UTF8 -Value ($config | ConvertTo-Json)
Start-Process -FilePath $InstalledConfigFile
}
} else {
Copy-Item -Path $configFile.FullName -Destination (Join-Path $InstallationPath 'Data')
if ($configFile.BaseName -iin ('DockerSettings','GITSettings')) {
Start-Process -FilePath $InstalledConfigFile
}
}
}
Write-Host "Please update configuration files to match your environment (opened automatically)"
$Answer = Read-Host -Prompt "Perform Remote Administration Module Installation ? (Default = No)"
if ($Answer -iin ('Yes','Y')) {
$ScriptToStart = Join-Path $InstallationPath 'Scripts\Install-RemoteManagementModules.ps1'
& $ScriptToStart
Start-Process -FilePath (Join-Path $InstallationPath "Data\RemoteSettings.Json")
}
$Answer = Read-Host -Prompt "Perform NAV Environment Configuration (required after NAV installation) ? (Default = No)"
if ($Answer -iin ('Yes','Y')) {
$SetupParameters = Get-Content -Path (Join-Path $InstallationPath "Data\GITSettings.Json") | Out-String | ConvertFrom-Json
$ScriptToStart = Join-Path $InstallationPath 'Scripts\Prepare-NAVEnvironment.ps1'
& $ScriptToStart
}