-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetgeoffrey.ps1
100 lines (85 loc) · 3.46 KB
/
getgeoffrey.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
[cmdletbinding()]
param(
[string]$sourceUri = 'https://raw.githubusercontent.com/geoffrey-ps/geoffrey/master/getgeoffrey.ps1',
[string]$toolsDir = ("$env:LOCALAPPDATA\LigerShark\tools\")
)
$installFolder = (Join-Path $toolsDir 'geoffrey-pre')
$installPath = (Join-Path $installFolder 'geoffrey.psm1')
if(Get-Module geoffrey){
'Removing geoffrey module' | Write-Verbose
Remove-Module geoffrey -force
}
function EnsureNuGetPowerShellInstlled2{
[cmdletbinding()]
param(
[string]$installUri = 'https://raw.githubusercontent.com/ligershark/nuget-powershell/master/get-nugetps.ps1'
)
process{
if(-not (Get-Command -Name Get-NuGetPackage -Module nuget-powershell -errorAction SilentlyContinue)){
'Installing nuget-powershell from [{0}]' -f $installUri | Write-Verbose
(new-object Net.WebClient).DownloadString($installUri) | iex
}
else{
'nuget-powershell already loaded, skipping download' | Write-Verbose
}
# make sure it's loaded and throw if not
if(-not (Get-Command -Name Get-NuGetPackage -Module nuget-powershell -errorAction SilentlyContinue)){
throw ('Unable to install/load nuget-powershell from [{0}]' -f $installUri)
}
}
}
function GetPsModulesPath2{
[cmdletbinding()]
param()
process{
$Destination = $null
if(Test-Path 'Env:PSModulePath'){
$ModulePaths = @($Env:PSModulePath -split ';')
$ExpectedUserModulePath = Join-Path -Path ([Environment]::GetFolderPath('MyDocuments')) -ChildPath WindowsPowerShell\Modules
$Destination = $ModulePaths | Where-Object { $_ -eq $ExpectedUserModulePath}
if (-not $Destination) {
$Destination = $ModulePaths | Select-Object -Index 0
}
}
$Destination
}
}
# install script
try{
EnsureNuGetPowerShellInstlled2
# get the module locally
$installpath = (Get-NuGetPackage -name geoffrey -version 0.0.11-beta -binpath)
# copy the files to the powershell modules folder
$destFolderPath = (Join-Path (GetPsModulesPath2) 'geoffrey')
if(-not (Test-Path $destFolderPath)){
'Creating modules folder at [{0}]' -f $destFolderPath | Write-Verbose
New-Item -Path $destFolderPath -ItemType Directory
}
[System.IO.FileInfo[]]$filesToCopy = (Get-ChildItem -Path $installPath *.ps*1)
$filesToCopy += (Get-ChildItem $installPath *.dll)
$filesToCopy += (Get-ChildItem $installPath *.md)
'Copying files to modules folder at [{0}]' -f $destFolderPath | Write-Verbose
$filesToCopy | Copy-Item -Destination $destFolderPath
Import-Module -Name (Join-Path $destFolderPath 'geoffrey.psm1')
}
catch{
'There was an error installing geoffrey. Exception details: {0}' -f ($_.Exception) | Write-Error
}
<#
# for now we re-install each time so delete the folder if it exists
if(Test-Path $installPath){
Remove-Item $installPath
}
if(-not (Test-Path $installFolder)){
new-item -Path $installFolder -ItemType Directory
}
'Downloading geoffrey.psm1 from [{0}] to [{1}]' -f $sourceUri,$installPath | Write-Verbose
(New-Object System.Net.WebClient).DownloadFile($sourceUri, $installPath) | Out-Null
# if the module is imported then remove it
if(Get-Module geoffrey){
'Removing geoffrey module' | Write-Verbose
Remove-Module geoffrey -force
}
'Importing geoffrey module from [{0}]' -f $installPath | Write-Verbose
Import-Module $installPath -DisableNameChecking -Global
#>