Skip to content

Commit 1f03b27

Browse files
authored
fix installers not updating system path (#622)
* fix msi installer not updating system path * modify install script to add binary path to system path * debug appveyor * add debug message to add-path and update appveyor to be compatible with changes * fix appveyorhelper.psm1 after accidentally removing call to uninstall * fix typo * use PS drive to modify PATH * rename Add-Path to Add-MachinePath in export list
1 parent 13a249a commit 1f03b27

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

contrib/win32/install/product.wxs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
<MajorUpgrade Schedule="afterInstallInitialize" DowngradeErrorMessage="A newer version of !(bind.property.ProductName) is already installed." />
2424
<Condition Message="OpenSSH is supported only on Windows 7 and newer."><![CDATA[VersionNT >= 601]]></Condition>
2525

26+
<!-- assume user wants path to be updated when client binaries are installed, can be overridden during install with ADD_PATH=0 -->
27+
<Property Id="ADD_PATH" Value="1" />
28+
2629
<Feature Id="Client" AllowAdvertise="no">
2730
<ComponentGroupRef Id="Client" />
2831
</Feature>

contrib/win32/openssh/AppveyorHelper.psm1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,12 @@ function Install-OpenSSH
171171

172172
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
173173
$newMachineEnvironmentPath = $machinePath
174-
if (-not ($machinePath.ToLower().Contains($OpenSSHDir.ToLower())))
174+
if (-not $machinePath.ToLower().Contains("$OpenSSHDir;".ToLower()))
175175
{
176176
$newMachineEnvironmentPath = "$OpenSSHDir;$newMachineEnvironmentPath"
177+
}
178+
if (-not $env:Path.ToLower().Contains("$OpenSSHDir;".ToLower()))
179+
{
177180
$env:Path = "$OpenSSHDir;$env:Path"
178181
}
179182
# Update machine environment path

contrib/win32/openssh/OpenSSHUtils.psm1

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,4 +829,25 @@ function Enable-Privilege {
829829
$type[0]::EnablePrivilege($Privilege, $Disable)
830830
}
831831

832-
Export-ModuleMember -Function Repair-FilePermission, Repair-SshdConfigPermission, Repair-SshdHostKeyPermission, Repair-AuthorizedKeyPermission, Repair-UserKeyPermission, Repair-UserSshConfigPermission, Enable-Privilege, Get-UserAccount, Get-UserSID, Repair-AdministratorsAuthorizedKeysPermission, Repair-ModuliFilePermission, Repair-SSHFolderPermission, Repair-SSHFolderFilePermission, Repair-SSHFolderPrivateKeyPermission
832+
Function Add-MachinePath {
833+
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="High")]
834+
param
835+
(
836+
[parameter(Mandatory=$true)]
837+
[string]$FilePath
838+
)
839+
840+
if (Test-Path $FilePath) {
841+
$machinePath = (Get-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path
842+
if (-not $machinePath.ToLower().Contains("$FilePath;".ToLower()))
843+
{
844+
$newPath = $FilePath + ; + $machinePath
845+
Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH –Value $newPath
846+
if ((Get-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).Path -eq $newPath) {
847+
Write-Host "Updated Machine PATH to include OpenSSH directory, restart/re-login required to take effect globally" -ForegroundColor Yellow
848+
}
849+
}
850+
}
851+
}
852+
853+
Export-ModuleMember -Function Repair-FilePermission, Repair-SshdConfigPermission, Repair-SshdHostKeyPermission, Repair-AuthorizedKeyPermission, Repair-UserKeyPermission, Repair-UserSshConfigPermission, Enable-Privilege, Get-UserAccount, Get-UserSID, Repair-AdministratorsAuthorizedKeysPermission, Repair-ModuliFilePermission, Repair-SSHFolderPermission, Repair-SSHFolderFilePermission, Repair-SSHFolderPrivateKeyPermission, Add-MachinePath

contrib/win32/openssh/install-sshd.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# @manojampalam - removed ntrights.exe dependency
44
# @bingbing8 - removed secedit.exe dependency
55
# @tessgauthier - added permissions check for %programData%/ssh
6+
# @tessgauthier - added update to system path for scp/sftp discoverability
67

78
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="High")]
89
param ()
@@ -126,3 +127,6 @@ New-Service -Name sshd -DisplayName "OpenSSH SSH Server" -BinaryPathName `"$sshd
126127
sc.exe privs sshd SeAssignPrimaryTokenPrivilege/SeTcbPrivilege/SeBackupPrivilege/SeRestorePrivilege/SeImpersonatePrivilege
127128

128129
Write-Host -ForegroundColor Green "sshd and ssh-agent services successfully installed"
130+
131+
# add folder to system PATH
132+
Add-MachinePath -FilePath $scriptdir @psBoundParameters

0 commit comments

Comments
 (0)