41 lines
993 B
TypeScript
41 lines
993 B
TypeScript
import { join } from "path";
|
|
import { Alpine } from "./alpine.js";
|
|
|
|
export type Mount = {
|
|
path: string;
|
|
username: string;
|
|
};
|
|
function getPersistPath(mount: Mount): string {
|
|
return join("/persist", mount.path);
|
|
}
|
|
|
|
export class Persist {
|
|
private alpine: Alpine;
|
|
private mounts: Mount[] = [];
|
|
constructor(alpine: Alpine) {
|
|
this.alpine = alpine;
|
|
}
|
|
|
|
async addMount(mount: Mount) {
|
|
await this.alpine.symlink(getPersistPath(mount), mount.path);
|
|
this.mounts.push(mount);
|
|
await this.write();
|
|
}
|
|
async write() {
|
|
await this.alpine.mkdirP("/persist");
|
|
let script = "#!/bin/sh -e\n";
|
|
script += this.mounts
|
|
.flatMap((m) => [
|
|
`mkdir -p '${getPersistPath(m)}'`,
|
|
`chown '${m.username}:${m.username}' '${getPersistPath(m)}'`,
|
|
`chmod 700 '${m.path}'`,
|
|
])
|
|
.join("\n");
|
|
await this.alpine.writeExecutable(
|
|
// runit/scripts/03-filesystems.sh
|
|
"/usr/local/sbin/set-persist-permissions",
|
|
script
|
|
);
|
|
}
|
|
}
|