-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathironfoundry-install.ps1
204 lines (162 loc) · 4.66 KB
/
ironfoundry-install.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
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
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$Dea_Yml_File,
[Parameter(Mandatory=$True,Position=2)]
[string] $IF_WardenUser_Password,
[string] $IF_WardenUser = "IFWardenService",
[string] $DefaultInstallDir = "C:\IronFoundry",
[string] $ReleaseVersion = '0.0.0',
[int] $DEAMemoryMB = -1,
[int] $DEADiskMB = -1
)
#
# Assumes:
# Ruby Installed
# Ruby DevKit Installed
# Go Installed
# Git installed
#
# In Path:
# gem
# bundle
# Git
#
# In Package:
# if_data
# if_warden
# dea_ng source
# Curl
# 7Zip
$ErrorActionPreference = "Stop"
# General install information
$StartDirectory = resolve-path $PWD
$ReleaseDir = join-path $StartDirectory $ReleaseVersion
$InstallRootDir = $DefaultInstallDir
# App locations
$rubyApp = $null
$rubyPath = $null
#
# Helper routines
#
function IsAdmin()
{
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
$prp=new-object System.Security.Principal.WindowsPrincipal($wid)
$adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
$IsAdmin=$prp.IsInRole($adm)
return $IsAdmin
}
function FindApp($appName)
{
# Search path for app
foreach ($path in $env:PATH.Split(";") ) {
$name = "${path}\${appName}"
$name = $name.Replace("`"", "")
if (test-path $name) {
return $name
}
}
return $null
}
function CreateLocalUser([string]$userName, [string]$password)
{
# Approach taken from: http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/23/use-powershell-to-create-local-user-accounts.aspx
$computer = [ADSI]("WinNT://$env:computername")
$objUser = $computer.Create("user", $userName)
$objUser.SetPassword($password)
$objUser.SetInfo()
# Set password not to expire
$ADS_UF_DONT_EXPIRE_PASSWD = 0x10000
$objUser.UserFlags = $objUser.UserFlags[0] -bor $ADS_UF_DONT_EXPIRE_PASSWD
$objUser.SetInfo()
}
function DeleteLocaluser($userName)
{
$computer = [ADSI]"WinNT://$env:computername"
Try
{
$computer.Delete("User", $userName)
}
Catch
{
Write-Host "Unable to delete user $userName. This is normal on first install since the user does not exist yet."
}
}
function AddUserToGroup($userName, $groupName)
{
$group = [ADSI]("WinNT://$env:computername/$groupName,group")
$user = [ADSI]("WinNT://$env:computername/$userName,user")
$group.Add($user.Path)
}
#
# Install and uninstall actions
#
function VerifyDependencies()
{
Write-Host "Verifying dependencies"
$success = $true
$script:rubyApp = (FindApp "ruby.exe")
$script:rubyPath = split-path $rubyApp
if ($rubyApp -eq $null) {
$success = $false
Write-Error "Unable to find ruby.exe"
}
if ((FindApp "go.exe") -eq $null) {
$success = $false
Write-Error "Unable to find Go"
}
if ((FindApp "git.exe") -eq $null) {
$success = $false
Write-Error "Unable to find git.exe"
}
return $success
}
function UpdateConfigFile($sourceConfig, $targetConfig)
{
Write-Host "Updating configuration file into to $targetConfig"
Set-Location $StartDirectory
$deaYmlFile = "$(resolve-path $sourceConfig)" -Replace "\\", "/"
$configRubyPath = $rubyPath -Replace "\\", "/"
$targetConfigRubyPath = $targetConfig -Replace "\\", "/"
$configureArgs = @(
'--source-config', $deaYmlFile,
'--ruby-path', $configRubyPath,
'--ironfoundry-path', $InstallRootDir,
'--output', $targetConfigRubyPath
)
if ($DEAMemoryMB -gt 0) {
$configureArgs += '--memory-mb', $DEAMemoryMB
}
if ($DEADiskMB -gt 0) {
$configureArgs += '--disk-mb', $DEADiskMB
}
& $rubyApp "$ReleaseDir\if_data\configure-dea.rb" @configureArgs
}
function CreateLocalAdminUser($user, $password)
{
Write-Host "Creating local user $user and adding to Administrators"
DeleteLocaluser $user
CreateLocalUser $user $password
AddUserToGroup $user "Administrators"
}
#
# Unpack folder and set permissions
#
if ( (IsAdmin) -eq $false)
{
Write-Error "This script must be run as admin."
Exit 1
}
if ( (VerifyDependencies) -eq $false)
{
Write-Error "Failed to verify dependencies."
Exit 1
}
& $ReleaseDir\if_data\install.ps1 $InstallRootDir $Dea_Yml_File
$configured_Dea_Yml_File = (join-path $InstallRootDir "dea_ng\config\dea.yml")
UpdateConfigFile $Dea_Yml_File $configured_Dea_Yml_File
& $ReleaseDir\dea_ng\install.ps1 $InstallRootDir
CreateLocalAdminUser $IF_WardenUser $IF_WardenUser_Password
& $ReleaseDir\if_warden\install.ps1 (join-path $ReleaseDir if_warden) $IF_WardenUser $IF_WardenUser_Password $InstallRootDir
Set-Location $StartDirectory
Write-Host "IronFoundry Installed"