#!/usr/bin/env bare
/**
* Reset identity registry config so the server boots with a fresh local registry.
* Run this when the Autobase state is corrupted after a failed identity-join.
*
* Usage: bare scripts/reset-identity-registry.js [--storage <path>]
*/
import Corestore from 'corestore'
import Hyperbee from 'hyperbee'
import path from 'bare-path'
const args = global.Bare ? global.Bare.argv : process.argv.slice(2)
let storagePath = 'pear-git-storage'
for (let i = 0; i < args.length; i++) {
if (args[i] === '--storage' && args[i + 1]) storagePath = args[i + 1]
}
const storageDir = path.resolve(storagePath)
console.log('Storage:', storageDir)
const store = new Corestore(path.join(storageDir, 'CORESTORE'))
const registry = new Hyperbee(store.get({ name: 'registry' }), {
keyEncoding: 'utf-8',
valueEncoding: 'json'
})
await registry.ready()
const entry = await registry.get('config:identityRegistry')
if (!entry) {
console.log('No identity registry config found — nothing to reset.')
} else {
console.log('Current config:', JSON.stringify(entry.value, null, 2))
await registry.del('config:identityRegistry')
console.log('Deleted config:identityRegistry — server will create fresh local registry on next boot.')
}
await registry.close()
await store.close()
console.log('Done.')