From 477e3fc1d477acd3ef0573eb57dc88309febe5f5 Mon Sep 17 00:00:00 2001 From: Hayden Barnes Date: Sat, 3 Jun 2023 09:38:34 -0400 Subject: [PATCH 1/2] docker-desktop fixes --- list-wsl.ps1 | 76 +++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/list-wsl.ps1 b/list-wsl.ps1 index cad8d02..0c1a609 100644 --- a/list-wsl.ps1 +++ b/list-wsl.ps1 @@ -1,47 +1,45 @@ $defaultGuid = (Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss").DefaultDistribution $wslDistributions = Get-ChildItem -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss" | ForEach-Object { - $distribution = @{ - Name = "" - "Linux Distro" = "" - "Distro Version" = "" - systemd = "" - "Default User" = "" - State = "" - WSL = "" - } - + $distribution = @{} $distribution["Name"] = $_.GetValue("DistributionName") - $osRelease = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/os-release" - if ($osRelease) { - $distribution["Linux Distro"] = ($osRelease | Where-Object { $_ -like "PRETTY_NAME=*" }).Split("=")[1].Replace('"', '') - $distribution["Distro Version"] = ($osRelease | Where-Object { $_ -like "VERSION=*" }).Split("=")[1].Replace('"', '') - } - - $wslConf = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/wsl.conf" - if ($wslConf) { - $distribution["systemd"] = ($wslConf | Where-Object { $_ -like "systemd=true" }).Count -gt 0 - } - - $distribution["DefaultUid"] = $_.GetValue("DefaultUid") - - $username = Invoke-Command -ScriptBlock { wsl.exe -d $($distribution["Name"]) -- id -un -- $args[0] } -ArgumentList $distribution["DefaultUid"] -ErrorAction SilentlyContinue - if ($username) { - $distribution["Default User"] = $username - } - - $distribution["State"] = $_.GetValue("State") - switch ($distribution["State"]) { - 0x1 { $distribution["State"] = "Installed" } - 0x3 { $distribution["State"] = "Installing" } - 0x4 { $distribution["State"] = "Uninstalling" } - } - - $distribution["WSL"] = $_.GetValue("Version") - - if ($defaultGuid -eq $_.PSChildName) { - $distribution["Name"] += "*" + if ($distribution["Name"] -eq "docker-desktop") { $distribution["Linux Distro"] = "Docker Desktop"; $distribution["State"] = "Installed" } + if ($distribution["Name"] -eq "docker-desktop-data") { $distribution["Linux Distro"] = "Docker Desktop Data"; $distribution["State"] = "Installed" } + + if ($distribution["Name"] -ne "docker-desktop" -and $distribution["Name"] -ne "docker-desktop-data" -and $distribution["Name"] -ne "docker-desktop-runtime") { + $osRelease = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/os-release" + if ($osRelease) { + $distribution["Linux Distro"] = ($osRelease | Where-Object { $_ -like "PRETTY_NAME=*" }).Split("=")[1].Replace('"', '') + $distribution["Distro Version"] = ($osRelease | Where-Object { $_ -like "VERSION=*" }).Split("=")[1].Replace('"', '') + } + + $wslConf = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/wsl.conf" + if ($wslConf -and $wslConf.Contains("systemd=true")) { + $distribution["systemd"] = "Enabled" + } else { + $distribution["systemd"] = "Disabled" + } + + $distribution["DefaultUid"] = $_.GetValue("DefaultUid") + + $username = Invoke-Command -ScriptBlock { wsl.exe -d $($distribution["Name"]) -- id -un -- $args[0] } -ArgumentList $distribution["DefaultUid"] -ErrorAction SilentlyContinue + if ($username) { + $distribution["Default User"] = $username + } + + $distribution["State"] = $_.GetValue("State") + switch ($distribution["State"]) { + 0x1 { $distribution["State"] = "Installed" } + 0x3 { $distribution["State"] = "Installing" } + 0x4 { $distribution["State"] = "Uninstalling" } + } + + $distribution["WSL"] = $_.GetValue("Version") + + if ($defaultGuid -eq $_.PSChildName) { + $distribution["Name"] += "*" + } } New-Object -TypeName PSObject -Property $distribution From 8f1b53cb240a531f2ed8c821171bf800b7a9ac8d Mon Sep 17 00:00:00 2001 From: Hayden Barnes Date: Sat, 3 Jun 2023 09:49:59 -0400 Subject: [PATCH 2/2] Fixes for openSUSE Tumbleweed --- list-wsl.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/list-wsl.ps1 b/list-wsl.ps1 index 0c1a609..63fbb2b 100644 --- a/list-wsl.ps1 +++ b/list-wsl.ps1 @@ -4,17 +4,18 @@ $wslDistributions = Get-ChildItem -Path "HKCU:\SOFTWARE\Microsoft\Windows\Curren $distribution = @{} $distribution["Name"] = $_.GetValue("DistributionName") - if ($distribution["Name"] -eq "docker-desktop") { $distribution["Linux Distro"] = "Docker Desktop"; $distribution["State"] = "Installed" } - if ($distribution["Name"] -eq "docker-desktop-data") { $distribution["Linux Distro"] = "Docker Desktop Data"; $distribution["State"] = "Installed" } + if ($distribution["Name"] -eq "docker-desktop") { $distribution["Linux Distro"] = "Docker Desktop"; $distribution["State"] = "Installed"; $distribution["WSL"] = 2; $distribution["systemd"] = "Disabled"; $distribution["Default User"] = ""; $distribution["Distro Version"] = "" } + if ($distribution["Name"] -eq "docker-desktop-data") { $distribution["Linux Distro"] = "Docker Desktop Data"; $distribution["State"] = "Installed"; $distribution["WSL"] = 2; $distribution["systemd"] = "Disabled"; $distribution["Default User"] = ""; $distribution["Distro Version"] = "" } + if ($distribution["Name"] -eq "docker-desktop-runtime") { $distribution["Linux Distro"] = "Docker Desktop Runtime"; $distribution["State"] = "Installed"; $distribution["WSL"] = 2; $distribution["systemd"] = "Disabled"; $distribution["Default User"] = ""; $distribution["Distro Version"] = "" } if ($distribution["Name"] -ne "docker-desktop" -and $distribution["Name"] -ne "docker-desktop-data" -and $distribution["Name"] -ne "docker-desktop-runtime") { $osRelease = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/os-release" if ($osRelease) { $distribution["Linux Distro"] = ($osRelease | Where-Object { $_ -like "PRETTY_NAME=*" }).Split("=")[1].Replace('"', '') - $distribution["Distro Version"] = ($osRelease | Where-Object { $_ -like "VERSION=*" }).Split("=")[1].Replace('"', '') + $distribution["Distro Version"] = ($osRelease | Where-Object { $_ -like "*VERSION=*" }).Split("=")[1].Replace('"', '') } - $wslConf = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/wsl.conf" + $wslConf = Invoke-Expression "wsl.exe -d $($distribution["Name"]) cat /etc/wsl.conf 2> `$null" if ($wslConf -and $wslConf.Contains("systemd=true")) { $distribution["systemd"] = "Enabled" } else {