Compare commits
5 commits
a826cfa41a
...
6e3ab48720
Author | SHA1 | Date | |
---|---|---|---|
6e3ab48720 | |||
53c1fa831d | |||
4380042db3 | |||
db7ae846f7 | |||
a74af935ac |
9 changed files with 43 additions and 27 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.js";
|
||||
import { execFile } from "./helpers/better-api";
|
||||
|
||||
export class Alpine {
|
||||
dir: string;
|
||||
|
|
18
helpers/better-api.ts
Normal file
18
helpers/better-api.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -1,22 +1,5 @@
|
|||
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";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
import { execFile } from "./better-api";
|
||||
|
||||
export async function sudoChown(path: string, owner: string): Promise<void> {
|
||||
await execFile("sudo", ["chown", owner, path]);
|
3
index.ts
3
index.ts
|
@ -3,7 +3,8 @@ import { tmpdir } from "node:os";
|
|||
import path from "node:path";
|
||||
import { cwd } from "node:process";
|
||||
import { Alpine } from "./alpine.js";
|
||||
import { execFile, spawn, sudoChownToRunningUser } from "./helpers.js";
|
||||
import { execFile } from "./helpers/better-api.js";
|
||||
import { sudoChownToRunningUser } from "./helpers/sudo.js";
|
||||
import { setupKernel } from "./kernel.js";
|
||||
import { runQemu } from "./qemu.js";
|
||||
import { Runit } from "./runit/index.js";
|
||||
|
|
|
@ -2,7 +2,8 @@ import { constants } from "node:fs";
|
|||
import { copyFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { Alpine } from "./alpine.js";
|
||||
import { canAccess, sudoChownToRunningUser, sudoRm } from "./helpers.js";
|
||||
import { canAccess } from "./helpers/better-api.js";
|
||||
import { sudoChownToRunningUser, sudoRm } from "./helpers/sudo.js";
|
||||
|
||||
export type Kind = "lts" | "virt";
|
||||
export type Kernel = {
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
"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"
|
||||
"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"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
|
|
9
qemu.ts
9
qemu.ts
|
@ -1,13 +1,16 @@
|
|||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { execFile } from "./helpers.js";
|
||||
import { execFile } from "./helpers/better-api.js";
|
||||
import { Kernel } from "./kernel.js";
|
||||
|
||||
export async function runQemu(
|
||||
squashfs: string,
|
||||
kernel: Kernel,
|
||||
{ graphic }: { graphic: boolean } = { graphic: true }
|
||||
{ graphic, noShutdown }: { graphic?: boolean; noShutdown?: boolean } = {
|
||||
graphic: true,
|
||||
noShutdown: false,
|
||||
}
|
||||
) {
|
||||
const tmp = await mkdtemp(path.join(tmpdir(), "define-alpine-qemu-"));
|
||||
try {
|
||||
|
@ -28,6 +31,7 @@ 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", [
|
||||
|
@ -49,7 +53,6 @@ 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 "fs/promises";
|
||||
import path from "path";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { Alpine } from "../alpine.js";
|
||||
|
||||
export class Runit {
|
||||
|
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2022",
|
||||
"module": "es2022",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
"strict": true
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue