Merge branch 'check-updates'

This commit is contained in:
Chris Wanstrath 2026-03-05 13:03:41 -08:00
commit 0a8287970d

View File

@ -298,26 +298,21 @@ router.get('/update', async c => {
}
})
// Apply update and restart
router.post('/update', async c => {
// Apply update and restart (delegates to install/install.sh)
// The script ends with `systemctl restart toes`, killing this process,
// so we respond immediately and run it detached.
router.post('/update', c => {
if (isUpdating) return c.json({ ok: false, error: 'update already in progress' }, 409)
isUpdating = true
try {
const pull = await Bun.spawn(['git', 'pull', 'origin', 'main'], { cwd: projectRoot }).exited
if (pull !== 0) return c.json({ ok: false, error: 'git pull failed' }, 500)
const install = await Bun.spawn(['bun', 'install'], { cwd: projectRoot }).exited
if (install !== 0) return c.json({ ok: false, error: 'bun install failed' }, 500)
const build = await Bun.spawn(['bun', 'run', 'build'], { cwd: projectRoot }).exited
if (build !== 0) return c.json({ ok: false, error: 'build failed' }, 500)
setTimeout(() => process.exit(0), 100)
const script = join(projectRoot, 'install/install.sh')
const proc = Bun.spawn(['bash', script], { cwd: projectRoot, stdout: 'ignore', stderr: 'ignore' })
proc.exited.then(code => { if (code !== 0) isUpdating = false })
.catch(() => { isUpdating = false })
return c.json({ ok: true })
} catch {
return c.json({ ok: false, error: 'update failed' }, 500)
} finally {
isUpdating = false
return c.json({ ok: false, error: 'failed to start update' }, 500)
}
})