/Scripts/Package.ps1
http://myjabbr.codeplex.com · Powershell · 137 lines · 114 code · 19 blank · 4 comment · 9 complexity · 235070ee313c9df2f003676159d821f8 MD5 · raw file
- param(
- $authKey = $env:JABBR_AUTH_KEY,
- $googleAnalyticsToken = $env:JABBR_GOOGLE_ANALYTICS,
- $remoteDesktopAccountExpiration = $env:JABBR_REMOTE_DESKTOP_ACCOUNT_EXPIRATION,
- $remoteDesktopCertificateThumbprint = $env:JABBR_REMOTE_DESKTOP_CERTIFICATE_THUMBPRINT,
- $remoteDesktopEnctyptedPassword = $env:JABBR_REMOTE_DESKTOP_ENCRYPTED_PASSWORD,
- $remoteDesktopUsername = $env:JABBR_REMOTE_DESKTOP_USERNAME,
- $sqlAzureConnectionString = $env:JABBR_SQL_AZURE_CONNECTION_STRING,
- $commitSha,
- $commitBranch
- )
- # Import Common Stuff
- $ScriptRoot = (Split-Path -parent $MyInvocation.MyCommand.Definition)
- . $ScriptRoot\_Common.ps1
- # Validate Sutff
- require-param -value $authKey -paramName "authKey"
- require-param -value $remoteDesktopAccountExpiration -paramName "remoteDesktopAccountExpiration"
- require-param -value $remoteDesktopCertificateThumbprint -paramName "remoteDesktopCertificateThumbprint"
- require-param -value $remoteDesktopEnctyptedPassword -paramName "remoteDesktopEnctyptedPassword"
- require-param -value $remoteDesktopUsername -paramName "remoteDesktopUsername"
- require-param -value $sqlAzureConnectionString -paramName "sqlAzureConnectionString"
- # Helper Functions
- function set-certificatethumbprint {
- param($path, $name, $value)
- $xml = [xml](get-content $path)
- $certificate = $xml.serviceconfiguration.role.Certificates.Certificate | where { $_.name -eq $name }
- $certificate.thumbprint = "$value"
- $resolvedPath = resolve-path($path)
- $xml.save($resolvedPath)
- }
- function set-configurationsetting {
- param($path, $name, $value)
- $xml = [xml](get-content $path)
- $setting = $xml.serviceconfiguration.role.configurationsettings.setting | where { $_.name -eq $name }
- $setting.value = "$value"
- $resolvedPath = resolve-path($path)
- $xml.save($resolvedPath)
- }
- function set-connectionstring {
- param($path, $name, $value)
- $settings = [xml](get-content $path)
- $setting = $settings.configuration.connectionStrings.add | where { $_.name -eq $name }
- $setting.connectionString = "$value"
- $setting.providerName = "System.Data.SqlClient"
- $resolvedPath = resolve-path($path)
- $settings.save($resolvedPath)
- }
- function set-appsetting {
- param($path, $name, $value)
- $settings = [xml](get-content $path)
- $setting = $settings.configuration.appSettings.selectsinglenode("add[@key='" + $name + "']")
- $setting.value = $value.toString()
- $resolvedPath = resolve-path($path)
- $settings.save($resolvedPath)
- }
- function set-releasemode {
- param($path)
- $xml = [xml](get-content $path)
- $compilation = $xml.configuration."system.web".compilation
- $compilation.debug = "false"
- $resolvedPath = resolve-path($path)
- $xml.save($resolvedPath)
- }
- function set-machinekey {
- param($path)
- if($validationKey -AND $decryptionKey){
- $xml = [xml](get-content $path)
- $machinekey = $xml.CreateElement("machineKey")
- $machinekey.setattribute("validation", "HMACSHA256")
- $machinekey.setattribute("validationKey", $validationKey)
- $machinekey.setattribute("decryption", "AES")
- $machinekey.setattribute("decryptionKey", $decryptionKey)
- $xml.configuration."system.web".AppendChild($machineKey)
- $resolvedPath = resolve-path($path)
- $xml.save($resolvedPath)
- }
- }
- # Do Work Brah
- $scriptPath = split-path $MyInvocation.MyCommand.Path
- $rootPath = resolve-path(join-path $scriptPath "..")
- $csdefFile = join-path $scriptPath "JabbR.csdef"
- $websitePath = join-path $rootPath "JabbR"
- $webConfigPath = join-path $websitePath "Web.config"
- $webConfigBakPath = join-path $scriptPath "Web.config.bak"
- $rolePropertiesPath = join-path $scriptPath "JabbR.RoleProperties.txt"
- $cscfgPath = join-path $scriptPath "JabbR.cscfg"
- $cscfgBakPath = join-path $scriptPath "JabbR.cscfg.bak"
- $cspkgFolder = join-path $rootPath "_AzurePackage"
- $cspkgFile = join-path $cspkgFolder "JabbR.cspkg"
- $gitPath = join-path (programfiles-dir) "Git\bin\git.exe"
- $binPath = join-path $websitePath "bin"
- if ($commitSha -eq $null) {
- $commitSha = (& "$gitPath" rev-parse HEAD)
- }
- if ($commitBranch -eq $null) {
- $commitBranch = (& "$gitPath" name-rev --name-only HEAD)
- }
- if ((test-path $cspkgFolder) -eq $false) {
- mkdir $cspkgFolder | out-null
- }
- cp $webConfigPath $webConfigBakPath
- cp $cscfgPath $cscfgBakPath
- set-appsetting -path $webConfigPath -name "auth.apiKey" -value $authKey
- set-appsetting -path $webConfigPath -name "googleAnalytics" -value $googleAnalyticsToken
- set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration" -value $remoteDesktopAccountExpiration
- set-certificatethumbprint -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.PasswordEncryption" -value $remoteDesktopCertificateThumbprint
- set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountEncryptedPassword" -value $remoteDesktopEnctyptedPassword
- set-configurationsetting -path $cscfgPath -name "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" -value $remoteDesktopUsername
- set-connectionstring -path $webConfigPath -name "JabbR" -value $sqlAzureConnectionString
- set-releasemode $webConfigPath
- set-machinekey $webConfigPath
- & 'C:\Program Files\Windows Azure SDK\v1.6\bin\cspack.exe' "$csdefFile" /out:"$cspkgFile" /role:"Website;$websitePath" /sites:"Website;Web;$websitePath" /rolePropertiesFile:"Website;$rolePropertiesPath"
- cp $cscfgPath $cspkgFolder
- cp $webConfigBakPath $webConfigPath
- cp $cscfgBakPath $cscfgPath
- print-success("Azure package and configuration dropped to $cspkgFolder.")
- write-host ""
- Exit 0