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 { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { cwd } from "node:process";
|
import { cwd } from "node:process";
|
||||||
import { execFile } from "./helpers/better-api";
|
import { execFile } from "./helpers.js";
|
||||||
|
|
||||||
export class Alpine {
|
export class Alpine {
|
||||||
dir: string;
|
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 { 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> {
|
export async function sudoChown(path: string, owner: string): Promise<void> {
|
||||||
await execFile("sudo", ["chown", owner, path]);
|
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 path from "node:path";
|
||||||
import { cwd } from "node:process";
|
import { cwd } from "node:process";
|
||||||
import { Alpine } from "./alpine.js";
|
import { Alpine } from "./alpine.js";
|
||||||
import { execFile } from "./helpers/better-api.js";
|
import { execFile, spawn, sudoChownToRunningUser } from "./helpers.js";
|
||||||
import { sudoChownToRunningUser } from "./helpers/sudo.js";
|
|
||||||
import { setupKernel } from "./kernel.js";
|
import { setupKernel } from "./kernel.js";
|
||||||
import { runQemu } from "./qemu.js";
|
import { runQemu } from "./qemu.js";
|
||||||
import { Runit } from "./runit/index.js";
|
import { Runit } from "./runit/index.js";
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { constants } from "node:fs";
|
||||||
import { copyFile } from "node:fs/promises";
|
import { copyFile } from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { Alpine } from "./alpine.js";
|
import { Alpine } from "./alpine.js";
|
||||||
import { canAccess } from "./helpers/better-api.js";
|
import { canAccess, sudoChownToRunningUser, sudoRm } from "./helpers.js";
|
||||||
import { sudoChownToRunningUser, sudoRm } from "./helpers/sudo.js";
|
|
||||||
|
|
||||||
export type Kind = "lts" | "virt";
|
export type Kind = "lts" | "virt";
|
||||||
export type Kernel = {
|
export type Kernel = {
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"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": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
|
|
9
qemu.ts
9
qemu.ts
|
@ -1,16 +1,13 @@
|
||||||
import { mkdtemp, rm } from "node:fs/promises";
|
import { mkdtemp, rm } from "node:fs/promises";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { execFile } from "./helpers/better-api.js";
|
import { execFile } from "./helpers.js";
|
||||||
import { Kernel } from "./kernel.js";
|
import { Kernel } from "./kernel.js";
|
||||||
|
|
||||||
export async function runQemu(
|
export async function runQemu(
|
||||||
squashfs: string,
|
squashfs: string,
|
||||||
kernel: Kernel,
|
kernel: Kernel,
|
||||||
{ graphic, noShutdown }: { graphic?: boolean; noShutdown?: boolean } = {
|
{ graphic }: { graphic: boolean } = { graphic: true }
|
||||||
graphic: true,
|
|
||||||
noShutdown: false,
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
const tmp = await mkdtemp(path.join(tmpdir(), "define-alpine-qemu-"));
|
const tmp = await mkdtemp(path.join(tmpdir(), "define-alpine-qemu-"));
|
||||||
try {
|
try {
|
||||||
|
@ -31,7 +28,6 @@ export async function runQemu(
|
||||||
kernelAppend.push("console=ttyS0");
|
kernelAppend.push("console=ttyS0");
|
||||||
qemuAppend.push("-nographic");
|
qemuAppend.push("-nographic");
|
||||||
}
|
}
|
||||||
if (noShutdown) qemuAppend.push("-no-shutdown");
|
|
||||||
|
|
||||||
// sudo chown root:$(id -u) -R boot/ && sudo chmod g+rw -R boot/
|
// sudo chown root:$(id -u) -R boot/ && sudo chmod g+rw -R boot/
|
||||||
await execFile("qemu-system-x86_64", [
|
await execFile("qemu-system-x86_64", [
|
||||||
|
@ -53,6 +49,7 @@ export async function runQemu(
|
||||||
"-append",
|
"-append",
|
||||||
kernelAppend.join(" "),
|
kernelAppend.join(" "),
|
||||||
...qemuAppend,
|
...qemuAppend,
|
||||||
|
"-no-shutdown",
|
||||||
]);
|
]);
|
||||||
// -append "root=/dev/sda rootfstype=squashfs modules=ext4 quiet init=/sbin/runit-init $append" $qemuappend
|
// -append "root=/dev/sda rootfstype=squashfs modules=ext4 quiet init=/sbin/runit-init $append" $qemuappend
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "fs/promises";
|
||||||
import path from "node:path";
|
import path from "path";
|
||||||
import { Alpine } from "../alpine.js";
|
import { Alpine } from "../alpine.js";
|
||||||
|
|
||||||
export class Runit {
|
export class Runit {
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"target": "es2022",
|
|
||||||
"module": "es2022",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"strict": true
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue