Compare commits

..

5 Commits

2 changed files with 30 additions and 21 deletions

View File

@ -13,8 +13,6 @@ DEST=~/toes
APPS_DIR=~/apps
DATA_DIR=~/data
BUNDLED_APPS="clock code cron env git metrics"
# ── Helpers ──────────────────────────────────────────────
quiet() { "$@" > /dev/null 2>&1; }
@ -82,18 +80,34 @@ info "Installing dependencies"
quiet bun install
info "Building"
rm -rf "$DEST/dist"
quiet bun run build
# ── Bundled apps ─────────────────────────────────────────
REPOS_DIR="$DATA_DIR/repos"
mkdir -p "$REPOS_DIR"
info "Installing bundled apps"
for app in $BUNDLED_APPS; do
[ -d "$DEST/apps/$app" ] || continue
for app_dir in "$DEST"/apps/*/; do
app=$(basename "$app_dir")
[ -f "$app_dir/package.json" ] || continue
echo " $app"
cp -r "$DEST/apps/$app" "$APPS_DIR/"
if [ -f "$APPS_DIR/$app/package.json" ]; then
quiet bun install --frozen-lockfile --cwd "$APPS_DIR/$app" || quiet bun install --cwd "$APPS_DIR/$app"
cp -a "$app_dir" "$APPS_DIR/$app"
quiet bun install --frozen-lockfile --cwd "$APPS_DIR/$app" || quiet bun install --cwd "$APPS_DIR/$app"
# Seed bare repo for git-based versioning
bare="$REPOS_DIR/$app.git"
quiet git -C "$APPS_DIR/$app" init -b main
quiet git -C "$APPS_DIR/$app" add -A
quiet git -C "$APPS_DIR/$app" -c user.name=toes -c user.email=toes@localhost commit -m "install"
if [ -d "$bare" ]; then
quiet git -C "$APPS_DIR/$app" push --force "$bare" main
else
quiet git clone --bare "$APPS_DIR/$app" "$bare"
quiet git -C "$bare" config http.receivepack true
fi
rm -rf "$APPS_DIR/$app/.git"
done
# ── Systemd ──────────────────────────────────────────────

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)
}
})