mirror of
https://github.com/FULU-Foundation/OrcaSlicer-bambulab.git
synced 2026-05-14 06:53:47 -07:00
Initial release
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
param(
|
||||
[string]$OutputTar = "",
|
||||
[string]$BaseImage = "ubuntu:24.04",
|
||||
[switch]$Force
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Get-ScriptDir {
|
||||
if (-not [string]::IsNullOrWhiteSpace($PSScriptRoot)) {
|
||||
return $PSScriptRoot
|
||||
}
|
||||
if (-not [string]::IsNullOrWhiteSpace($PSCommandPath)) {
|
||||
return (Split-Path -Parent $PSCommandPath)
|
||||
}
|
||||
if ($MyInvocation.MyCommand -and -not [string]::IsNullOrWhiteSpace($MyInvocation.MyCommand.Path)) {
|
||||
return (Split-Path -Parent $MyInvocation.MyCommand.Path)
|
||||
}
|
||||
return (Get-Location).Path
|
||||
}
|
||||
|
||||
$scriptDir = Get-ScriptDir
|
||||
if ([string]::IsNullOrWhiteSpace($OutputTar)) {
|
||||
$OutputTar = Join-Path $scriptDir 'windows-wsl2-rootfs.tar'
|
||||
}
|
||||
$OutputTar = [System.IO.Path]::GetFullPath($OutputTar)
|
||||
|
||||
if ((Test-Path $OutputTar) -and -not $Force) {
|
||||
Write-Host "Rootfs already exists: $OutputTar"
|
||||
exit 0
|
||||
}
|
||||
|
||||
$docker = Get-Command docker -ErrorAction SilentlyContinue
|
||||
if (-not $docker) {
|
||||
throw 'docker not found. Install Docker Desktop or set PJARCZAK_WSL_ROOTFS_TAR to an existing rootfs tar.'
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $OutputTar) | Out-Null
|
||||
|
||||
$containerName = "pjarczak-bambu-rootfs-" + [guid]::NewGuid().ToString('N')
|
||||
try {
|
||||
& docker pull --platform linux/amd64 $BaseImage
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "docker pull failed for image: $BaseImage"
|
||||
}
|
||||
|
||||
& docker create --platform linux/amd64 --name $containerName $BaseImage /bin/sh -lc 'exit 0'
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "docker create failed for image: $BaseImage"
|
||||
}
|
||||
|
||||
if (Test-Path $OutputTar) {
|
||||
Remove-Item -Force $OutputTar
|
||||
}
|
||||
|
||||
$exportProcess = Start-Process -FilePath docker -ArgumentList @('export', $containerName, '-o', $OutputTar) -NoNewWindow -Wait -PassThru
|
||||
if ($exportProcess.ExitCode -ne 0) {
|
||||
throw 'docker export failed'
|
||||
}
|
||||
|
||||
if (!(Test-Path $OutputTar)) {
|
||||
throw "rootfs tar was not created: $OutputTar"
|
||||
}
|
||||
|
||||
$size = (Get-Item $OutputTar).Length
|
||||
if ($size -le 0) {
|
||||
throw "rootfs tar is empty: $OutputTar"
|
||||
}
|
||||
|
||||
Write-Host "WSL rootfs created:"
|
||||
Write-Host $OutputTar
|
||||
}
|
||||
finally {
|
||||
& docker rm -f $containerName 2>$null | Out-Null
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
OUTPUT_TAR="${1:-$SCRIPT_DIR/windows-wsl2-rootfs.tar}"
|
||||
BASE_IMAGE="${PJARCZAK_WSL_ROOTFS_IMAGE:-ubuntu:24.04}"
|
||||
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
echo "docker not found. Install Docker or provide a prebuilt windows-wsl2-rootfs.tar." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname -- "$OUTPUT_TAR")"
|
||||
|
||||
CONTAINER_NAME="pjarczak-bambu-rootfs-$(date +%s)-$$"
|
||||
cleanup() {
|
||||
docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
docker pull "$BASE_IMAGE" >/dev/null
|
||||
docker create --name "$CONTAINER_NAME" "$BASE_IMAGE" /bin/sh -lc 'exit 0' >/dev/null
|
||||
|
||||
rm -f "$OUTPUT_TAR"
|
||||
docker export "$CONTAINER_NAME" -o "$OUTPUT_TAR"
|
||||
|
||||
if [[ ! -s "$OUTPUT_TAR" ]]; then
|
||||
echo "failed to create rootfs tar: $OUTPUT_TAR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "WSL rootfs created:"
|
||||
echo " $OUTPUT_TAR"
|
||||
Reference in New Issue
Block a user