Add further functionality to the WSL script
This commit is contained in:
parent
380b70322c
commit
6ab0df4dc8
3 changed files with 101 additions and 47 deletions
scripts/Windows/Scripts
|
@ -1,25 +1,96 @@
|
|||
$null = New-Module {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the name of the WSL distribution used for managing the configuration.
|
||||
#>
|
||||
function Get-DistributionName {
|
||||
return "ValhallaUbuntu";
|
||||
. "$PSScriptRoot/../Scripts/Security.ps1";
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the name of the WSL distribution used for managing the configuration.
|
||||
#>
|
||||
function Get-WslDistributionName {
|
||||
return "ValhallaUbuntu";
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the path to the directory containing the WSL distribution.
|
||||
#>
|
||||
function Get-WslDistributionPath {
|
||||
return "$env:ProgramData/PortValhalla/$(Get-WslDistributionName)";
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the path to the virtual hard disk of the WSL distribution.
|
||||
#>
|
||||
function Get-WslDistributionDisk {
|
||||
return "$(Get-WslDistributionPath)/ext4.vhdx";
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks whether `wsl` is installed properly.
|
||||
#>
|
||||
function Test-Wsl {
|
||||
& { $null = wsl --status; $?; };
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Checks whether any WSL distributions are installed for the current user.
|
||||
#>
|
||||
function Test-WslDistributions {
|
||||
& { $null = wsl -l; $?; };
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs `wsl` on the system.
|
||||
#>
|
||||
function Install-Wsl {
|
||||
wsl --install --no-launch;
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Installs a Ubuntu distribution to a shared directory.
|
||||
#>
|
||||
function Install-WslDistribution {
|
||||
$dir = Get-WslDistributionPath;
|
||||
$root = Split-Path -Parent $dir;
|
||||
|
||||
if (-not (Test-Path $root)) {
|
||||
$null = New-Item -ItemType Directory $root;
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the path to the directory containing the WSL distribution.
|
||||
#>
|
||||
function Get-DistributionPath {
|
||||
return "$env:ProgramData/PortValhalla/$distribution";
|
||||
}
|
||||
Copy-Item -Recurse -Force (Get-AppxPackage "*Ubuntu*").InstallLocation $dir;
|
||||
Set-UserPermissions $dir;
|
||||
& "$dir\ubuntu.exe" install --root;
|
||||
wsl --shutdown;
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Gets the path to the virtual hard disk of the WSL distribution.
|
||||
#>
|
||||
function Get-DistributionDisk {
|
||||
return "$(Get-DistributionPath)/ext4.vhdx";
|
||||
}
|
||||
};
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Uninstalls the managed WSL distribution.
|
||||
#>
|
||||
function Uninstall-WslDistribution {
|
||||
wsl --unregister (Get-WslDistributionName);
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Registers the managed WSL distribution.
|
||||
#>
|
||||
function Register-WslDistribution {
|
||||
wsl --import-in-place (Get-WslDistributionName) (Get-WslDistributionDisk);
|
||||
wsl --set-default (Get-WslDistributionName);
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Unregisters the managed WSL distribution.
|
||||
#>
|
||||
function Unregister-WslDistribution {
|
||||
$wslDisk = Get-WslDistributionDisk;
|
||||
wsl --shutdown;
|
||||
$tempDisk = Rename-Item -Force $wslDisk "ext4_.vhdx" -PassThru;
|
||||
Uninstall-WslDistribution;
|
||||
Move-Item $tempDisk $wslDisk;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue