diff --git a/InstallScripts/deploy.ps1 b/InstallScripts/deploy.ps1 new file mode 100644 index 0000000..a6979cf --- /dev/null +++ b/InstallScripts/deploy.ps1 @@ -0,0 +1,40 @@ +Function Deploy +{ + ##param ( + ##[Parameter(Mandatory=$true)] + ##[string] $enviroment, +## [Parameter(Mandatory=$true)] +## [string] $artifiactName +## ) + $enviroment = "development" + $artifiactName = "sgp_1.3.1.200.zip" + + Import-Module ".\remoteDeployModules.psm1" + $azureConnectionString = "DefaultEndpointsProtocol=https;AccountName=pebbledeploybucket;AccountKey=V4K6iBIbAdDsoQ/Ly7RBpEF8dFvtOdRomFV4a80hxzp5eTxBaOwbkUSE2IELSV+f+5ZG9KVobY7WR/Yy3dABAA==" + $containerName = "testbucket" + Import-Module "C:\Windows\System32\AzureHelper.dll" + + #Upload the artifact to the blob store to use later + Push-AzureBlobUpload -ContainerName $containerName -ConnectionString $azureConnectionString -LocalFileName $artifiactName + + #Replace config with latest from git + rm config -Recurse -Force -ErrorAction SilentlyContinue + git clone git@github.com:BedeGaming/config.git -b powershell-remote-deploy-scripts + + #Loop through each settings folder in the enviroment and install the service + $settingsFolder = ("config\"+$enviroment) + foreach ($serverName in (Get-ChildItem -Path $settingsFolder)){ + + Write-Host ("Deploying to " + $serverName) + $settings = Get-Content ("config\"+$enviroment +"\" + $serverName + "\settings.xml") + RemoteInstall -remotePC $serverName -azureConnectionString $azureConnectionString -artifiactName $artifiactName -containerName $containerName -settings $settings + } +} + +try{ + Deploy +}catch{ + Write-Error $_.Exception.Message + exit 1 + +} diff --git a/InstallScripts/remoteDeployModules.psm1 b/InstallScripts/remoteDeployModules.psm1 new file mode 100644 index 0000000..d3f2b3a --- /dev/null +++ b/InstallScripts/remoteDeployModules.psm1 @@ -0,0 +1,44 @@ +Function RemoteInstall +{ + param ([string] $remotePC, [string] $azureConnectionString, [string] $artifiactName, [string] $containerName, [string] $settings) + + $params = $remotePC, $azureConnectionString,$artifiactName,$containerName,$settings + $remoteSession = new-pssession -computerName $remotePC + + invoke-command -session $remoteSession -ArgumentList $params -ScriptBlock { + try + { + mkdir -ErrorAction SilentlyContinue "C:\BEDE\Temp" + Set-Location "C:\BEDE\Temp" + + #Download File + $ZipName = "Artifacts.zip" + $file = "C:\BEDE\Temp\" + $ZipName + Import-Module "C:\Windows\System32\AzureHelper.dll" + Get-AzureBlobDownload -ConnectionString $args[1] -RemoteFileName $args[2] -ContainerName $args[3] -LocalFileName $file + + #Unzip it + $shell_app=new-object -com shell.application + $zip_file = $shell_app.namespace($file) + $destination = $shell_app.namespace((Get-Location).Path) + $destination.Copyhere($zip_file.items()) + + #Make the settings file + $args[4] > settings.xml + + #Run Installer + Invoke-Expression ("C:\BEDE\Temp\UnInstallerSub.ps1 -dir C:\BEDE\Temp") + Invoke-Expression ("C:\BEDE\Temp\InstallerSub.ps1 -dir C:\BEDE\Temp") + + #Clear the temp directory + get-childitem "C:\BEDE\Temp" -recurse | remove-item -recurse + } + finally + { + Exit-PSSession + } + } +} + + +export-modulemember RemoteInstall \ No newline at end of file