From 7584c7b8793620167c46cd587f35c46520b5f26e Mon Sep 17 00:00:00 2001 From: Andy Mishechkin <57713077+andy-mishechkin@users.noreply.github.com> Date: Mon, 16 Mar 2020 10:52:13 +0300 Subject: [PATCH] Add Hub installation (#529) * Hub installation has been added * Checking and documentation updating has been created * Canges in hub version detection code * GIT_LFS_PATH has been removed from hub version detection * Copy-Past has been returned * Refactoring for separate command checking --- images/linux/scripts/installers/git.sh | 10 +++ images/win/scripts/Installers/Install-Git.ps1 | 1 + .../win/scripts/Installers/Validate-Git.ps1 | 77 +++++++++++-------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/images/linux/scripts/installers/git.sh b/images/linux/scripts/installers/git.sh index 026e73cd9..1d8e58a14 100644 --- a/images/linux/scripts/installers/git.sh +++ b/images/linux/scripts/installers/git.sh @@ -35,3 +35,13 @@ echo "Lastly, document the installed versions" DocumentInstalledItem "Git ($(git --version 2>&1 | cut -d ' ' -f 3))" # git-lfs/2.6.1 (GitHub; linux amd64; go 1.11.1) DocumentInstalledItem "Git Large File Storage (LFS) ($(git-lfs --version 2>&1 | cut -d ' ' -f 1 | cut -d '/' -f 2))" + +#Install hub +snap install hub --classic +if command -v hub; then + echo "hub CLI was installed successfully" + DocumentInstalledItem "Hub CLI ($(hub --version | grep "hub version" | cut -d ' ' -f 3))" +else + echo "[!] Hub CLI was not installed" + exit 1 +fi diff --git a/images/win/scripts/Installers/Install-Git.ps1 b/images/win/scripts/Installers/Install-Git.ps1 index a67d7c998..24efc5bd0 100644 --- a/images/win/scripts/Installers/Install-Git.ps1 +++ b/images/win/scripts/Installers/Install-Git.ps1 @@ -8,6 +8,7 @@ Import-Module -Name ImageHelpers # Install the latest version of Git which is bundled with Git LFS. # See https://chocolatey.org/packages/git choco install git -y --package-parameters="/GitAndUnixToolsOnPath /WindowsTerminal /NoShellIntegration" +choco install hub # Disable GCM machine-wide [Environment]::SetEnvironmentVariable("GCM_INTERACTIVE", "Never", [System.EnvironmentVariableTarget]::Machine) diff --git a/images/win/scripts/Installers/Validate-Git.ps1 b/images/win/scripts/Installers/Validate-Git.ps1 index 6f2bb33f1..1927a6ad9 100644 --- a/images/win/scripts/Installers/Validate-Git.ps1 +++ b/images/win/scripts/Installers/Validate-Git.ps1 @@ -2,48 +2,61 @@ ## File: Validate-Git.ps1 ## Desc: Validate Git for Windows ################################################################################ - -if((Get-Command -Name 'git') -and (Get-Command -Name 'bash') -and (Get-Command -Name 'awk') -and (Get-Command -Name 'git-lfs')) -{ - Write-Host "$(git version) on path" - Write-Host "$(git-lfs version) on path" +function Test-CommandName { + param( + [parameter(Mandatory)][string] $CommandName + ) + Write-Host "Checking the [$CommandName]" + if(-not (Get-Command $CommandName -ErrorAction "Continue")) { + Write-Host "[!] $CommandName is not found" + exit 1 + } } -else -{ - Write-Host "git or git-lfs are not on path." - exit 1 +function Test-Command { + param( + [parameter(Mandatory)][string] $CommandName, + [parameter(Mandatory)][string] $CommandDescription, + [parameter(Mandatory)][string] $VersionCmd, + [parameter(Mandatory)][string] $regexVersion, + [parameter(Mandatory)][string] $DescriptionMarkdown + ) + Test-CommandName -CommandName $CommandName + + $strVersion = Invoke-Expression $VersionCmd + Write-Host "$strVersion on path" + if($strVersion -match $regexVersion) { + $Version = $Matches.version + } + else { + Write-Host "[!] $CommandName version detection failed" + exit 1 + } + # Adding description of the software to Markdown + $DescriptionMarkdown = $DescriptionMarkdown -f $Version + Add-SoftwareDetailsToMarkdown -SoftwareName $CommandDescription -DescriptionMarkdown $DescriptionMarkdown } +Test-CommandName -CommandName 'bash' +Test-CommandName -CommandName 'awk' -if( $(git version) -match 'git version (?.*).win.*' ) -{ - $gitVersion = $Matches.version -} - -if( $(git-lfs version) -match 'git-lfs\/(?.*) \(Git.*' ) -{ - $gitLfsVersion = $Matches.version -} - -# Adding description of the software to Markdown -$SoftwareName = "Git" - -$Description = @" -_Version:_ $gitVersion
+$GitDescription = @" +_Version:_ {0}
_Environment:_ * PATH: contains location of git.exe "@ +Test-Command -CommandName 'git' -CommandDescription 'Git' -VersionCmd "git version" -regexVersion 'git version (?.*).win.*' -DescriptionMarkdown $GitDescription -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description - -# Adding description of the software to Markdown -$SoftwareName = "Git Large File Storage (LFS)" - -$Description = @" -_Version:_ $gitLfsVersion
+$GitLfsDescription = @" +_Version:_ {0}
_Environment:_ * PATH: contains location of git-lfs.exe * GIT_LFS_PATH: location of git-lfs.exe "@ +Test-Command -CommandName 'git-lfs' -CommandDescription 'Git Large File Storage (LFS)' -VersionCmd "git-lfs version" -regexVersion 'git-lfs\/(?.*) \(Git.*' -DescriptionMarkdown $GitLfsDescription -Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description +$HubCliDescription = @" +_Version:_ {0}
+_Environment:_ +* PATH: contains location of hub.exe +"@ +Test-Command -CommandName 'hub' -CommandDescription 'Hub CLI' -VersionCmd "hub version | Select-String 'hub version'" -regexVersion 'hub version (?.*)' -DescriptionMarkdown $HubCliDescription \ No newline at end of file