-
Notifications
You must be signed in to change notification settings - Fork 1
feat(install): uninstall the shell and undo what the installer changed #61
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
Merged
kanushka
merged 3 commits into
feat/install-windows-issue-55
from
feat/uninstall-issue-56
Aug 11, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
a2ac66a
feat(install): uninstall the shell and undo what the installer changed
kanushka 42b0a7a
Merge branch 'feat/install-windows-issue-55' into feat/uninstall-issu…
kanushka 34b2a57
fix(install): never truncate a profile whose block has no end marker
kanushka 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 hidden or 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 contains hidden or 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,122 @@ | ||
| # Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| # | ||
| # WSO2 LLC. licenses this file to you under the Apache License, | ||
| # Version 2.0 (the "License"); you may not use this file except | ||
| # in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| <# | ||
| .SYNOPSIS | ||
| Removes what scripts/install.ps1 added. | ||
|
|
||
| .DESCRIPTION | ||
| Removes the binary, the directory the installer created for it, the per-user PATH | ||
| entry, and the per-user WSO2_HOME variable. It does not remove configuration, | ||
| contexts, or credentials unless -Purge is given: removing a binary is not the | ||
| same decision as abandoning a setup. | ||
|
|
||
| Running it when nothing is installed is not a failure. It reports what it found | ||
| and exits successfully, which is also what makes it usable to clean up after an | ||
| install that failed halfway. | ||
|
|
||
| Nothing here needs administrator rights. | ||
|
|
||
| .PARAMETER Purge | ||
| Also remove configuration, contexts, and credentials. | ||
| #> | ||
| param( | ||
| [switch] $Purge | ||
| ) | ||
|
|
||
| Set-StrictMode -Version Latest | ||
| $ErrorActionPreference = 'Stop' | ||
|
|
||
| $stateRoot = if ($env:WSO2_HOME) { $env:WSO2_HOME } else { Join-Path $HOME '.wso2' } | ||
| $binDir = Join-Path $stateRoot 'bin' | ||
| $removed = $false | ||
|
|
||
| $installed = Join-Path $binDir 'wso2.exe' | ||
| if (Test-Path -LiteralPath $installed) { | ||
| try { | ||
| Remove-Item -LiteralPath $installed -Force | ||
| } catch { | ||
| [Console]::Error.WriteLine("error: could not remove ${installed}: $($_.Exception.Message). Close any running wso2 and try again.") | ||
| exit 1 | ||
| } | ||
| Write-Output "Removed $installed" | ||
| $removed = $true | ||
| } | ||
|
|
||
| # Any staging file an interrupted install left beside the binary. | ||
| Get-ChildItem -LiteralPath $binDir -Filter '.wso2.install.*' -Force -ErrorAction SilentlyContinue | | ||
| ForEach-Object { Remove-Item -LiteralPath $_.FullName -Force -ErrorAction SilentlyContinue } | ||
|
|
||
| # Only if it is empty. A directory holding something this installer did not put | ||
| # there is not this script's to delete. | ||
| if ((Test-Path -LiteralPath $binDir) -and | ||
| -not (Get-ChildItem -LiteralPath $binDir -Force -ErrorAction SilentlyContinue)) { | ||
| Remove-Item -LiteralPath $binDir -Force | ||
| Write-Output "Removed $binDir" | ||
| } | ||
|
|
||
| # The PATH entry, matched the way the installer wrote it: case-insensitively and | ||
| # ignoring a trailing separator, so the entry is found however it was recorded. | ||
| # Every other entry is written back exactly as it was. | ||
| $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') | ||
| if ($userPath) { | ||
| $target = $binDir.TrimEnd('\') | ||
| $kept = @() | ||
| $dropped = 0 | ||
| foreach ($entry in $userPath -split ';') { | ||
| if ($entry.Trim() -and $entry.Trim().TrimEnd('\') -ieq $target) { | ||
| $dropped++ | ||
| } else { | ||
| $kept += $entry | ||
| } | ||
| } | ||
| if ($dropped -gt 0) { | ||
| [Environment]::SetEnvironmentVariable('Path', ($kept -join ';'), 'User') | ||
| Write-Output "Removed $binDir from your user PATH." | ||
| $removed = $true | ||
| } | ||
| } | ||
|
|
||
| # Only when it is this state root. A WSO2_HOME pointing somewhere else was set by | ||
| # someone for a reason, and clearing it would be removing a decision that is not | ||
| # this script's to reverse. | ||
| $userStateRoot = [Environment]::GetEnvironmentVariable('WSO2_HOME', 'User') | ||
| if ($userStateRoot -and $userStateRoot.TrimEnd('\') -ieq $stateRoot.TrimEnd('\')) { | ||
| [Environment]::SetEnvironmentVariable('WSO2_HOME', $null, 'User') | ||
| Write-Output 'Removed the user WSO2_HOME variable.' | ||
| $removed = $true | ||
| } | ||
|
|
||
| if ($Purge) { | ||
| if (Test-Path -LiteralPath $stateRoot) { | ||
| Remove-Item -LiteralPath $stateRoot -Recurse -Force | ||
| Write-Output "Removed $stateRoot, including configuration and credentials." | ||
| $removed = $true | ||
| } | ||
| } elseif (Test-Path -LiteralPath $stateRoot) { | ||
| # Named explicitly rather than left implicit: someone who wanted everything | ||
| # gone needs to know that something is still there and how to remove it. | ||
| Write-Output '' | ||
| Write-Output "Left $stateRoot in place, with your contexts and credentials." | ||
| Write-Output 'Remove it too with: .\uninstall.ps1 -Purge' | ||
| } | ||
|
|
||
| if (-not $removed) { | ||
| Write-Output "Nothing to remove: no wso2 installation was found under $stateRoot." | ||
| } else { | ||
| Write-Output '' | ||
| Write-Output 'Open a new terminal so the PATH change takes effect.' | ||
| } | ||
This file contains hidden or 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,116 @@ | ||
| #!/usr/bin/env bash | ||
| # Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com). | ||
| # | ||
| # WSO2 LLC. licenses this file to you under the Apache License, | ||
| # Version 2.0 (the "License"); you may not use this file except | ||
| # in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| # Removes what scripts/install.sh added on macOS, Linux, and WSL. | ||
| # | ||
| # bash uninstall.sh # remove the binary and the profile block | ||
| # bash uninstall.sh --purge # also remove configuration and credentials | ||
| # | ||
| # It removes the binary, the directory the installer created for it, and the | ||
| # delimited block the installer appended to a shell profile. It does not remove | ||
| # configuration, contexts, or credentials unless asked: removing a binary is not | ||
| # the same decision as abandoning a setup, and silently destroying the second | ||
| # would be the worse default. | ||
| # | ||
| # Running it when nothing is installed is not a failure. It reports what it found | ||
| # and exits successfully, which is also what makes it usable to clean up after an | ||
| # install that failed halfway. | ||
| # | ||
| # The block markers and paths here must match scripts/install.sh exactly. They are | ||
| # repeated rather than shared because each script is fetched and run on its own, | ||
| # so neither can source the other. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| BLOCK_BEGIN='# >>> wso2 cli >>>' | ||
| BLOCK_END='# <<< wso2 cli <<<' | ||
|
|
||
| PURGE=0 | ||
| for argument in "$@"; do | ||
| case "$argument" in | ||
| --purge) PURGE=1 ;; | ||
| -h | --help) | ||
| printf 'Usage: uninstall.sh [--purge]\n\n' | ||
| printf ' --purge Also remove configuration, contexts, and credentials.\n' | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| printf 'error: unknown option: %s\n' "$argument" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| state_root="${WSO2_HOME:-$HOME/.wso2}" | ||
| bin_dir="${state_root}/bin" | ||
| removed=0 | ||
|
|
||
| # The binary and any staging file an interrupted install left beside it. | ||
| if [ -e "${bin_dir}/wso2" ]; then | ||
| rm -f "${bin_dir}/wso2" | ||
| printf 'Removed %s\n' "${bin_dir}/wso2" | ||
| removed=1 | ||
| fi | ||
| rm -f "${bin_dir}"/.wso2.install.* 2>/dev/null || true | ||
|
|
||
| # Only if it is empty. A directory holding something this installer did not put | ||
| # there is not this script's to delete. | ||
| if [ -d "$bin_dir" ] && [ -z "$(ls -A "$bin_dir" 2>/dev/null)" ]; then | ||
| rmdir "$bin_dir" | ||
| printf 'Removed %s\n' "$bin_dir" | ||
| fi | ||
|
kanushka marked this conversation as resolved.
|
||
|
|
||
| # Every profile is checked, not only the one this shell would be wired in: the | ||
| # install may have run under a different shell, and a block left behind would go | ||
| # on putting a directory that no longer exists on PATH. | ||
| for profile in "$HOME/.bashrc" "$HOME/.bash_profile" "$HOME/.zshrc" "$HOME/.zprofile" "$HOME/.profile"; do | ||
| [ -f "$profile" ] || continue | ||
| grep -qF "$BLOCK_BEGIN" "$profile" || continue | ||
|
|
||
| staged="${profile}.wso2-uninstall.$$" | ||
| # Only the lines between the markers go. Everything else is written back | ||
| # byte for byte, through a temporary file beside the profile so an interrupted | ||
| # run cannot truncate it. | ||
| awk -v begin="$BLOCK_BEGIN" -v end="$BLOCK_END" ' | ||
| $0 == begin { inside = 1; next } | ||
| $0 == end { inside = 0; next } | ||
| !inside { print }' "$profile" >"$staged" | ||
| mv "$staged" "$profile" | ||
|
kanushka marked this conversation as resolved.
|
||
| printf 'Removed the wso2 block from %s\n' "$profile" | ||
| removed=1 | ||
| done | ||
|
|
||
| if [ "$PURGE" -eq 1 ]; then | ||
| if [ -d "$state_root" ]; then | ||
| rm -rf "$state_root" | ||
| printf 'Removed %s, including configuration and credentials.\n' "$state_root" | ||
| removed=1 | ||
| fi | ||
| else | ||
| # Named explicitly rather than left implicit: someone who wanted everything | ||
| # gone needs to know that something is still there and how to remove it. | ||
| if [ -d "$state_root" ]; then | ||
| printf '\nLeft %s in place, with your contexts and credentials.\n' "$state_root" | ||
| printf 'Remove it too with: bash uninstall.sh --purge\n' | ||
| fi | ||
| fi | ||
|
|
||
| if [ "$removed" -eq 0 ]; then | ||
| printf 'Nothing to remove: no wso2 installation was found under %s.\n' "$state_root" | ||
| else | ||
| printf '\nOpen a new terminal so the PATH change takes effect.\n' | ||
| fi | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.