-
Notifications
You must be signed in to change notification settings - Fork 4
/
install-local.ps1
59 lines (54 loc) · 1.87 KB
/
install-local.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
[CmdletBinding()]
Param(
[Parameter(Mandatory=$false,Position=0)]
[string]$TargetDir
)
if (-not $PSBoundParameters.ContainsKey("ErrorAction")) { $ErrorActionPreference = "Stop" }
if (-not $PSBoundParameters.ContainsKey("Verbose")) { $VerbosePreference = $PSCmdlet.GetVariableValue("VerbosePreference") }
if ($PSVersionTable.Platform -ne "Unix")
{
$UserProf = $env:USERPROFILE
$Delim = ';'
}
else
{
$UserProf = $HOME
$Delim = ':'
}
if (-not $TargetDir)
{
$TargetDir = [array]($env:PSModulePath -split $Delim) | Where-Object { $_.StartsWith($UserProf) } | Select-Object -First 1
if (-not $TargetDir)
{
throw "Unable to find a PSModulePath in your user profile (" + $UserProf + "), PSModulePath: " + $env:PSModulePath
}
}
if (-not (Test-Path $TargetDir))
{
Write-Host "Creating target directory '$TargetDir'"
New-Item -Path $TargetDir -ItemType Container -Force | Out-Null
}
$ModuleName = "safeguard-discovery"
$Module = (Join-Path $PSScriptRoot "src\$ModuleName.psd1")
$ModuleDef = (Invoke-Expression -Command (Get-Content $Module -Raw))
Write-Host "Installing '$ModuleName $($ModuleDef["ModuleVersion"])' to '$TargetDir'"
$ModuleDir = (Join-Path $TargetDir $ModuleName)
if (-not (Test-Path $ModuleDir))
{
Write-Host "Creating module directory '$ModuleDir'"
New-Item -Path $ModuleDir -ItemType Container -Force | Out-Null
}
else
{
Write-Host "Removing module directory '$ModuleDir'"
Remove-Item -Recurse -Force (Join-Path $ModuleDir "*")
}
$VersionDir = (Join-Path $ModuleDir $ModuleDef["ModuleVersion"])
if (-not (Test-Path $VersionDir))
{
Write-Host "Creating version directory '$VersionDir'"
New-Item -Path $VersionDir -ItemType Container -Force | Out-Null
}
$Sources = (Join-Path $PSScriptRoot (Join-Path "src" "*"))
Write-Host "Copying '$Sources' to '$VersionDir'"
Copy-Item -Recurse -Path $Sources -Destination $VersionDir