forked from defunkt/toes
Merge branch 'check-updates'
This commit is contained in:
commit
0a8287970d
|
|
@ -298,26 +298,21 @@ router.get('/update', async c => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Apply update and restart
|
// Apply update and restart (delegates to install/install.sh)
|
||||||
router.post('/update', async c => {
|
// 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)
|
if (isUpdating) return c.json({ ok: false, error: 'update already in progress' }, 409)
|
||||||
isUpdating = true
|
isUpdating = true
|
||||||
try {
|
try {
|
||||||
const pull = await Bun.spawn(['git', 'pull', 'origin', 'main'], { cwd: projectRoot }).exited
|
const script = join(projectRoot, 'install/install.sh')
|
||||||
if (pull !== 0) return c.json({ ok: false, error: 'git pull failed' }, 500)
|
const proc = Bun.spawn(['bash', script], { cwd: projectRoot, stdout: 'ignore', stderr: 'ignore' })
|
||||||
|
proc.exited.then(code => { if (code !== 0) isUpdating = false })
|
||||||
const install = await Bun.spawn(['bun', 'install'], { cwd: projectRoot }).exited
|
.catch(() => { isUpdating = false })
|
||||||
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)
|
|
||||||
return c.json({ ok: true })
|
return c.json({ ok: true })
|
||||||
} catch {
|
} catch {
|
||||||
return c.json({ ok: false, error: 'update failed' }, 500)
|
|
||||||
} finally {
|
|
||||||
isUpdating = false
|
isUpdating = false
|
||||||
|
return c.json({ ok: false, error: 'failed to start update' }, 500)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user