Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated some MacOS path issues and added CurrentUser Scope param #22

Merged
merged 4 commits into from
Aug 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions InstallModuleFromGitHub.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function Install-ModuleFromGitHub {
$ProjectUri,
$DestinationPath,
$SSOToken,
$moduleName
$moduleName,
$Scope
)

Process {
Expand Down Expand Up @@ -41,11 +42,11 @@ function Install-ModuleFromGitHub {
if ($SSOToken) {$headers = @{"Authorization" = "token $SSOToken" }}

#enable TLS1.2 encryption
if (-not ($IsLinux -or $IsOSX)) {
if (-not ($IsLinux -or $IsMacOS)) {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
}
Invoke-RestMethod $url -OutFile $OutFile -Headers $headers
if (-not ($IsLinux -or $IsOSX)) {
if (-not ([System.Environment]::OSVersion.Platform -eq "Unix")) {
Unblock-File $OutFile
}

Expand All @@ -57,29 +58,43 @@ function Install-ModuleFromGitHub {
$unzippedArchive = get-childItem "$tmpDir"
Write-Debug "targetModule: $targetModule"

if ($IsLinux -or $IsOSX) {
if ([System.Environment]::OSVersion.Platform -eq "Unix") {
$dest = Join-Path -Path $HOME -ChildPath ".local/share/powershell/Modules"
}

else {
$dest = "C:\Program Files\WindowsPowerShell\Modules"
if ($Scope = "CurrentUser") {
$scopedPath = $HOME
$scopedChildPath = "\Documents\WindowsPowerShell\Modules"
} else {
$scopedPath = $env:ProgramFiles
$scopedChildPath = "\WindowsPowerShell\Modules"
}
$dest = Join-Path -Path $scopedPath -ChildPath $scopedChildPath
}

if($DestinationPath) {
$dest = $DestinationPath
}
$dest = Join-Path -Path $dest -ChildPath $targetModuleName

$psd1 = Get-ChildItem (Join-Path -Path $tmpDir -ChildPath $unzippedArchive) -Include *.psd1 -Recurse
if ([System.Environment]::OSVersion.Platform -eq "Unix") {
$psd1 = Get-ChildItem (Join-Path -Path $unzippedArchive -ChildPath *) -Include *.psd1 -Recurse
} else {
$psd1 = Get-ChildItem (Join-Path -Path $tmpDir -ChildPath $unzippedArchive) -Include *.psd1 -Recurse
}


if($psd1) {
$ModuleVersion=(Get-Content -Raw $psd1.FullName | Invoke-Expression).ModuleVersion
$dest = Join-Path -Path $dest -ChildPath $ModuleVersion
$null = New-Item -ItemType directory -Path $dest -Force
}

$null = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive\*)" $dest -Force -Recurse

if ([System.Environment]::OSVersion.Platform -eq "Unix") {
$null = Copy-Item "$(Join-Path -Path $unzippedArchive -ChildPath *)" $dest -Force -Recurse
} else {
$null = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive\*)" $dest -Force -Recurse
}
}
}
}
Expand Down