Commit 90030416 authored by Viet Hoang's avatar Viet Hoang

init the Scripts for Sitecore 9.1 installation

parent 61a956c5
Function Get-JavaVersions() {
$versions = '', 'Wow6432Node\' |
ForEach-Object {Get-ItemProperty -Path HKLM:\SOFTWARE\$($_)Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object {($_.DisplayName -like '*Java *') -and (-not $_.SystemComponent)} |
Select-Object DisplayName, DisplayVersion, InstallLocation, @{n = 'Architecture'; e = {If ($_.PSParentPath -like '*Wow6432Node*') {'x86'} Else {'x64'}}}}
return $versions
}
Function Get-JavaInstallationPath
{
param (
[version] $toVersion
)
$versions_ = Get-JavaVersions
$foundRightVersion = $false
$JavaInstallPath = ""
foreach ($version_ in $versions_) {
try {
$version = New-Object System.Version($version_.DisplayVersion)
}
catch {
continue
}
if ($version.CompareTo($toVersion) -ge 0) {
$foundRightVersion = $true
$JavaInstallPath = $version_.InstallLocation
break;
}
}
if (-not $foundRightVersion) {
throw "Invalid Java version. Expected $JavaMinVersionRequired or above."
}
return $JavaInstallPath
}
Function Find-UpdateJAVAHOME
{
param (
[Version] $JavaMinVersionRequired
)
$JREPath = Get-JavaInstallationPath($JavaMinVersionRequired)
$jreVal_ = [Environment]::GetEnvironmentVariable("JAVA_HOME", [EnvironmentVariableTarget]::Machine)
if($jreVal_ -ne $JREPath)
{
Write-Host "Setting JAVA_HOME environment variable"
[Environment]::SetEnvironmentVariable("JAVA_HOME", $JREPath, [EnvironmentVariableTarget]::Machine)
# Fixed known issue: error finding keytool
$jreVal_ = $JREPath
}
return $jreVal_
}
Function Get-JavaKeytool
{
param (
[string] $JavaMinVersionRequired = "8.0.1510"
)
$RequiredVersion = New-Object System.Version($JavaMinVersionRequired)
try {
$jreVal = Find-UpdateJAVAHOME -JavaMinVersionRequired $RequiredVersion
$path = $jreVal + '\bin\keytool.exe'
if (Test-Path $path) {
$keytool_ = (Get-Command $path).Source
}
} catch {
$keytool_ = Read-Host "keytool.exe not on path. Enter path to keytool (found in JRE bin folder)"
}
if([string]::IsNullOrEmpty($keytool_) -or -not (Test-Path $keytool_)) {
throw "Keytool path was invalid."
}
return $keytool_
}
function downloadAndUnzipIfRequired
{
Param(
[string]$toolName,
[string]$toolFolder,
[string]$toolZip,
[string]$toolSourceFile,
[string]$installRoot
)
if(!(Test-Path -Path $toolFolder))
{
if(!(Test-Path -Path $toolZip))
{
Write-Host "Downloading $toolName..."
Start-BitsTransfer -Source $toolSourceFile -Destination $toolZip
}
Write-Host "Extracting $toolName to $toolFolder..."
Expand-Archive $toolZip -DestinationPath $installRoot
}
}
\ No newline at end of file
# Credit primarily to jermdavis for the original script
Param(
[string]$solrVersion = "7.2.1",
[string]$installFolder = "D:\solr",
[string]$solrPort = "8984",
[string]$solrHost = "localhost",
[bool]$solrSSL = $TRUE,
[string]$nssmVersion = "2.24",
[string]$keystoreSecret = "secret",
[string]$KeystoreFile = 'solr-ssl.keystore.jks',
[string]$SolrDomain = 'localhost',
[switch]$Clobber
)
$solrName = "solr-$solrVersion"
$solrRoot = "$installFolder\$solrName"
$nssmRoot = "$installFolder\nssm-$nssmVersion"
$solrPackage = "http://archive.apache.org/dist/lucene/solr/$solrVersion/$solrName.zip"
$nssmPackage = "http://nssm.cc/release/nssm-$nssmVersion.zip"
$downloadFolder =(Resolve-Path "\")
## Verify elevated
## https://superuser.com/questions/749243/detect-if-powershell-is-running-as-administrator
$elevated = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
if(!($elevated))
{
throw "In order to install services, please run this script elevated."
}
$JavaMinVersionRequired = "8.0.1510"
if (Get-Module("helper")) {
Remove-Module "helper"
}
Import-Module "$PSScriptRoot\helper.psm1"
$ErrorActionPreference = 'Stop'
# Ensure Java environment variable
try {
$keytool = (Get-Command 'keytool.exe').Source
} catch {
$keytool = Get-JavaKeytool -JavaMinVersionRequired $JavaMinVersionRequired
}
# download & extract the solr archive to the right folder
$solrZip = "$downloadFolder\$solrName.zip"
downloadAndUnzipIfRequired "Solr" $solrRoot $solrZip $solrPackage $installFolder
# download & extract the nssm archive to the right folder
$nssmZip = "$downloadFolder\nssm-$nssmVersion.zip"
downloadAndUnzipIfRequired "NSSM" $nssmRoot $nssmZip $nssmPackage $installFolder
### PARAM VALIDATION
if($keystoreSecret -ne 'secret') {
Write-Error 'The keystore password must be "secret", because Solr apparently ignores the parameter'
}
if((Test-Path $KeystoreFile)) {
if($Clobber) {
Write-Host "Removing $KeystoreFile..."
Remove-Item $KeystoreFile
} else {
$KeystorePath = Resolve-Path $KeystoreFile
Write-Error "Keystore file $KeystorePath already existed. To regenerate it, pass -Clobber."
}
}
$P12Path = [IO.Path]::ChangeExtension($KeystoreFile, 'p12')
if((Test-Path $P12Path)) {
if($Clobber) {
Write-Host "Removing $P12Path..."
Remove-Item $P12Path
} else {
$P12Path = Resolve-Path $P12Path
Write-Error "Keystore file $P12Path already existed. To regenerate it, pass -Clobber."
}
}
### DOING STUFF
Write-Host ''
Write-Host 'Generating JKS keystore...'
& $keytool -genkeypair -alias solr-ssl -keyalg RSA -keysize 2048 -keypass $keystoreSecret -storepass $keystoreSecret -validity 9999 -keystore $KeystoreFile -ext SAN=DNS:$SolrDomain,IP:127.0.0.1 -dname "CN=$SolrDomain, OU=Organizational Unit, O=Organization, L=Location, ST=State, C=Country"
Write-Host ''
Write-Host 'Generating .p12 to import to Windows...'
& $keytool -importkeystore -srckeystore $KeystoreFile -destkeystore $P12Path -srcstoretype jks -deststoretype pkcs12 -srcstorepass $keystoreSecret -deststorepass $keystoreSecret
Write-Host ''
Write-Host 'Trusting generated SSL certificate...'
$secureStringKeystorePassword = ConvertTo-SecureString -String $keystoreSecret -Force -AsPlainText
$root = Import-PfxCertificate -FilePath $P12Path -Password $secureStringKeystorePassword -CertStoreLocation Cert:\LocalMachine\Root
Write-Host 'SSL certificate is now locally trusted. (added as root CA)'
if(-not $KeystoreFile.EndsWith('solr-ssl.keystore.jks')) {
Write-Warning 'Your keystore file is not named "solr-ssl.keystore.jks"'
Write-Warning 'Solr requires this exact name, so make sure to rename it before use.'
}
$KeystorePath = Resolve-Path $KeystoreFile
Copy-Item $KeystorePath -Destination "$solrRoot\server\etc\solr-ssl.keystore.jks" -Force
# Update solr cfg to use keystore & right host name
if(Test-Path -Path "$solrRoot\bin\solr.in.cmd.old")
{
Write-Host "Resetting solr.in.cmd" -ForegroundColor Green
Remove-Item "$solrRoot\bin\solr.in.cmd"
Rename-Item -Path "$solrRoot\bin\solr.in.cmd.old" -NewName "$solrRoot\bin\solr.in.cmd"
}
Write-Host "Rewriting solr config"
$cfg = Get-Content "$solrRoot\bin\solr.in.cmd"
Rename-Item "$solrRoot\bin\solr.in.cmd" "$solrRoot\bin\solr.in.cmd.old"
$certStorePath = "etc/solr-ssl.keystore.jks"
$newCfg = $cfg | ForEach-Object { $_ -replace "REM set SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks", "set SOLR_SSL_KEY_STORE=$certStorePath" }
$newCfg = $newCfg | ForEach-Object { $_ -replace "REM set SOLR_SSL_KEY_STORE_PASSWORD=secret", "set SOLR_SSL_KEY_STORE_PASSWORD=$keystoreSecret" }
$newCfg = $newCfg | ForEach-Object { $_ -replace "REM set SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks", "set SOLR_SSL_TRUST_STORE=$certStorePath" }
$newCfg = $newCfg | ForEach-Object { $_ -replace "REM set SOLR_SSL_TRUST_STORE_PASSWORD=secret", "set SOLR_SSL_TRUST_STORE_PASSWORD=$keystoreSecret" }
$newCfg = $newCfg | ForEach-Object { $_ -replace "REM set SOLR_HOST=192.168.1.1", "set SOLR_HOST=$solrHost" }
$newCfg | Set-Content "$solrRoot\bin\solr.in.cmd"
# install the service & runs
$svc = Get-Service "$solrName" -ErrorAction SilentlyContinue
if(!($svc))
{
Write-Host "Installing Solr service"
&"$installFolder\nssm-$nssmVersion\win64\nssm.exe" install "$solrName" "$solrRoot\bin\solr.cmd" "-f" "-p $solrPort"
$svc = Get-Service "$solrName" -ErrorAction SilentlyContinue
}
if($svc.Status -ne "Running")
{
Write-Host "Starting Solr service..."
Start-Service "$solrName"
}
elseif ($svc.Status -eq "Running")
{
Write-Host "Restarting Solr service..."
Restart-Service "$solrName"
}
Start-Sleep -s 5
# finally prove it's all working
$protocol = "http"
if($solrSSL)
{
$protocol = "https"
}
Invoke-Expression "start $($protocol)://$($solrHost):$solrPort/solr/#/"
Write-Host ''
Write-Host 'Done!' -ForegroundColor Green
\ No newline at end of file
$InstallDirectory = "D:\websites\"
#The prefix that will be used on the SOLR, Website, and Database instances.
$Prefix = "sc910"
# The root folder with the license file and the WDP files.
$SCInstallRoot = "D:\sc91_install"
# The name of the XConnect service.
$XConnectSiteName = "$prefix.xconnect.local"
# The Sitecore site instance name.
$SitecoreSiteName = "$prefix.local"
# The Identity Server site name.
$IdentityServerSiteName = "$prefix.identityserver.local"
# The path to the license file.
$LicenseFile = "$SCInstallRoot\license.xml"
# The URL of the Solr Server.
$SolrUrl = "https://localhost:8984/solr"
# The folder that Solr has been installed in.
$SolrRoot = "D:\Solr\solr-7.2.1"
# The name of the Solr Service.
$SolrService = "Solr-7.2.1"
# The DNS name or IP address of the SQL Instance.
$SqlServer = "DESKTOP-12HS4P0"
# A SQL user with sysadmin privileges.
$SqlAdminUser = "sa"
# The password for $SQLAdminUser.
$SqlAdminPassword = "Abcd1234"
# The path to the XConnect package to deploy.
$XConnectPackage = "$SCInstallRoot\Sitecore 9.1.0 rev. 001442 (OnPrem)_xp0xconnect.scwdp.zip"
# The path to the Sitecore package to deploy.
$SitecorePackage = "$SCInstallRoot\Sitecore 9.1.0 rev. 001442 (OnPrem)_single.scwdp.zip"
# The path to the Identity Server package to deploy.
$IdentityServerPackage = "$SCInstallRoot\Sitecore.IdentityServer 2.0.0 rev. 00151 (OnPrem)_identityserver.scwdp.zip"
# The Identity Server password recovery URL, this should be the URL of the CM instance.
$PasswordRecoveryUrl = "http://$SitecoreSiteName"
# The URL of the XconnectService.
$XConnectCollectionService = "https://$XConnectSiteName"
# The URL of the Identity Authority.
$SitecoreIdentityAuthority = "https://$IdentityServerSiteName"
# The random string key used for establishing a connection with the IdentityService.
$ClientSecret = "SIF-Default"
# A pipe-separated list of instances (URIs) that are allowed to log in through Sitecore Identity.
$AllowedCorsOrigins = "http://$SitecoreSiteName"
# Install XP0 via combined partials file.
$singleDeveloperParams = @{
Path = "$SCInstallRoot\XP0-SingleDeveloper.json"
InstallDirectory = $InstallDirectory
SqlServer = $SqlServer
SqlAdminUser = $SqlAdminUser
SqlAdminPassword = $SqlAdminPassword
SolrUrl = $SolrUrl
SolrRoot = $SolrRoot
SolrService = $SolrService
Prefix = $Prefix
XConnectCertificateName = $XConnectSiteName
IdentityServerCertificateName = $IdentityServerSiteName
IdentityServerSiteName = $IdentityServerSiteName
LicenseFile = $LicenseFile
XConnectPackage = $XConnectPackage
SitecorePackage = $SitecorePackage
IdentityServerPackage = $IdentityServerPackage
XConnectSiteName = $XConnectSiteName
SitecoreSitename = $SitecoreSiteName
PasswordRecoveryUrl = $PasswordRecoveryUrl
SitecoreIdentityAuthority = $SitecoreIdentityAuthority
XConnectCollectionService = $XConnectCollectionService
ClientSecret = $ClientSecret
AllowedCorsOrigins = $AllowedCorsOrigins
}
Push-Location $SCInstallRoot
Install-SitecoreConfiguration @singleDeveloperParams *>&1 | Tee-Object XP0-SingleDeveloper.log
Pop-Location
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment