Function ConfigureUmbraco { | |
Param([string]$url, [string]$username, [string]$email, [string]$password, [string]$databaseType, [string]$sqlServer, [string]$databaseName, [bool]$sqlUseIntegratedAuthentication, [string]$sqlUsername, [string]$sqlPassword) | |
try { $response = Invoke-WebRequest $("{0}/install/api/GetSetup" -f $url) -SessionVariable 'session' -Method GET } | |
catch { $response = $null } | |
if ($null -ne $response) { | |
$responseData = ParseResponse($response); | |
$installId = $responseData.installId; | |
$isUpgrade = $responseData.steps[0].name -eq "Upgrade"; | |
if ($isUpgrade -eq $false) { | |
$data = @{ | |
installId = $installId | |
instructions = @{ | |
User = @{ | |
name = $username | |
email = $email | |
password = $password | |
subscribeToNewsLetter = $false | |
} | |
DatabaseConfigure = @{ | |
dbType = [DatabaseType]::$databaseType | |
} | |
ConfigureMachineKey = $true | |
StarterKitDownload = "00000000-0000-0000-0000-000000000000" | |
} | |
} | |
if ([DatabaseType]::$databaseType -ne [DatabaseType]::SqlCe) { | |
$data.instructions.DatabaseConfigure.server = $sqlServer; | |
$data.instructions.DatabaseConfigure.databaseName = $databaseName; | |
if ($sqlUseIntegratedAuthentication) { | |
$data.instructions.DatabaseConfigure.integratedAuth = $true; | |
} | |
else { | |
$data.instructions.DatabaseConfigure.login = $sqlUsername; | |
$data.instructions.DatabaseConfigure.password = $sqlPassword; | |
} | |
} | |
if ((StartUmbracoProcess $("{0}/install/api/PostPerformInstall" -f $url) $data $session) -eq $false) { | |
Error "An error occured during Umbraco configuration" | |
} | |
} | |
else { | |
$model = ParseResponse($response).steps[0].model; | |
$data = @{ | |
username = $email | |
password = $password | |
}; | |
try { $response = Invoke-WebRequest $("{0}/umbraco/backoffice/UmbracoApi/Authentication/PostLogin" -f $url) -WebSession $session -Method POST -Body ($data | ConvertTo-Json -Depth 5) -ContentType "application/json" } | |
catch { $response = $null} | |
if ($null -ne $response) { | |
$data = @{ | |
installId = $installId | |
instructions = @{ | |
Upgrade = $model | |
} | |
} | |
if ((StartUmbracoProcess $("{0}/install/api/PostPerformInstall" -f $url) $data $session) -eq $false) { | |
Error "An error occured during Umbraco configuration" | |
} | |
} | |
else { | |
Error "The authentication to Umbraco back office failed"; | |
} | |
} | |
Success | |
} | |
else { | |
Warning "No configuration needed" | |
} | |
} | |
Function StartUmbracoProcess { | |
Param([string]$url, [Hashtable]$data, [Microsoft.PowerShell.Commands.WebRequestSession]$session) | |
$continue = $true; | |
do { | |
try { | |
$response = Invoke-WebRequest $url -WebSession $session -Method POST -Body ($data | ConvertTo-Json -Depth 5) -ContentType "application/json; charset=utf-8" | |
$continue = !(ParseResponse($response)).complete; | |
} | |
catch { | |
return $false | |
} | |
} while ($continue -eq $true); | |
return $true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment