define-alpine-the-sequel/fstab.ts

42 lines
1 KiB
TypeScript

import { Alpine } from "./alpine.js";
export class Fstab {
private alpine: Alpine;
constructor(alpine: Alpine) {
this.alpine = alpine;
}
private mounts: string[] = [
"/current.squashfs / squashfs defaults 0 0",
"tmpfs /tmp tmpfs defaults 0 0",
];
async addMount(mount: string) {
this.mounts.push(mount);
await this.write();
}
async addTmpfs(path: string, opts: TmpfsOptions = {}) {
const add = Object.entries(opts)
.map(([key, val]) => `,${key}=${val}`)
.join("");
await this.addMount(`tmpfs ${path} tmpfs defaults,noexec,nosuid${add} 0 0`);
await this.alpine.mkdirP(path);
}
// Writes fstab to disk.
// Intended for internal use only, use addMount or addTmpfs instead
async write() {
await this.alpine.writeFile(
"/etc/fstab",
this.mounts.join("\n") +
// Busybox mount no entiende la última línea sino
"\n",
{ uid: 0, gid: 0 }
);
}
}
interface TmpfsOptions {
uid?: number;
gid?: number;
mode?: string;
}