[Windows] Add shell symlinks (#2395)

* add shell symlinks

* fix paths

* add a wrapper

* fix target output

* fix tests
This commit is contained in:
Aleksandr Chebotov
2021-01-15 13:42:37 +03:00
committed by GitHub
parent da495ea119
commit 68e9c68855
7 changed files with 57 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
# create user profile at the first launch
$null = cmd /c "C:\msys64\usr\bin\bash.exe -leo pipefail -c 'echo $SHELL' 2>&1"

View File

@@ -0,0 +1,23 @@
# Create shells folder
$shellPath = "C:\shells"
New-Item -Path $shellPath -ItemType Directory | Out-Null
# add a wrapper for C:\msys64\usr\bin\bash.exe
@'
@echo off
setlocal
IF NOT DEFINED MSYS2_PATH_TYPE set MSYS2_PATH_TYPE=strict
IF NOT DEFINED MSYSTEM set MSYSTEM=mingw64
set CHERE_INVOKING=1
C:\msys64\usr\bin\bash.exe -leo pipefail %*
'@ | Out-File -FilePath "$shellPath\msys2bash.cmd"
# gitbash <--> C:\Program Files\Git\bin\bash.exe
New-Item -ItemType SymbolicLink -Path "$shellPath\gitbash.exe" -Target "$env:ProgramFiles\Git\bin\bash.exe" | Out-Null
# WSL is available on Windows Server 2019
if (Test-IsWin19)
{
# wslbash <--> C:\Windows\System32\bash.exe
New-Item -ItemType SymbolicLink -Path "$shellPath\wslbash.exe" -Target "$env:SystemRoot\System32\bash.exe" | Out-Null
}

View File

@@ -304,6 +304,17 @@ function Get-CachedDockerImagesTableData {
}
}
function Get-ShellTarget {
$shells = Get-ChildItem C:\shells -File | Select-Object Name, @{n="Target";e={
if ($_.Name -eq "msys2bash.cmd") {
"C:\msys64\usr\bin\bash.exe"
} else {
@($_.Target)[0]
}
}} | Sort-Object Name
$shells | New-MDTable -Columns ([ordered]@{Name = "left"; Target = "left";})
}
function Get-PacmanVersion {
$msys2BinDir = "C:\msys64\usr\bin"
$pacmanPath = Join-Path $msys2BinDir "pacman.exe"

View File

@@ -142,6 +142,10 @@ $markdown += New-MDList -Style Unordered -Lines @(
(Get-SeleniumWebDriverVersion -Driver "iexplorer")
)
$markdown += New-MDHeader "Shells" -Level 3
$markdown += Get-ShellTarget
$markdown += New-MDNewLine
$markdown += New-MDHeader "MSYS2" -Level 3
$markdown += Get-PacmanVersion
$markdown += New-MDNewLine

View File

@@ -0,0 +1,13 @@
Describe "Shell" {
$shellTestCases = @(
@{Name = "C:\shells\gitbash.exe"; Target = "$env:ProgramFiles\Git\bin\bash.exe"},
@{Name = "C:\shells\msys2bash.cmd"; Target = $null}
)
if (Test-IsWin19) {
$shellTestCases += @{Name = "C:\shells\wslbash.exe"; Target = "$env:SystemRoot\System32\bash.exe"}
}
It "<Name> target to <Target>" -TestCases $shellTestCases {
(Get-Item $Name).Target | Should -BeExactly $Target
}
}

View File

@@ -330,7 +330,8 @@
"type": "powershell",
"scripts": [
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1",
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1"
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1",
"{{ template_dir }}/scripts/Installers/Configure-Shell.ps1"
],
"elevated_user": "{{user `install_user`}}",
"elevated_password": "{{user `install_password`}}"

View File

@@ -323,7 +323,8 @@
"type": "powershell",
"scripts": [
"{{ template_dir }}/scripts/Installers/Install-WindowsUpdates.ps1",
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1"
"{{ template_dir }}/scripts/Installers/Configure-DynamicPort.ps1",
"{{ template_dir }}/scripts/Installers/Configure-Shell.ps1"
],
"elevated_user": "{{user `install_user`}}",
"elevated_password": "{{user `install_password`}}"