Skip to content

Commit 499411e

Browse files
authored
Added Debian installation (#5)
1 parent c4683ab commit 499411e

3 files changed

Lines changed: 93 additions & 8 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
function WSL-Debian-Install
2+
{
3+
Param(
4+
[switch]$Interactive = $false,
5+
[Parameter(Mandatory = $true)] [String]$DistroAlias,
6+
[String]$InstallPath
7+
)
8+
try {
9+
$wsl = Ensure-WSL
10+
}
11+
catch {
12+
Write-ColorOutput red "[ERROR] Elevated access needed to check WSL settings"
13+
throw "Elevated access required"
14+
}
15+
16+
if (-not $wsl) {
17+
Write-ColorOutput red "[ERROR] WSL not installed"
18+
throw "WSL not installed"
19+
}
20+
21+
if (-not($DistroAlias -match '^[^\s\\/]*$')) {
22+
Write-ColorOutput red "[ERROR] Provided DistroAlias contains whitespace or slash/backslash characters"
23+
throw "Incorrect DistroAlias"
24+
}
25+
26+
if (-not($PSBoundParameters.ContainsKey('InstallPath'))) {
27+
$InstallPath = "$(Get-Location)\install"
28+
New-Item -ItemType directory -Path $InstallPath -ErrorAction SilentlyContinue | Out-Null
29+
}
30+
31+
if ($PSBoundParameters.ContainsKey('InstallPath')) {
32+
if (Test-Path -Path $InstallPath) {
33+
if ( (Get-Item $InstallPath) -isnot [System.IO.DirectoryInfo]) {
34+
Write-ColorOutput red "[ERROR] Provided InstallPath is not a directory"
35+
throw "Incorrect InstallPath"
36+
}
37+
}
38+
if (-not(Test-Path -Path $InstallPath)) {
39+
Write-ColorOutput red "[ERROR] Provided InstallPath is does not exist"
40+
throw "Incorrect InstallPath"
41+
}
42+
}
43+
44+
# Get which debian version
45+
$debian_vs = "bookworm","bullseye","buster"
46+
if ($Interactive) {
47+
$version = Get-Select -Prompt "[OPER] Select which Debian distribution you'd like to install:" -Options $debian_vs
48+
}
49+
# Get latest
50+
if (-not $Interactive) {
51+
$version = "buster"
52+
}
53+
54+
$debian_vs = "full","slim"
55+
if ($Interactive) {
56+
$subselected = Get-Select -Prompt "[OPER] Full or slim (reduced size, e.g. man pages):" -Options $debian_vs
57+
}
58+
# Get latest
59+
if (-not $Interactive) {
60+
$subselected = "full"
61+
}
62+
63+
if ($subselected -eq "full") {
64+
$subversion = ""
65+
}
66+
if (-not ($subselected -eq "full")) {
67+
$subversion = "/slim"
68+
}
69+
70+
New-Item -ItemType directory -Path "$(Get-Location)\tmp" -ErrorAction SilentlyContinue | Out-Null
71+
$ProgressPreference = 'SilentlyContinue'
72+
Invoke-WebRequest -Uri https://github.com/debuerreotype/docker-debian-artifacts/raw/dist-amd64/$version$subversion/rootfs.tar.xz -OutFile "$(Get-Location)\tmp\$($DistroAlias).tar.xz"
73+
74+
wsl --import $DistroAlias $InstallPath "$(Get-Location)\tmp\$($DistroAlias).tar.xz"
75+
Remove-Item -Path "$(Get-Location)\tmp" -Recurse | Out-Null
76+
77+
wsl -d $DistroAlias -u root -e sh -c 'apt-get update && apt-get upgrade -y'
78+
79+
return $true
80+
}

WSLTools/WSLTools.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'WSLTools.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.2.1'
15+
ModuleVersion = '1.3.0'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = 'Desktop', 'Core'
@@ -69,7 +69,7 @@ PowerShellVersion = '5.1'
6969
# NestedModules = @()
7070

7171
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
FunctionsToExport = 'Ensure-HyperV', 'Ensure-NewPS', 'Ensure-WSL', 'Run-AfterReboot', 'WSL-Alpine-Install', 'WSL-Ubuntu-Install', "Get-Select"
72+
FunctionsToExport = 'Ensure-HyperV', 'Ensure-NewPS', 'Ensure-WSL', 'Run-AfterReboot', 'WSL-Alpine-Install', 'WSL-Ubuntu-Install', 'WSL-Debian-Install', "Get-Select"
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7575
CmdletsToExport = @()
@@ -95,7 +95,7 @@ PrivateData = @{
9595
PSData = @{
9696

9797
# Tags applied to this module. These help with module discovery in online galleries.
98-
Tags = "WSL", "HyperV", "Linux", "PowerShell", "Automation", "WSL2", "Ubuntu", "Alpine"
98+
Tags = "WSL", "HyperV", "Linux", "PowerShell", "Automation", "WSL2", "Ubuntu", "Alpine", "Debian"
9999

100100
# A URL to the license for this module.
101101
LicenseUri = 'https://github.com/rgryta/PowerShell-WSLTools/blob/main/LICENSE'

example.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
if (-not (Get-Module -ListAvailable -Name WSLTools)) {
2-
Install-Module -Name WSLTools
3-
Import-Module WSLTools -WarningAction SilentlyContinue
2+
Install-Module -Name WSLTools
43
}
5-
6-
Ensure-HyperV -Install
7-
Ensure-WSL -Install
4+
Import-Module WSLTools -WarningAction SilentlyContinue
5+
try {
6+
Ensure-HyperV -Install
7+
Ensure-WSL -Install
8+
Write-Host "Reboot required"
9+
}
10+
catch {
11+
Write-Host "Permissions need to be elevated or HyperV is disabled in BIOS"
12+
}

0 commit comments

Comments
 (0)