Guest User

Untitled

a guest
Jul 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. Function ConfigureUmbraco {
  2. Param([string]$url, [string]$username, [string]$email, [string]$password, [string]$databaseType, [string]$sqlServer, [string]$databaseName, [bool]$sqlUseIntegratedAuthentication, [string]$sqlUsername, [string]$sqlPassword)
  3.  
  4. try { $response = Invoke-WebRequest $("{0}/install/api/GetSetup" -f $url) -SessionVariable 'session' -Method GET }
  5. catch { $response = $null }
  6.  
  7. if ($null -ne $response) {
  8. $responseData = ParseResponse($response);
  9.  
  10. $installId = $responseData.installId;
  11. $isUpgrade = $responseData.steps[0].name -eq "Upgrade";
  12.  
  13. if ($isUpgrade -eq $false) {
  14. $data = @{
  15. installId = $installId
  16. instructions = @{
  17. User = @{
  18. name = $username
  19. email = $email
  20. password = $password
  21. subscribeToNewsLetter = $false
  22. }
  23. DatabaseConfigure = @{
  24. dbType = [DatabaseType]::$databaseType
  25. }
  26. ConfigureMachineKey = $true
  27. StarterKitDownload = "00000000-0000-0000-0000-000000000000"
  28. }
  29. }
  30.  
  31. if ([DatabaseType]::$databaseType -ne [DatabaseType]::SqlCe) {
  32. $data.instructions.DatabaseConfigure.server = $sqlServer;
  33. $data.instructions.DatabaseConfigure.databaseName = $databaseName;
  34.  
  35. if ($sqlUseIntegratedAuthentication) {
  36. $data.instructions.DatabaseConfigure.integratedAuth = $true;
  37. }
  38. else {
  39. $data.instructions.DatabaseConfigure.login = $sqlUsername;
  40. $data.instructions.DatabaseConfigure.password = $sqlPassword;
  41. }
  42. }
  43.  
  44. if ((StartUmbracoProcess $("{0}/install/api/PostPerformInstall" -f $url) $data $session) -eq $false) {
  45. Error "An error occured during Umbraco configuration"
  46. }
  47. }
  48. else {
  49. $model = ParseResponse($response).steps[0].model;
  50.  
  51. $data = @{
  52. username = $email
  53. password = $password
  54. };
  55.  
  56. 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" }
  57. catch { $response = $null}
  58.  
  59. if ($null -ne $response) {
  60. $data = @{
  61. installId = $installId
  62. instructions = @{
  63. Upgrade = $model
  64. }
  65. }
  66.  
  67. if ((StartUmbracoProcess $("{0}/install/api/PostPerformInstall" -f $url) $data $session) -eq $false) {
  68. Error "An error occured during Umbraco configuration"
  69. }
  70. }
  71. else {
  72. Error "The authentication to Umbraco back office failed";
  73. }
  74. }
  75.  
  76. Success
  77. }
  78. else {
  79. Warning "No configuration needed"
  80. }
  81. }
  82.  
  83. Function StartUmbracoProcess {
  84. Param([string]$url, [Hashtable]$data, [Microsoft.PowerShell.Commands.WebRequestSession]$session)
  85.  
  86. $continue = $true;
  87.  
  88. do {
  89. try {
  90. $response = Invoke-WebRequest $url -WebSession $session -Method POST -Body ($data | ConvertTo-Json -Depth 5) -ContentType "application/json; charset=utf-8"
  91. $continue = !(ParseResponse($response)).complete;
  92. }
  93. catch {
  94. return $false
  95. }
  96. } while ($continue -eq $true);
  97.  
  98. return $true
  99. }
Add Comment
Please, Sign In to add comment