Skip to content

Instantly share code, notes, and snippets.

@jackpoz
Last active January 14, 2019 11:43
Show Gist options
  • Save jackpoz/6161c2872d9fd0527f506036ed5c5922 to your computer and use it in GitHub Desktop.
Save jackpoz/6161c2872d9fd0527f506036ed5c5922 to your computer and use it in GitHub Desktop.
PowerShell script to automate TrinityCore and requirements installation and update
$url = "https://gist.githubusercontent.com/jackpoz/6161c2872d9fd0527f506036ed5c5922/raw/Get-TrinityCore.ps1"
$output = "Get-TrinityCore.ps1"
#Invoke-WebRequest -Uri $url -OutFile $filename
(New-Object System.Net.WebClient).DownloadFile($url, [IO.Path]::Combine((get-location), $output))
#TrinityCore AutoInstaller and Updater
#In case PowerShell doesn't allow to execute this script, change the execution policy with "Set-ExecutionPolicy -ExecutionPolicy Unrestricted". For more informations check "get-help Set-ExecutionPolicy"
$ErrorActionPreference = "Stop"
#Config variables
$appVeyorBinariesUrl = "https://ci.appveyor.com/api/projects/DDuarte/trinitycore/artifacts/build/bin/TrinityCoreWin64VS2017.zip"
$appVeyorFileName = "TrinityCore.zip"
$binariesFolder = "TrinityCore"
$vc12RuntimeUrl = "http://download.microsoft.com/download/0/5/6/056dcda9-d667-4e27-8001-8a0c6971d6b1/vcredist_x64.exe"
$vc12RuntimeFileName = "vc12redist.exe"
$vcRuntimeUrl = "https://aka.ms/vs/15/release/vc_redist.x64.exe"
$vcRuntimeFileName = "vcredist.exe"
$tdbUrl = "https://github.com/TrinityCore/TrinityCore/releases/download/TDB335.64/TDB_full_world_335.64_2018_02_19.zip"
$tdbFileName = "tdb.zip"
$webclient = New-Object System.Net.WebClient
$localFolder = ((Get-Location).Path + "\")
function UnhandledChoice
{
Write-Error -Message "Unhandled choice in a switch statement" -ErrorAction Stop
}
function Expand-ZIPFile($file, $destination)
{
$zipOptions = 4 + 1024
if (Test-Path $destination)
{
$title = "Destionation folder already exist"
$info = "Destination folder $destination already exist, do you want to [Overwrite] the files, [Delete] the folder or [Stop] the execution of the script ?"
$options = [System.Management.Automation.Host.ChoiceDescription[]] @("&Overwrite", "&Delete", "&Stop")
[int]$defaultchoice = 0
$opt = $host.UI.PromptForChoice($title, $info, $options, $defaultchoice)
switch($opt)
{
0 { $zipOptions += 16 }
1 { rm -force -Recurse -Path $destination
mkdir $destination | Out-Null
}
2 { Write-Error -Message "User chose to stop the execution of the script" -ErrorAction Stop }
Default { UnhandledChoice }
}
}
else
{
mkdir $destination | Out-Null
}
$shell = New-Object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).CopyHere($item, $zipOptions)
}
}
function DownloadFile($url, $destination)
{
$webclient.DownloadFile($url, $destination)
}
function InstallAppVeyor
{
Write-Output "Downloading from AppVeyor the archive with latest build. This is a HUGE archive of around ~100 MB and will take some time"
DownloadFile $appVeyorBinariesUrl ($localFolder + $appVeyorFileName)
Write-Output "Extracting the content to $binariesFolder"
Expand-ZIPFile($localFolder + $appVeyorFileName) ($localFolder + $binariesFolder)
Write-Output "Downloading Visual C++ runtimes"
DownloadFile $vc12RuntimeUrl ($localFolder + $vc12RuntimeFileName)
DownloadFile $vcRuntimeUrl ($localFolder + $vcRuntimeFileName)
Write-Output "Installing Visual C++ runtimes"
Start-Process -FilePath $vc12RuntimeFileName -Wait -ArgumentList "/install", "/quite", "/passive", "/norestart"
Start-Process -FilePath $vcRuntimeFileName -Wait -ArgumentList "/install", "/quite", "/passive", "/norestart"
Write-Output "Downloading TDB"
DownloadFile $tdbUrl ($localFolder + $tdbFileName)
Write-Output "Extracting TDB $binariesFolder"
Expand-ZIPFile($localFolder + $tdbFileName) ($localFolder + $binariesFolder)
Write-Error -Message ("ToDo: implement " + $MyInvocation.MyCommand) -ErrorAction Stop
}
function InstallLocal
{
Write-Error -Message ("ToDo: implement " + $MyInvocation.MyCommand) -ErrorAction Stop
}
function InstallMain
{
$title = "AppVeyor or Local compile"
$info = "Would you like to download binaries from [AppVeyor] or setup a [Local] build environment to build the binaries from the sources ?"
$options = [System.Management.Automation.Host.ChoiceDescription[]] @("&AppVeyor", "&Local")
[int]$defaultchoice = 0
$opt = $host.UI.PromptForChoice($title, $info, $options, $defaultchoice)
switch($opt)
{
0 { InstallAppVeyor }
1 { InstallLocal }
Default { UnhandledChoice }
}
}
function UpdateMain
{
Write-Error -Message ("ToDo: implement " + $MyInvocation.MyCommand) -ErrorAction Stop
}
function AskInstallOrUpdate
{
$title = "Install or Update"
$info = "Would you like to [Install] TrinityCore from scratch on a new environment or would you like to [Update] an existing installation ?"
$options = [System.Management.Automation.Host.ChoiceDescription[]] @("&Install", "&Update")
[int]$defaultchoice = 0
$opt = $host.UI.PromptForChoice($title, $info, $options, $defaultchoice)
switch($opt)
{
0 { InstallMain }
1 { UpdateMain }
Default { UnhandledChoice }
}
}
function Get-TrinityCore
{
AskInstallOrUpdate
}
Get-TrinityCore
@jackpoz
Copy link
Author

jackpoz commented Jan 3, 2019

Windows Server 2008 R2

  • check for (Get-HotFix -Id KB976932) -eq $null
    check the windows version with (Get-CimInstance Win32_OperatingSystem).version
    it can be a nice to have, for now just ignore the issue
  • Some KB update is required to add support to Tls12 to .NET, required to download TDB [System.Net.ServicePointManager]::SecurityProtocol = [Enum]::ToObject([System.Net.SecurityProtocolType], 3072)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment