-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSnittlistanInstall.ps1
161 lines (130 loc) · 5.8 KB
/
SnittlistanInstall.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
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
# Right click and choose "Run with PowerShell"
param($ScriptDirectory)
trap {
$_
Read-Host
exit 1
}
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
if ($Invocation.PSScriptRoot)
{
$Invocation.PSScriptRoot
}
ElseIf ($Invocation.MyCommand.Path)
{
Split-Path $Invocation.MyCommand.Path
}
Else
{
$Invocation.InvocationName.Substring(0, $Invocation.InvocationName.LastIndexOf("\"))
}
}
# run as admin
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
$arguments = "& '" + $MyInvocation.MyCommand.Definition + "' " + (Get-ScriptDirectory)
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
$winver = [System.Environment]::OSVersion.Version
if ($winver.Major -eq 6 -and $winver.Minor -ge 3) {
# perform check for Windows Server 2012 R2 (Get-WindowsFeature is not available otherwise)
$feature = Get-WindowsFeature NET-WCF-HTTP-Activation45
if (-not $feature.Installed) {
Write-Host -Fore Red "HTTP Activation needs to be installed."
Read-Host
break
}
}
if (-not (Test-Path ..\service-account.txt)) {
Read-Host -AsSecureString "Enter Service account" | ConvertFrom-SecureString | Out-File ..\service-account.txt
}
$serviceAccount = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\service-account.txt))))
if (-not (Test-Path ..\service-password.txt)) {
Read-Host -AsSecureString "Enter Service password" | ConvertFrom-SecureString | Out-File ..\service-password.txt
}
$servicePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\service-password.txt))))
if (-not (Test-Path ..\email-password.txt)) {
Read-Host -AsSecureString "Enter Email password" | ConvertFrom-SecureString | Out-File ..\email-password.txt
}
$emailPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\email-password.txt))))
if (-not (Test-Path ..\elmah-email-password.txt)) {
Read-Host -AsSecureString "Enter Elmah Email password" | ConvertFrom-SecureString | Out-File ..\elmah-email-password.txt
}
$elmahEmailPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\elmah-email-password.txt))))
if (-not (Test-Path ..\db-host.txt)) {
Read-Host -AsSecureString "Enter Database host" | ConvertFrom-SecureString | Out-File ..\db-host.txt
}
$dbHost = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\db-host.txt))))
if (-not (Test-Path ..\db-name.txt)) {
Read-Host -AsSecureString "Enter Database name" | ConvertFrom-SecureString | Out-File ..\db-name.txt
}
$dbName = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\db-name.txt))))
if (-not (Test-Path ..\db-name2.txt)) {
Read-Host -AsSecureString "Enter Second Database name" | ConvertFrom-SecureString | Out-File ..\db-name2.txt
}
$dbName2 = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\db-name2.txt))))
if (-not (Test-Path ..\db-username.txt)) {
Read-Host -AsSecureString "Enter Database username" | ConvertFrom-SecureString | Out-File ..\db-username.txt
}
$dbUsername = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\db-username.txt))))
if (-not (Test-Path ..\db-password.txt)) {
Read-Host -AsSecureString "Enter Database password" | ConvertFrom-SecureString | Out-File ..\db-password.txt
}
$dbPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR(
(ConvertTo-SecureString (Get-Content ..\db-password.txt))))
if (-not (Test-Path ..\owner-email.txt)) {
Read-Host "Enter owner email" | Out-File ..\owner-email.txt
}
$ownerEmail = Get-Content ..\owner-email.txt
if (-not (Test-Path ..\bcc-email.txt)) {
Read-Host "Enter bcc email" | Out-File ..\bcc-email.txt
}
$bccEmail = Get-Content ..\bcc-email.txt
$settings = @{
SERVICE_ACCOUNT = $serviceAccount
SERVICE_PASSWORD = $servicePassword
EMAIL_PASSWORD = $emailPassword
ELMAH_EMAIL_PASSWORD = $elmahEmailPassword
DB_HOST = $dbHost
DB_NAME = $dbName
DB_NAME2 = $dbName2
DB_USERNAME = $dbUsername
DB_PASSWORD = $dbPassword
OWNER_EMAIL = $ownerEmail
BCC_EMAIL = $bccEmail
}
$settingsFormatted = ($settings.Keys | % { "$_=$($settings[$_])" }) -join "`n"
"Settings:`n$settingsFormatted"
"Installing new version..."
$settingsJoined = ($settings.Keys | % { "$_=""$($settings[$_])""" }) -join " "
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.WorkingDirectory = $ScriptDirectory
$pinfo.FileName = "msiexec.exe"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "/l* Snittlistan_install.log /i Snittlistan.msi $settingsJoined"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$stdout = $p.StandardOutput.ReadToEnd()
$p.WaitForExit()