mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
Refactor/sdk init (#2947)
* fixes for main * refactor package initialization * fixes from testing * more fixes * beta.21 * do not use instanceof * closes #2921 * beta22 * allow disabling kiosk * migration * fix /etc/shadow * actionRequest -> task * beta.23
This commit is contained in:
@@ -2,6 +2,8 @@ import * as T from "../../../base/lib/types"
|
||||
import * as child_process from "child_process"
|
||||
import * as fs from "fs/promises"
|
||||
import { Affine, asError } from "../util"
|
||||
import { ExtendedVersion, VersionRange } from "../../../base/lib"
|
||||
import { InitKind, InitScript } from "../../../base/lib/inits"
|
||||
|
||||
export const DEFAULT_OPTIONS: T.SyncOptions = {
|
||||
delete: true,
|
||||
@@ -17,7 +19,7 @@ export type BackupSync<Volumes extends string> = {
|
||||
|
||||
export type BackupEffects = T.Effects & Affine<"Backups">
|
||||
|
||||
export class Backups<M extends T.SDKManifest> {
|
||||
export class Backups<M extends T.SDKManifest> implements InitScript {
|
||||
private constructor(
|
||||
private options = DEFAULT_OPTIONS,
|
||||
private restoreOptions: Partial<T.SyncOptions> = {},
|
||||
@@ -35,7 +37,7 @@ export class Backups<M extends T.SDKManifest> {
|
||||
return Backups.withSyncs(
|
||||
...volumeNames.map((srcVolume) => ({
|
||||
dataPath: `/media/startos/volumes/${srcVolume}/` as const,
|
||||
backupPath: `/media/startos/backup/${srcVolume}/` as const,
|
||||
backupPath: `/media/startos/backup/volumes/${srcVolume}/` as const,
|
||||
})),
|
||||
)
|
||||
}
|
||||
@@ -96,7 +98,7 @@ export class Backups<M extends T.SDKManifest> {
|
||||
return this
|
||||
}
|
||||
|
||||
mountVolume(
|
||||
addVolume(
|
||||
volume: M["volumes"][number],
|
||||
options?: Partial<{
|
||||
options: T.SyncOptions
|
||||
@@ -106,7 +108,7 @@ export class Backups<M extends T.SDKManifest> {
|
||||
) {
|
||||
return this.addSync({
|
||||
dataPath: `/media/startos/volumes/${volume}/` as const,
|
||||
backupPath: `/media/startos/backup/${volume}/` as const,
|
||||
backupPath: `/media/startos/backup/volumes/${volume}/` as const,
|
||||
...options,
|
||||
})
|
||||
}
|
||||
@@ -143,6 +145,12 @@ export class Backups<M extends T.SDKManifest> {
|
||||
return
|
||||
}
|
||||
|
||||
async init(effects: T.Effects, kind: InitKind): Promise<void> {
|
||||
if (kind === "restore") {
|
||||
await this.restoreBackup(effects)
|
||||
}
|
||||
}
|
||||
|
||||
async restoreBackup(effects: T.Effects) {
|
||||
this.preRestore(effects as BackupEffects)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Backups } from "./Backups"
|
||||
import * as T from "../../../base/lib/types"
|
||||
import { _ } from "../util"
|
||||
import { InitScript } from "../../../base/lib/inits"
|
||||
|
||||
export type SetupBackupsParams<M extends T.SDKManifest> =
|
||||
| M["volumes"][number][]
|
||||
@@ -8,7 +9,7 @@ export type SetupBackupsParams<M extends T.SDKManifest> =
|
||||
|
||||
type SetupBackupsRes = {
|
||||
createBackup: T.ExpectedExports.createBackup
|
||||
restoreBackup: T.ExpectedExports.restoreBackup
|
||||
restoreInit: InitScript
|
||||
}
|
||||
|
||||
export function setupBackups<M extends T.SDKManifest>(
|
||||
@@ -20,19 +21,18 @@ export function setupBackups<M extends T.SDKManifest>(
|
||||
} else {
|
||||
backupsFactory = async () => Backups.withVolumes(...options)
|
||||
}
|
||||
const answer: {
|
||||
createBackup: T.ExpectedExports.createBackup
|
||||
restoreBackup: T.ExpectedExports.restoreBackup
|
||||
} = {
|
||||
const answer: SetupBackupsRes = {
|
||||
get createBackup() {
|
||||
return (async (options) => {
|
||||
return (await backupsFactory(options)).createBackup(options.effects)
|
||||
}) as T.ExpectedExports.createBackup
|
||||
},
|
||||
get restoreBackup() {
|
||||
return (async (options) => {
|
||||
return (await backupsFactory(options)).restoreBackup(options.effects)
|
||||
}) as T.ExpectedExports.restoreBackup
|
||||
get restoreInit(): InitScript {
|
||||
return {
|
||||
init: async (effects, kind) => {
|
||||
return (await backupsFactory({ effects })).init(effects, kind)
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
return answer
|
||||
|
||||
Reference in New Issue
Block a user