-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
instdev.ps1
67 lines (57 loc) · 3.01 KB
/
instdev.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
55
56
57
58
59
60
61
62
63
64
65
66
67
#Requires -Version 5.1
# set the user module path based on edition and platform
if ($PSVersionTable.PSEdition -eq 'Desktop') {
$installpath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell\Modules'
} elseif ($IsWindows) {
$installpath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'PowerShell\Modules'
} else {
$installpath = Join-Path $env:HOME '.local/share/powershell/Modules'
}
# deal with execution policy on Windows
if (('PSEdition' -notin $PSVersionTable.Keys -or
$PSVersionTable.PSEdition -eq 'Desktop' -or
$IsWindows) -and
(Get-ExecutionPolicy) -notin 'Unrestricted','RemoteSigned','Bypass')
{
Write-Host "Setting user execution policy to RemoteSigned" -ForegroundColor Cyan
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
}
# create user-specific modules folder if it doesn't exist
New-Item -ItemType Directory -Force -Path $installpath | out-null
if ([String]::IsNullOrWhiteSpace($PSScriptRoot)) {
if ([String]::IsNullOrWhiteSpace($remoteBranch)) {
$remoteBranch = 'main'
}
# GitHub now requires TLS 1.2
# https://blog.github.com/2018-02-23-weak-cryptographic-standards-removed/
$currentMaxTls = [Math]::Max([Net.ServicePointManager]::SecurityProtocol.value__,[Net.SecurityProtocolType]::Tls.value__)
$newTlsTypes = [enum]::GetValues('Net.SecurityProtocolType') | Where-Object { $_ -gt $currentMaxTls }
$newTlsTypes | ForEach-Object {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor $_
}
# likely running from online, so download
$url = "https://github.com/rmbolger/Posh-ACME/archive/$remoteBranch.zip"
Write-Host "Downloading latest version of Posh-ACME from $url" -ForegroundColor Cyan
$file = Join-Path ([system.io.path]::GetTempPath()) 'Posh-ACME.zip'
$webclient = New-Object System.Net.WebClient
try { $webclient.DownloadFile($url,$file) }
catch { throw }
Write-Host "File saved to $file" -ForegroundColor Green
# extract the zip
Write-Host "Uncompressing the Zip file to $($installpath)" -ForegroundColor Cyan
Expand-Archive $file -DestinationPath $installpath
Write-Host "Removing any old copy" -ForegroundColor Cyan
Remove-Item "$installpath\Posh-ACME" -Recurse -Force -EA Ignore
Write-Host "Renaming folder" -ForegroundColor Cyan
Copy-Item "$installpath\Posh-ACME-$remoteBranch\Posh-ACME" $installpath -Recurse -Force -EA Continue
Remove-Item "$installpath\Posh-ACME-$remoteBranch" -Recurse -Force
Import-Module -Name Posh-ACME -Force
} else {
# running locally
Remove-Item "$installpath\Posh-ACME" -Recurse -Force -EA Ignore
Copy-Item "$PSScriptRoot\Posh-ACME" $installpath -Recurse -Force -EA Continue
# force re-load the module (assuming you're editing locally and want to see changes)
Import-Module -Name Posh-ACME -Force
}
Write-Host 'Module has been installed' -ForegroundColor Green
Get-Command -Module Posh-ACME