Skip to content

Commit

Permalink
Fix argument parsing in wsl-reset binary
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
sirredbeard committed Oct 12, 2023
1 parent 5ce9261 commit 9fdce8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ To run wsl-dist-update as a service, copy wsl-dist-update.exe to a permanent loc

A troubleshooting utility that resets the WSL 2 stack to various degrees.

`wsl-reset --reset` - Shuts down WSL, resets the WSL service, and installs any WSL updates, if available.
`wsl-reset -reset` - Shuts down WSL, resets the WSL service, and installs any WSL updates, if available.

`wsl-reset --hard-reset` - Shuts down WSL, stops the WSL service, uninstalls WSL, and re-installs WSL.
`wsl-reset -hard-reset` - Shuts down WSL, stops the WSL service, uninstalls WSL, and re-installs WSL.

`wsl-reset --destrutive-reset` - Shuts down WSL, restarts the WSL service, **unregisters all WSL distros**, stops the WSL service, uninstalls WSL, and re-installs WSL.
`wsl-reset -destrutive-reset` - Shuts down WSL, restarts the WSL service, **unregisters all WSL distros**, stops the WSL service, uninstalls WSL, and re-installs WSL.

## sysdistrowt

Expand All @@ -51,4 +51,4 @@ Adds the WSL System Distro (CBL-Mariner) to the Windows Terminal and/or Windows

## build-wslinternals

Builds wslinternals PowerShell scripts to .exe files using ps2exe. Requires PowerShell 5.
Builds wslinternals PowerShell scripts to .exe files using ps2exe. Must be run as Administrator on PowerShell 7 or on PowerShell 5.
23 changes: 10 additions & 13 deletions wsl-reset.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
param (
[switch]$reset,
[switch]$hardReset,
[switch]$destructiveReset
)

if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Error "This script must be run as an administrator."
Exit 1
}


if (-not $args) {
Write-Error "This script must be run with either --reset, --hard-reset, or --destructive-reset."
Exit 1
}


$arg = $args[0]
switch ($arg) {
"--reset" {
switch ($true) {
$reset {
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null
Restart-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue
if ($LASTEXITCODE -ne 0) {
Expand All @@ -22,7 +19,7 @@ switch ($arg) {
wsl.exe --update > $null
Write-Host "WSL has been shutdown, Windows service restarted, and updated, if applicable."
}
"--hard-reset" {
$hardReset {
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null
Stop-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue
if ($LASTEXITCODE -ne 0) {
Expand All @@ -34,7 +31,7 @@ switch ($arg) {
wsl.exe --install --no-launch --no-distribution
Write-Host "WSL has been shutdown and re-installed."
}
"--destructive-reset" {
$destructiveReset {
wsl.exe --shutdown -ErrorAction SilentlyContinue 2>$null
Restart-Service "Windows Subsystem for Linux" -Force -ErrorAction SilentlyContinue
if ($LASTEXITCODE -ne 0) {
Expand All @@ -55,7 +52,7 @@ switch ($arg) {
Write-Host "WSL has been shutdown, all distros unregistered, and WSL has been re-installed."
}
default {
Write-Error "Invalid argument. This script must be run with either --reset, --hard-reset, or --destructive-reset."
Write-Error "This script must be run with either --reset, --hard-reset, or --destructive-reset."
Exit 1
}
}

0 comments on commit 9fdce8a

Please sign in to comment.