-
Notifications
You must be signed in to change notification settings - Fork 1
/
instdev.ps1
65 lines (56 loc) · 3.04 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
#Requires -Version 5.1
# set the user module path based on edition and platform
if ('PSEdition' -notin $PSVersionTable.Keys -or $PSVersionTable.PSEdition -eq 'Desktop') {
$installpath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'WindowsPowerShell\Modules'
} else {
if ($IsWindows) {
$installpath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'PowerShell\Modules'
} else {
$installpath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) '.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)) {
# 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/DnsClient-PS/archive/main.zip'
Write-Host "Downloading latest version of DnsClient-PS from $url" -ForegroundColor Cyan
$file = Join-Path ([system.io.path]::GetTempPath()) 'DnsClient-PS.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\DnsClient-PS" -Recurse -Force -EA Ignore
Write-Host "Renaming folder" -ForegroundColor Cyan
Copy-Item "$installpath\DnsClient-PS-main\DnsClient-PS" $installpath -Recurse -Force -EA Continue
Remove-Item "$installpath\DnsClient-PS-main" -recurse -confirm:$false
Import-Module -Name DnsClient-PS -Force
} else {
# running locally
Remove-Item "$installpath\DnsClient-PS" -Recurse -Force -EA Ignore
Copy-Item "$PSScriptRoot\DnsClient-PS" $installpath -Recurse -Force -EA Continue
# force re-load the module (assuming you're editing locally and want to see changes)
Import-Module -Name DnsClient-PS -Force
}
Write-Host 'Module has been installed' -ForegroundColor Green
Get-Command -Module DnsClient-PS