This commit is contained in:
20
startos/init/index.ts
Normal file
20
startos/init/index.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { actions } from '../actions'
|
||||
import { restoreInit } from '../backups'
|
||||
import { setDependencies } from '../dependencies'
|
||||
import { setInterfaces } from '../interfaces'
|
||||
import { sdk } from '../sdk'
|
||||
import { versionGraph } from '../versions'
|
||||
import { taskBtcAuth } from './taskBtcAuth'
|
||||
import { taskSetPassword } from './taskSetPassword'
|
||||
|
||||
export const init = sdk.setupInit(
|
||||
restoreInit,
|
||||
versionGraph,
|
||||
setInterfaces,
|
||||
setDependencies,
|
||||
actions,
|
||||
taskBtcAuth,
|
||||
taskSetPassword,
|
||||
)
|
||||
|
||||
export const uninit = sdk.setupUninit(versionGraph)
|
||||
34
startos/init/taskBtcAuth.ts
Normal file
34
startos/init/taskBtcAuth.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { storeJson } from '../fileModels/storeJson'
|
||||
import { i18n } from '../i18n'
|
||||
import { sdk } from '../sdk'
|
||||
import {
|
||||
BITCOIN_RPC_USER,
|
||||
BITCOIND_PACKAGE_ID,
|
||||
randomPassword,
|
||||
} from '../utils'
|
||||
|
||||
export const taskBtcAuth = sdk.setupOnInit(async (effects) => {
|
||||
const existing = await storeJson.read((s) => s.btcAuth).once()
|
||||
if (existing) return
|
||||
|
||||
const username = BITCOIN_RPC_USER
|
||||
const password = randomPassword()
|
||||
|
||||
await effects.action.createTask({
|
||||
replayId: 'spaces-rpc-auth',
|
||||
packageId: BITCOIND_PACKAGE_ID,
|
||||
actionId: 'generate-rpc-dependent',
|
||||
severity: 'critical',
|
||||
reason: i18n('Spaces needs RPC credentials in Bitcoin'),
|
||||
input: {
|
||||
kind: 'partial',
|
||||
value: { username, password },
|
||||
},
|
||||
})
|
||||
|
||||
await storeJson.merge(
|
||||
effects,
|
||||
{ btcAuth: { username, password } },
|
||||
{ allowWriteAfterConst: true },
|
||||
)
|
||||
})
|
||||
20
startos/init/taskSetPassword.ts
Normal file
20
startos/init/taskSetPassword.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { showCredentials } from '../actions/showCredentials'
|
||||
import { storeJson } from '../fileModels/storeJson'
|
||||
import { i18n } from '../i18n'
|
||||
import { sdk } from '../sdk'
|
||||
import { randomPassword } from '../utils'
|
||||
|
||||
export const taskSetPassword = sdk.setupOnInit(async (effects) => {
|
||||
const existing = await storeJson.read((s) => s.password).once()
|
||||
if (existing) return
|
||||
|
||||
await storeJson.merge(
|
||||
effects,
|
||||
{ password: randomPassword() },
|
||||
{ allowWriteAfterConst: true },
|
||||
)
|
||||
|
||||
await sdk.action.createOwnTask(effects, showCredentials, 'critical', {
|
||||
reason: i18n('Spaces needs an admin password for the web terminal'),
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user