-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Windows installer: Use PowerShell to update PATH value to avoid 1024 char truncation #4362
Merged
tstromberg
merged 2 commits into
kubernetes:master
from
blueelvis:bug/2587-path-being-destroyed-when-too-long
May 29, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<# | ||
.DESCRIPTION | ||
This script is used to add/remove the installation path of Minikube in the PATH Environment variable as part of installation/uninstallation of Minikube. | ||
The script assumes that the PATH exists before running. | ||
|
||
.PARAMETER Add | ||
This is a Switch parameter which tells the script to ADD the path supplied to the System's PATH Environment variable. | ||
|
||
.PARAMETER Remove | ||
This is a Switch parameter which tells the script to REMOVE the path supplied from the System's PATH Environment variable. | ||
|
||
.PARAMETER Path | ||
This parameter accepts a string which needs to be added/removed from the System's PATH Environment Variable. | ||
#> | ||
|
||
param( | ||
[cmdletbinding()] | ||
|
||
# This parameter dictates if the path needs to be added | ||
[Parameter(Mandatory=$false,ParameterSetName="EnvironmentVariableAddOperation")] | ||
[switch] | ||
$Add, | ||
|
||
# This parameter dictates if the path needs to be removed | ||
[Parameter(Mandatory=$false,ParameterSetName="EnvironmentVariableRemoveOperation")] | ||
[switch] | ||
$Remove, | ||
|
||
# This parameter tells us the path inside the $PATH Environment Variable for which the operation needs to be performed | ||
[Parameter(Mandatory=$true)] | ||
[string] | ||
$Path | ||
) | ||
|
||
$currentSystemPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine) | ||
|
||
try { | ||
if ($Add) { | ||
Write-Output "Path needs to be added." | ||
Write-Output "Checking if the given path already exists or not" | ||
|
||
if ($currentSystemPath -match [Regex]::Escape($Path)) { | ||
Write-Output "The provided path already exists in the system. Exiting now." | ||
} else { | ||
Write-Output "The given path was not found. Adding it now." | ||
if ($currentSystemPath.EndsWith(";")) { | ||
$newSystemPath = $currentSystemPath + $Path.Trim() + ";" | ||
} else { | ||
$newSystemPath = $currentSystemPath + ";" + $Path.Trim() + ";" | ||
} | ||
[Environment]::SetEnvironmentVariable("Path", $newSystemPath, [EnvironmentVariableTarget]::Machine) | ||
Write-Output "Path has been added successfully." | ||
} | ||
} else { | ||
Write-Output "Path needs to be added." | ||
Write-Output "Checking if the given path already exists or not" | ||
|
||
if ($currentSystemPath -match [Regex]::Escape($Path)) { | ||
Write-Output "The provided path exists in the system. Removing now." | ||
$newSystemPath = $currentSystemPath.Replace(($Path.Trim() + ";"), "") | ||
[Environment]::SetEnvironmentVariable("Path", $newSystemPath, [EnvironmentVariableTarget]::Machine) | ||
} else { | ||
Write-Output "The given path was not found. Exiting now." | ||
} | ||
} | ||
} | ||
catch { | ||
Write-Output "[Error]:: There was an error while execution. Please see the details below. Ensure that the script is running with administrator privileges." | ||
Write-Output $_ | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with this format - but shouldn't .DESCRIPTION be indented the same amount as .PARAMETER?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks to be properly indented in my IDE -