Compare commits
No commits in common. "6e3ab487200147793b72736b6d78d1c3057341eb" and "a826cfa41aa27eb197ad8bc778c961833637b3d1" have entirely different histories.
6e3ab48720
...
a826cfa41a
9 changed files with 27 additions and 43 deletions
|
@ -11,7 +11,7 @@ import {
|
|||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { cwd } from "node:process";
|
||||
import { execFile } from "./helpers/better-api";
|
||||
import { execFile } from "./helpers.js";
|
||||
|
||||
export class Alpine {
|
||||
dir: string;
|
||||
|
|
|
@ -1,5 +1,22 @@
|
|||
import { promisify } from "node:util";
|
||||
import {
|
||||
execFile as execFileCallback,
|
||||
spawn as spawnCallback,
|
||||
} from "node:child_process";
|
||||
import { access } from "node:fs/promises";
|
||||
import { getuid } from "node:process";
|
||||
import { execFile } from "./better-api";
|
||||
|
||||
export const execFile = promisify(execFileCallback);
|
||||
export const spawn = promisify(spawnCallback);
|
||||
|
||||
export async function canAccess(path: string): Promise<boolean> {
|
||||
try {
|
||||
await access(path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function sudoChown(path: string, owner: string): Promise<void> {
|
||||
await execFile("sudo", ["chown", owner, path]);
|
|
@ -1,18 +0,0 @@
|
|||
import { promisify } from "node:util";
|
||||
import {
|
||||
execFile as execFileCallback,
|
||||
spawn as spawnCallback,
|
||||
} from "node:child_process";
|
||||
import { access } from "node:fs/promises";
|
||||
|
||||
export const execFile = promisify(execFileCallback);
|
||||
export const spawn = promisify(spawnCallback);
|
||||
|
||||
export async function canAccess(path: string): Promise<boolean> {
|
||||
try {
|
||||
await access(path);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
3
index.ts
3
index.ts
|
@ -3,8 +3,7 @@ import { tmpdir } from "node:os";
|
|||
import path from "node:path";
|
||||
import { cwd } from "node:process";
|
||||
import { Alpine } from "./alpine.js";
|
||||
import { execFile } from "./helpers/better-api.js";
|
||||
import { sudoChownToRunningUser } from "./helpers/sudo.js";
|
||||
import { execFile, spawn, sudoChownToRunningUser } from "./helpers.js";
|
||||
import { setupKernel } from "./kernel.js";
|
||||
import { runQemu } from "./qemu.js";
|
||||
import { Runit } from "./runit/index.js";
|
||||
|
|
|
@ -2,8 +2,7 @@ import { constants } from "node:fs";
|
|||
import { copyFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { Alpine } from "./alpine.js";
|
||||
import { canAccess } from "./helpers/better-api.js";
|
||||
import { sudoChownToRunningUser, sudoRm } from "./helpers/sudo.js";
|
||||
import { canAccess, sudoChownToRunningUser, sudoRm } from "./helpers.js";
|
||||
|
||||
export type Kind = "lts" | "virt";
|
||||
export type Kernel = {
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"run": "esbuild --log-level=warning --target=node18 --sourcemap --outdir=build-javascript --outbase=. *.ts **/*.ts && node --enable-source-maps build-javascript/index.js",
|
||||
"tsc:check": "tsc --noEmit"
|
||||
"run": "esbuild --log-level=warning --target=node18 --sourcemap --outdir=build-javascript --outbase=. *.ts **/*.ts && node --enable-source-maps build-javascript/index.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
|
9
qemu.ts
9
qemu.ts
|
@ -1,16 +1,13 @@
|
|||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { execFile } from "./helpers/better-api.js";
|
||||
import { execFile } from "./helpers.js";
|
||||
import { Kernel } from "./kernel.js";
|
||||
|
||||
export async function runQemu(
|
||||
squashfs: string,
|
||||
kernel: Kernel,
|
||||
{ graphic, noShutdown }: { graphic?: boolean; noShutdown?: boolean } = {
|
||||
graphic: true,
|
||||
noShutdown: false,
|
||||
}
|
||||
{ graphic }: { graphic: boolean } = { graphic: true }
|
||||
) {
|
||||
const tmp = await mkdtemp(path.join(tmpdir(), "define-alpine-qemu-"));
|
||||
try {
|
||||
|
@ -31,7 +28,6 @@ export async function runQemu(
|
|||
kernelAppend.push("console=ttyS0");
|
||||
qemuAppend.push("-nographic");
|
||||
}
|
||||
if (noShutdown) qemuAppend.push("-no-shutdown");
|
||||
|
||||
// sudo chown root:$(id -u) -R boot/ && sudo chmod g+rw -R boot/
|
||||
await execFile("qemu-system-x86_64", [
|
||||
|
@ -53,6 +49,7 @@ export async function runQemu(
|
|||
"-append",
|
||||
kernelAppend.join(" "),
|
||||
...qemuAppend,
|
||||
"-no-shutdown",
|
||||
]);
|
||||
// -append "root=/dev/sda rootfstype=squashfs modules=ext4 quiet init=/sbin/runit-init $append" $qemuappend
|
||||
} finally {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { readFile } from "fs/promises";
|
||||
import path from "path";
|
||||
import { Alpine } from "../alpine.js";
|
||||
|
||||
export class Runit {
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"module": "es2022",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"strict": true
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue