diff --git a/InstallModuleFromGitHub.psm1 b/InstallModuleFromGitHub.psm1 index 2310fa4..8b33a9e 100644 --- a/InstallModuleFromGitHub.psm1 +++ b/InstallModuleFromGitHub.psm1 @@ -11,18 +11,24 @@ function Install-ModuleFromGitHub { Process { if($PSBoundParameters.ContainsKey("ProjectUri")) { $GitHubRepo = $null - if($ProjectUri.OriginalString.StartsWith("https://github.com")) { + if($ProjectUri.OriginalString.StartsWith("https://github.com") -or $ProjectUri.OriginalString.StartsWith("https://bitbucket.org")) { $GitHubRepo = $ProjectUri.AbsolutePath } else { $name=$ProjectUri.LocalPath.split('/')[-1] - Write-Host -ForegroundColor Red ("Module [{0}]: not installed, it is not hosted on GitHub " -f $name) + Write-Host -ForegroundColor Red ("Module [{0}]: not installed, it is not hosted on GitHub or BitBucket " -f $name) } } if($GitHubRepo) { Write-Verbose ("[$(Get-Date)] Retrieving {0} {1}" -f $GitHubRepo, $Branch) - $url = "https://github.com/{0}/archive/{1}.zip" -f $GitHubRepo, $Branch + if ($ProjectUri.OriginalString.StartsWith("https://github.com")){ + $url = "https://github.com/{0}/archive/{1}.zip" -f $GitHubRepo, $Branch + } + elseif($ProjectUri.OriginalString.StartsWith("https://bitbucket.org")){ + $url = "https://bitbucket.org/{0}/get/{1}.zip" -f $GitHubRepo, $Branch + } + $targetModuleName=$GitHubRepo.split('/')[-1] Write-Debug "targetModuleName: $targetModuleName" @@ -42,8 +48,7 @@ function Install-ModuleFromGitHub { } Expand-Archive -Path $OutFile -DestinationPath $tmpDir -Force - - $unzippedArchive = "$($targetModuleName)-$($Branch)" + $unzippedArchive = (Get-ChildItem $tmpDir| Where-Object {$_.LastWriteTime -gt $(get-date).AddMinutes(-2) -and $_.Name -like "*$targetModuleName*"}).Name Write-Debug "targetModule: $targetModule" if ($IsLinux -or $IsOSX) { @@ -51,7 +56,7 @@ function Install-ModuleFromGitHub { } else { - $dest = "C:\Program Files\WindowsPowerShell\Modules" + $dest = [Environment]::GetFolderPath("MyDocuments")+"\WindowsPowerShell\" } if($DestinationPath) { @@ -67,7 +72,7 @@ function Install-ModuleFromGitHub { $dest = Join-Path -Path $dest -ChildPath $ModuleVersion } - $null = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)/*" $dest -Force + $null = Copy-Item "$(Join-Path -Path $tmpDir -ChildPath $unzippedArchive)/*" $dest -Force -Recurse } } }