master
ps1 64 lines 2.64 KB
Raw
1 <#
2 .SYNOPSIS
3 Takes in an exported distribution, installs dependencies for testing, cleans unnecessary components, and exports it for later use.
4 .PARAMETER Base
5 Base distribution to use.
6 .PARAMETER OutputTarPath
7 Path to write the test distro .tar to.
8 #>
9
10 [CmdletBinding()]
11 Param ($Base, [string]$Platform)
12
13 $ErrorActionPreference = "Stop"
14 Set-StrictMode -Version Latest
15
16 function Run {
17 [CmdletBinding()]
18 param([scriptblock]$cmd)
19
20 Invoke-Command -ScriptBlock $cmd
21 if ($lastexitcode -ne 0) {
22 throw ("$cmd failed with exit code: " + $lastexitcode)
23 }
24 }
25
26 function RunInDistro {
27 [CmdletBinding()]
28 param([string]$cmd)
29 & cmd /c "wsl.exe -d test_distro -- $cmd"
30 if ($lastexitcode -ne 0) {
31 throw ("wsl.exe -d test_distro -- $cmd failed with exit code: " + $lastexitcode)
32 }
33 }
34
35 if ([string]::IsNullOrEmpty($Platform)) {
36 if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
37 $Platform = "arm64"
38 } else {
39 $Platform = "x64"
40 }
41 }
42
43 $git_version = (git describe --tags).split('-')
44 $version = "$($git_version[0])-$($git_version[1])"
45
46 echo "Building test_distro version: $version for $Platform"
47
48 Run { wsl.exe --install $Base --name test_distro --version 2 --no-launch }
49
50 RunInDistro("apt update")
51 RunInDistro("apt install daemonize libmount-dev genisoimage dosfstools make gcc socat systemd libpam-systemd bind9-dnsutils xz-utils bzip2 -f -y --no-install-recommends")
52 RunInDistro("apt purge cpio isc-dhcp-client isc-dhcp-common nftables rsyslog vim vim-tiny vim-common whiptail xxd init genisoimage tasksel kmod mawk udev cron -y -f --allow-remove-essential")
53 RunInDistro("apt-get autopurge -y")
54 RunInDistro("apt clean")
55 RunInDistro("umount /usr/lib/wsl/drivers")
56 RunInDistro("umount /usr/lib/wsl/lib")
57 RunInDistro("rm -rf /etc/wsl-distribution.conf /etc/wsl.conf /usr/share/doc/* /var/lib/apt/lists/* /var/log/* /var/cache/debconf/* /var/cache/ldconfig/* /usr/lib/wsl /usr/share/{gdb,vim,zsh,man}")
58 RunInDistro('rm -rf -- $(ls /usr/share/locale ^| grep -vE "en|locale.alias")')
59 RunInDistro("rm /usr/lib/systemd/user/{systemd-tmpfiles-setup.service,systemd-tmpfiles-clean.timer,systemd-tmpfiles-clean.service}")
60 RunInDistro("rm /usr/lib/systemd/system/{systemd-tmpfiles-setup-dev.service,systemd-tmpfiles-setup.service,systemd-tmpfiles-clean.timer,systemd-tmpfiles-clean.service} /lib/systemd/system/{kmod-static-nodes.service,kmod.service,sysinit.target.wants/kmod-static-nodes.service}")
61 New-Item -ItemType Directory -Path $Platform -Force
62 Run { wsl.exe --export --format tar.xz test_distro "$Platform\test_distro.tar.xz" }
63
64 & "$PSScriptRoot/../../_deps/nuget.exe" pack Microsoft.WSL.TestDistro.nuspec -Properties version=$version