/Scripts/Package.ps1

http://myjabbr.codeplex.com · Powershell · 137 lines · 114 code · 19 blank · 4 comment · 9 complexity · 235070ee313c9df2f003676159d821f8 MD5 · raw file

  1. param(
  2. $authKey = $env:JABBR_AUTH_KEY,
  3. $googleAnalyticsToken = $env:JABBR_GOOGLE_ANALYTICS,
  4. $remoteDesktopAccountExpiration = $env:JABBR_REMOTE_DESKTOP_ACCOUNT_EXPIRATION,
  5. $remoteDesktopCertificateThumbprint = $env:JABBR_REMOTE_DESKTOP_CERTIFICATE_THUMBPRINT,
  6. $remoteDesktopEnctyptedPassword = $env:JABBR_REMOTE_DESKTOP_ENCRYPTED_PASSWORD,
  7. $remoteDesktopUsername = $env:JABBR_REMOTE_DESKTOP_USERNAME,
  8. $sqlAzureConnectionString = $env:JABBR_SQL_AZURE_CONNECTION_STRING,
  9. $commitSha,
  10. $commitBranch
  11. )
  12. # Import Common Stuff
  13. $ScriptRoot = (Split-Path -parent $MyInvocation.MyCommand.Definition)
  14. . $ScriptRoot\_Common.ps1
  15. # Validate Sutff
  16. require-param -value $authKey -paramName "authKey"
  17. require-param -value $remoteDesktopAccountExpiration -paramName "remoteDesktopAccountExpiration"
  18. require-param -value $remoteDesktopCertificateThumbprint -paramName "remoteDesktopCertificateThumbprint"
  19. require-param -value $remoteDesktopEnctyptedPassword -paramName "remoteDesktopEnctyptedPassword"
  20. require-param -value $remoteDesktopUsername -paramName "remoteDesktopUsername"
  21. require-param -value $sqlAzureConnectionString -paramName "sqlAzureConnectionString"
  22. # Helper Functions
  23. function set-certificatethumbprint {
  24. param($path, $name, $value)
  25. $xml = [xml](get-content $path)
  26. $certificate = $xml.serviceconfiguration.role.Certificates.Certificate | where { $_.name -eq $name }
  27. $certificate.thumbprint = "$value"
  28. $resolvedPath = resolve-path($path)
  29. $xml.save($resolvedPath)
  30. }
  31. function set-configurationsetting {
  32. param($path, $name, $value)
  33. $xml = [xml](get-content $path)
  34. $setting = $xml.serviceconfiguration.role.configurationsettings.setting | where { $_.name -eq $name }
  35. $setting.value = "$value"
  36. $resolvedPath = resolve-path($path)
  37. $xml.save($resolvedPath)
  38. }
  39. function set-connectionstring {
  40. param($path, $name, $value)
  41. $settings = [xml](get-content $path)
  42. $setting = $settings.configuration.connectionStrings.add | where { $_.name -eq $name }
  43. $setting.connectionString = "$value"
  44. $setting.providerName = "System.Data.SqlClient"
  45. $resolvedPath = resolve-path($path)
  46. $settings.save($resolvedPath)
  47. }
  48. function set-appsetting {
  49. param($path, $name, $value)
  50. $settings = [xml](get-content $path)
  51. $setting = $settings.configuration.appSettings.selectsinglenode("add[@key='" + $name + "']")
  52. $setting.value = $value.toString()
  53. $resolvedPath = resolve-path($path)
  54. $settings.save($resolvedPath)
  55. }
  56. function set-releasemode {
  57. param($path)
  58. $xml = [xml](get-content $path)
  59. $compilation = $xml.configuration."system.web".compilation
  60. $compilation.debug = "false"
  61. $resolvedPath = resolve-path($path)
  62. $xml.save($resolvedPath)
  63. }
  64. function set-machinekey {
  65. param($path)
  66. if($validationKey -AND $decryptionKey){
  67. $xml = [xml](get-content $path)
  68. $machinekey = $xml.CreateElement("machineKey")
  69. $machinekey.setattribute("validation", "HMACSHA256")
  70. $machinekey.setattribute("validationKey", $validationKey)
  71. $machinekey.setattribute("decryption", "AES")
  72. $machinekey.setattribute("decryptionKey", $decryptionKey)
  73. $xml.configuration."system.web".AppendChild($machineKey)
  74. $resolvedPath = resolve-path($path)
  75. $xml.save($resolvedPath)
  76. }
  77. }
  78. # Do Work Brah
  79. $scriptPath = split-path $MyInvocation.MyCommand.Path
  80. $rootPath = resolve-path(join-path $scriptPath "..")
  81. $csdefFile = join-path $scriptPath "JabbR.csdef"
  82. $websitePath = join-path $rootPath "JabbR"
  83. $webConfigPath = join-path $websitePath "Web.config"
  84. $webConfigBakPath = join-path $scriptPath "Web.config.bak"
  85. $rolePropertiesPath = join-path $scriptPath "JabbR.RoleProperties.txt"
  86. $cscfgPath = join-path $scriptPath "JabbR.cscfg"
  87. $cscfgBakPath = join-path $scriptPath "JabbR.cscfg.bak"
  88. $cspkgFolder = join-path $rootPath "_AzurePackage"
  89. $cspkgFile = join-path $cspkgFolder "JabbR.cspkg"
  90. $gitPath = join-path (programfiles-dir) "Git\bin\git.exe"
  91. $binPath = join-path $websitePath "bin"
  92. if ($commitSha -eq $null) {
  93. $commitSha = (& "$gitPath" rev-parse HEAD)
  94. }
  95. if ($commitBranch -eq $null) {
  96. $commitBranch = (& "$gitPath" name-rev --name-only HEAD)
  97. }
  98. if ((test-path $cspkgFolder) -eq $false) {
  99. mkdir $cspkgFolder | out-null
  100. }
  101. cp $webConfigPath $webConfigBakPath
  102. cp $cscfgPath $cscfgBakPath
  103. set-appsetting -path $webConfigPath -name "auth.apiKey" -value $authKey
  104. set-appsetting -path $webConfigPath -name "googleAnalytics" -value $googleAnalyticsToken
  105. set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" -value $remoteDesktopAccountExpiration
  106. set-certificatethumbprint -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" -value $remoteDesktopCertificateThumbprint
  107. set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" -value $remoteDesktopEnctyptedPassword
  108. set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" -value $remoteDesktopUsername
  109. set-connectionstring -path $webConfigPath -name "JabbR" -value $sqlAzureConnectionString
  110. set-releasemode $webConfigPath
  111. set-machinekey $webConfigPath
  112. & 'C:\Program Files\Windows Azure SDK\v1.6\bin\cspack.exe' "$csdefFile" /out:"$cspkgFile" /role:"Website;$websitePath" /sites:"Website;Web;$websitePath" /rolePropertiesFile:"Website;$rolePropertiesPath"
  113. cp $cscfgPath $cspkgFolder
  114. cp $webConfigBakPath $webConfigPath
  115. cp $cscfgBakPath $cscfgPath
  116. print-success("Azure package and configuration dropped to $cspkgFolder.")
  117. write-host ""
  118. Exit 0