Created
October 10, 2013 14:09
-
-
Save ElanHasson/6919005 to your computer and use it in GitHub Desktop.
Updated version of Powershell self-host installer script located at http://about.jabbr.net/self-host-install.html to include support for additional site to host Local File System Storage Handler from Feature #1023. It Does the following: 0) Create directory for site
1) Create IIS Site for JabbRLocalFileSystemStorage
2) Create IIS AppPool for new…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$webFolder = "$env:systemdrive\inetpub\jabbr" | |
$appPoolName = "JabbR" | |
$siteName = "JabbR" | |
$dbServer = ".\SQLEXPRESS" | |
$dbName = "JabbR" | |
$fileSource = "http://teamcity.codebetter.com/repository/download/bt980/.lastSuccessful/site.zip?guest=1" | |
$tempFile = "$env:temp\jabbr.zip" | |
$identity = "IIS AppPool\$appPoolName" | |
$enableLocalFileSystemStorage = $false; #set to $true to enable local file system storage | |
$appPoolNameForLocalFileSystemStorage = "JabbRLocalFileSystemStorage" | |
$siteNameForLocalFileSystemStorage = "JabbR LocalFileSystemStorage" | |
$webFolderForLocalFileSystemStorage = "$env:systemdrive\inetpub\jabbrLocalFileSystemStorage" | |
$serverPortForLocalFileSystemStorage = 81 | |
$identityForLocalFileSystemStorage = "IIS AppPool\$appPoolName"+"LocalFileSystemStorage" | |
Import-Module servermanager | |
Add-WindowsFeature Web-Server | |
Add-WindowsFeature Web-Mgmt-Console | |
Add-WindowsFeature Web-Asp-Net45 | |
New-Item $webFolder -type directory | |
Stop-Website -Name 'Default Web Site' | |
New-WebAppPool $appPoolName | |
New-Website -Name $siteName -Port 80 -PhysicalPath $webFolder -ApplicationPool $appPoolName | |
(New-Object System.Net.WebClient).DownloadFile($fileSource, $tempFile ) | |
$sh = New-Object -com shell.application; $sh.namespace($webFolder).Copyhere($sh.namespace($tempFile ).items()) | |
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | |
$server = New-Object Microsoft.SqlServer.Management.Smo.Server($dbServer) | |
$db = New-Object Microsoft.SqlServer.Management.Smo.Database($server, $dbName) | |
$db.Create() | |
$login = New-Object Microsoft.SqlServer.Management.Smo.Login($server, $identity) | |
$login.DefaultDatabase = $dbName | |
$login.LoginType = [Microsoft.SqlServer.Management.SMO.LoginType]::WindowsUser | |
$login.Create() | |
$user = New-Object Microsoft.SqlServer.Management.Smo.User($db, $identity) | |
$user.Create(); | |
$db.Roles["db_owner"].AddMember($login.Name) | |
(Get-Content "$webFolder\web.config") | | |
Foreach-Object {$_ -replace "Data Source=\.\\SQLEXPRESS", "Data Source=$dbServer"} | | |
Foreach-Object {$_ -replace "Initial Catalog=JabbR", "Initial Catalog=$dbName"} | | |
Set-Content "$webFolder\web.config" | |
$acl = Get-Acl "$webFolder\Content" | |
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identity, "Write", "ContainerInherit, ObjectInherit", "None", "Allow") | |
$acl.SetAccessRule($rule) | |
Set-Acl "$webFolder\Content" $acl | |
$acl = Get-Acl "$webFolder\Scripts" | |
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identity, "Write", "ContainerInherit, ObjectInherit", "None", "Allow") | |
$acl.SetAccessRule($rule) | |
Set-Acl "$webFolder\Scripts" $acl | |
if ($enableLocalFileSystemStorage -eq $true) { | |
write-host "Configuring LocalFileSystemStorage.." | |
New-Item $webFolderForLocalFileSystemStorage -type directory | |
NewWebAppPool $appPoolNameForLocalFileSystemStorage | |
New-WebSite -Name $siteNameForLocalFileSystemStorage -Port $serverPortForLocalFileSystemStorage -PhysicalPath $webFolderForLocalFileSystemStorage | |
#Set Permissions for JabbR site to read/write to $webFolderFoLocalFileSystemStorage | |
$acl = Get-Acl "$webFolderForLocalFileSystemStorage" | |
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identity, "Write", "ContainerInherit, ObjectInherit", "None", "Allow") | |
$acl.SetAccessRule($rule) | |
Set-Acl "$webFolderForLocalFileSystemStorage" $acl | |
$acl = Get-Acl "$webFolderForLocalFileSystemStorage" | |
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identity, "Read", "ContainerInherit, ObjectInherit", "None", "Allow") | |
$acl.SetAccessRule($rule) | |
Set-Acl "$webFolderForLocalFileSystemStorage" $acl | |
#Set Permissions for JabbRLocalFileSystemStorage site to read only to $webFolderFoLocalFileSystemStorage | |
$acl = Get-Acl "$webFolderForLocalFileSystemStorage" | |
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identityForLocalFileSystemStorage, "Read", "ContainerInherit, ObjectInherit", "None", "Allow") | |
$acl.SetAccessRule($rule) | |
Set-Acl "$webFolderForLocalFileSystemStorage" $acl | |
$acl = Get-Acl "$webFolderForLocalFileSystemStorage" | |
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($identityForLocalFileSystemStorage, "Write", "ContainerInherit, ObjectInherit", "None", "Deny") | |
$acl.SetAccessRule($rule) | |
Set-Acl "$webFolderForLocalFileSystemStorage" $acl | |
#Configure $siteNameForLocalFileSystemStorage to only process static files for security reasons | |
function Remove-HandlerList { | |
param($IISSitePath, $handlersToKeep) | |
Get-WebHandler -PSPath $IISSitePath | ForEach-Object { | |
if ($handlersToKeep -contains $_.name) { | |
write-host "Keeping handler: " $_.name | |
} else { | |
write-host "Deleting handler: " $_.name | |
Remove-WebHandler -Name $_.name -PSPath $IISSitePath | |
} | |
} | |
} | |
#Define which handlers are to keep | |
$handlersToKeep = "StaticFile" | |
# Deleting unessary handlers at $siteNameForLocalFileSystemStorage level | |
Remove-HandlerList "IIS:\Sites\$siteNameForLocalFileSystemStorage" $handlersToKeep | |
write-host "Configuring LocalFileSystemStorage...Done." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment