working
Some checks are pending
Build Service / BuildPackage (push) Waiting to run

This commit is contained in:
2026-05-14 05:39:56 -04:00
parent 5b7cd13dc0
commit 172e3f63ac
33 changed files with 1633 additions and 0 deletions

13
startos/actions/index.ts Normal file
View File

@@ -0,0 +1,13 @@
import { sdk } from '../sdk'
import { resetPassword } from './resetPassword'
import { resetSpacedState } from './resetSpacedState'
import { setBitcoinRpc } from './setBitcoinRpc'
import { showCredentials } from './showCredentials'
import { syncStatus } from './syncStatus'
export const actions = sdk.Actions.of()
.addAction(resetPassword)
.addAction(showCredentials)
.addAction(setBitcoinRpc)
.addAction(syncStatus)
.addAction(resetSpacedState)

View File

@@ -0,0 +1,58 @@
import { storeJson } from '../fileModels/storeJson'
import { i18n } from '../i18n'
import { sdk } from '../sdk'
import { APP_USER, randomPassword } from '../utils'
export const resetPassword = sdk.Action.withoutInput(
// id
'reset-password',
// metadata
async ({ effects }) => ({
name: i18n('Reset Web UI Password'),
description: i18n(
'Generate a new admin password for the Spaces web terminal',
),
warning: null,
allowedStatuses: 'any',
group: null,
visibility: 'enabled',
}),
// run
async ({ effects }) => {
const password = randomPassword()
await storeJson.merge(effects, { password })
return {
version: '1',
title: i18n('Success'),
message: i18n(
'Use these credentials to log in to the Spaces web terminal.',
),
result: {
type: 'group',
value: [
{
type: 'single',
name: i18n('Username'),
description: null,
value: APP_USER,
masked: false,
copyable: true,
qr: false,
},
{
type: 'single',
name: i18n('Password'),
description: null,
value: password,
masked: true,
copyable: true,
qr: false,
},
],
},
}
},
)

View File

@@ -0,0 +1,59 @@
import { i18n } from '../i18n'
import { sdk } from '../sdk'
import { dataDir, SPACED_CHAIN } from '../utils'
export const resetSpacedState = sdk.Action.withoutInput(
// id
'reset-spaced-state',
// metadata
async ({ effects }) => ({
name: i18n('Reset Spaced State'),
description: i18n(
"Wipe /data/mainnet/ so spaced resyncs its index from spaces' anchor.",
),
warning: i18n(
"This deletes spaced's on-disk index. The next start will resync from spaces' anchor and can take a while. store.json (passwords + RPC credentials) is preserved.",
),
allowedStatuses: 'any',
group: null,
visibility: 'enabled',
}),
// run
async ({ effects }) => {
const res = await sdk.SubContainer.withTemp(
effects,
{ imageId: 'spaces' },
sdk.Mounts.of().mountVolume({
volumeId: 'main',
subpath: null,
mountpoint: dataDir,
readonly: false,
}),
'spaces-reset-state',
(subc) =>
subc.exec(['rm', '-rf', `${dataDir}/${SPACED_CHAIN}`], { user: 'root' }),
)
if (res.exitCode !== 0) {
return {
version: '1',
title: i18n('Failure'),
message: i18n('Could not wipe spaced state: ${error}', {
error: (res.stderr ?? '').toString() || `exit ${res.exitCode}`,
}),
result: null,
}
}
return {
version: '1',
title: i18n('Success'),
message: i18n(
'Spaced state has been wiped. Start (or restart) the service to resync.',
),
result: null,
}
},
)

View File

@@ -0,0 +1,60 @@
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 setBitcoinRpc = sdk.Action.withoutInput(
// id
'set-bitcoin-rpc',
// metadata
async ({ effects }) => ({
name: i18n('Set up Bitcoin RPC'),
description: i18n('Re-run the bitcoind RPC credential setup for Spaces'),
warning: null,
allowedStatuses: 'any',
group: null,
visibility: 'enabled',
}),
// run
async ({ effects }) => {
const existing = await storeJson.read((s) => s.btcAuth).once()
const username = existing?.username ?? BITCOIN_RPC_USER
const password = existing?.password ?? randomPassword()
try {
await effects.action.run({
packageId: BITCOIND_PACKAGE_ID,
actionId: 'generate-rpc-dependent',
input: { username, password },
})
} catch (err) {
return {
version: '1',
title: i18n('Failure'),
message: i18n('Could not call bitcoind. Is Bitcoin installed and running?'),
result: null,
}
}
if (!existing) {
await storeJson.merge(
effects,
{ btcAuth: { username, password } },
{ allowWriteAfterConst: true },
)
}
return {
version: '1',
title: i18n('Success'),
message: i18n('Bitcoin RPC credentials have been re-sent to bitcoind.'),
result: null,
}
},
)

View File

@@ -0,0 +1,57 @@
import { storeJson } from '../fileModels/storeJson'
import { i18n } from '../i18n'
import { sdk } from '../sdk'
import { APP_USER } from '../utils'
export const showCredentials = sdk.Action.withoutInput(
// id
'show-credentials',
// metadata
async ({ effects }) => ({
name: i18n('Show Web UI Credentials'),
description: i18n(
'Display the username and password for the Spaces web terminal',
),
warning: null,
allowedStatuses: 'any',
group: null,
visibility: 'hidden',
}),
// run
async ({ effects }) => {
const password = await storeJson.read((s) => s.password).once()
return {
version: '1',
title: i18n('Show Web UI Credentials'),
message: i18n(
'Use these credentials to log in to the Spaces web terminal.',
),
result: {
type: 'group',
value: [
{
type: 'single',
name: i18n('Username'),
description: null,
value: APP_USER,
masked: false,
copyable: true,
qr: false,
},
{
type: 'single',
name: i18n('Password'),
description: null,
value: password ?? '',
masked: true,
copyable: true,
qr: false,
},
],
},
}
},
)

View File

@@ -0,0 +1,69 @@
import { i18n } from '../i18n'
import { sdk } from '../sdk'
import { dataDir, SPACED_CHAIN } from '../utils'
export const syncStatus = sdk.Action.withoutInput(
// id
'sync-status',
// metadata
async ({ effects }) => ({
name: i18n('Sync Status'),
description: i18n(
"Query spaced's getserverinfo RPC and report sync progress",
),
warning: null,
allowedStatuses: 'only-running',
group: null,
visibility: 'enabled',
}),
// run
async ({ effects }) => {
const res = await sdk.SubContainer.withTemp(
effects,
{ imageId: 'spaces' },
sdk.Mounts.of().mountVolume({
volumeId: 'main',
subpath: null,
mountpoint: dataDir,
readonly: false,
}),
'spaces-sync-status',
(subc) =>
subc.exec([
'/root/.cargo/bin/space-cli',
'--chain',
SPACED_CHAIN,
'--rpc-cookie',
`${dataDir}/${SPACED_CHAIN}/.cookie`,
'getserverinfo',
]),
)
if (res.exitCode !== 0) {
return {
version: '1',
title: i18n('Failure'),
message: i18n('Could not query spaced. Is the service running?'),
result: null,
}
}
const stdout = (res.stdout ?? '').toString().trim()
return {
version: '1',
title: i18n('Sync Status'),
message: stdout || i18n('spaced is fully synced.'),
result: {
type: 'single',
name: 'getserverinfo',
description: null,
value: stdout,
masked: false,
copyable: true,
qr: false,
},
}
},
)