-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb-box-deploy.ps1
More file actions
184 lines (131 loc) · 5.06 KB
/
web-box-deploy.ps1
File metadata and controls
184 lines (131 loc) · 5.06 KB
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
param(
[string] $path_releases = "\\fs.tpondemand.net\Releases",
#[string] $path_releases = "c:\Inetpub",
[string] $path_config = "\\fs.tpondemand.net\Users",
[string] $path_wwwroot = "c:\Inetpub\wwwroot",
[string] $type = "Ondemand"
)
$isOnDemand = ($type -eq "Ondemand")
[string] $version_regex = "TP-(?<version>(?<major>\d+)\.(?<minor>\d+)\.(?<build>\d+)\.(?<revision>\d+))"
[string] $appcmd = "$env:windir/system32/inetsrv/appcmd.exe"
Function Unzip ($zipFile, $dest) {
$shell_app=new-object -com shell.application
$zip_file = $shell_app.namespace($zipFile)
$destination = $shell_app.namespace($dest)
$destination.Copyhere($zip_file.items())
}
Function UpdateWebConfig($webConfigPath) {
$lines = get-content $webConfigPath
$lines |
where { $_ -notmatch 'Hosting.Root'} |
where {$_ -notmatch 'HostingModule'} |
foreach {
$_
if ($_ -imatch '<appSettings' -and $isOnDemand) {
"<add key=`"Hosting.Root`" value=`"$path_config`" />"
}
if ($_ -imatch '<httpModules') {
if ($isOnDemand) {
'<add name="HostingModule" type="Tp.Web.Extensions.Hosting.OnDemandModule, Tp.Web.Extensions" />'
}
else {
'<add name="HostingModule" type="Tp.Web.Extensions.Hosting.OnSiteModule, Tp.Web.Extensions" />'
}
}
} |
set-content $webConfigPath
}
Function GetAllSiteNames() {
return &$appcmd list site /text:site.name | where { $_ -ne $null}
}
Function GetSites() {
$installedVersions = GetAllSiteNames |
where { $_ -match "^$version_regex$" } |
foreach { [System.Version] $matches['version'] }
return $installedVersions
}
Function StopAllSites() {
GetAllSiteNames |
foreach { &$appcmd stop site "$_" | Out-Host }
}
Function StartLatestSite() {
$installedVersions = GetSites | where { $_ -ne $null}
$maxVersion = $installedVersions | Sort-Object | Select-Object -Last 1
if ($maxVersion -ne $null) {
&$appcmd start site "TP-$maxVersion" | Out-Host
}
}
Function DeleteSite($version) {
&$appcmd delete site "TP-$version" | Out-Host
&$appcmd delete apppool "TP-$version" | Out-Host
}
Function GetPackages() {
$packages = @()
Get-ChildItem $path_releases | where { $_ -ne $null} |
where { !$_.PSIsContainer } |
where { $_ -match "^$version_regex-archive.zip$" } |
foreach {
$pack = New-Object Object
$pack | Add-Member NoteProperty version ([System.Version] $matches['version'])
$pack | Add-Member NoteProperty wwwrootPath $path_wwwroot
$pack | Add-Member NoteProperty zipPath $_.Fullname
$pack | Add-Member NoteProperty Path ($path_wwwroot+"\"+$_.Name.Replace("-archive.zip", ""))
$pack | Add-Member NoteProperty originalPath ($path_wwwroot+"\" +$_.Name.Replace(".zip", ""))
$pack | Add-Member ScriptMethod IsExtracted { Test-Path $this.Path }
$pack | Add-Member ScriptMethod Extract {
if (Test-Path $this.originalPath){
Remove-Item $this.originalPath -Recurse
}
Unzip $this.zipPath $this.wwwrootPath
Rename-Item $this.originalPath ("TP-"+$this.version)
}
$pack | Add-Member ScriptMethod UpdateWebConfig {
UpdateWebConfig ($this.Path + "/wwwroot/Web.config")
}
$packages += $pack
}
return $packages
}
Function GetBindings($configPath) {
$hostNames = ('')
# $hostNames = Get-ChildItem $configPath |
# where { $_.PSIsContainer } |
# foreach { $_.Name }
$bindings = [string]::join(',', ($hostNames | foreach { "http/*:80:$_" }))
return $bindings
}
Function CreateSite($version, $packagePath) {
$siteName = "TP-$version"
$physicalPath = "$packagePath\wwwroot"
$bindings = GetBindings $path_config
&$appcmd add apppool /name:"$siteName" /managedPipelineMode:Classic /processModel.identityType:NetworkService | Out-Host #/processModel.userName:OFFICE\khasenevich /processModel.password:xxx
if ($isOnDemand) {
&$appcmd add site /name:"$siteName" /bindings:"$bindings" /physicalPath:$physicalPath | Out-Host
&$appcmd set app "$siteName/" /applicationPool:"$siteName" | Out-Host
}
else {
&$appcmd add site /name:"$siteName" /bindings:"$bindings" /physicalPath:$path_wwwroot | Out-Host
&$appcmd add app /site.name:"$siteName" /path:"/TargetProcess" /physicalPath:$physicalPath | Out-Host
&$appcmd set app "$siteName/Targetprocess" /applicationPool:"$siteName" | Out-Host
}
}
#################################################################################################
#################### END OF FUNCTIONS ###########################################################
#################################################################################################
# Delete all Sites
GetSites | where { $_ -ne $null } |
foreach {
DeleteSite $_
}
# Extract and Create Sites for all available Packages
GetPackages |
foreach {
if (!$_.IsExtracted()) {
$_.Extract()
}
$_.UpdateWebConfig()
CreateSite $_.version $_.Path
}
# Start the latest Site
StopAllSites
StartLatestSite