-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInstall.ps1
54 lines (42 loc) · 1.79 KB
/
Install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Adapted from posh-git's install.ps1
# Copyright (c) 2010-2011 Keith Dahlby and contributors
param(
[switch]$WhatIf = $false,
[string] $WhichProfile = $PROFILE.CurrentUserCurrentHost
)
if($PSVersionTable.PSVersion.Major -lt 3) {
Write-Warning "SitecoreShipFunctions requires PowerShell 3.0 or better; you have version $($Host.Version)."
return
}
if(!(Test-Path $WhichProfile)) {
Write-Host "Creating PowerShell profile...`n$WhichProfile"
New-Item $WhichProfile -Force -Type File -ErrorAction Stop -WhatIf:$WhatIf > $null
}
$installDir = Split-Path $MyInvocation.MyCommand.Path -Parent
# Adapted from http://www.west-wind.com/Weblog/posts/197245.aspx
function Get-FileEncoding($Path) {
$bytes = [byte[]](Get-Content $Path -Encoding byte -ReadCount 4 -TotalCount 4)
if(!$bytes) { return 'utf8' }
switch -regex ('{0:x2}{1:x2}{2:x2}{3:x2}' -f $bytes[0],$bytes[1],$bytes[2],$bytes[3]) {
'^efbbbf' { return 'utf8' }
'^2b2f76' { return 'utf7' }
'^fffe' { return 'unicode' }
'^feff' { return 'bigendianunicode' }
'^0000feff' { return 'utf32' }
default { return 'ascii' }
}
}
$profileLine = "Import-Module '$installDir\SitecoreShipFunctions.psd1'"
if(Select-String -Path $WhichProfile -Pattern $profileLine -Quiet -SimpleMatch) {
Write-Host "It seems SitecoreShipFunctions is already installed..."
return
}
Write-Host "Adding SitecoreShipFunctions to profile..."
@"
# Load SitecoreShipFunctions module
$profileLine
"@ | Out-File $WhichProfile -Append -WhatIf:$WhatIf -Encoding (Get-FileEncoding $WhichProfile)
Write-Host 'SitecoreShipFunctions sucessfully installed!'
Write-Host 'Please reload your profile for the changes to take effect:'
Write-Host " . $WhichProfile"
Write-Host "To reload, simply type '& `$profile'"