Compare commits

..

No commits in common. "d3b6d97bb614bc6973d1f5675cf21a2a8de12e7d" and "08e1df544a1a8846ce0ce5df5c6745906593854b" have entirely different histories.

2 changed files with 21 additions and 30 deletions

View File

@ -13,6 +13,8 @@ DEST=~/toes
APPS_DIR=~/apps APPS_DIR=~/apps
DATA_DIR=~/data DATA_DIR=~/data
BUNDLED_APPS="clock code cron env git metrics"
# ── Helpers ────────────────────────────────────────────── # ── Helpers ──────────────────────────────────────────────
quiet() { "$@" > /dev/null 2>&1; } quiet() { "$@" > /dev/null 2>&1; }
@ -80,34 +82,18 @@ info "Installing dependencies"
quiet bun install quiet bun install
info "Building" info "Building"
rm -rf "$DEST/dist"
quiet bun run build quiet bun run build
# ── Bundled apps ───────────────────────────────────────── # ── Bundled apps ─────────────────────────────────────────
REPOS_DIR="$DATA_DIR/repos"
mkdir -p "$REPOS_DIR"
info "Installing bundled apps" info "Installing bundled apps"
for app_dir in "$DEST"/apps/*/; do for app in $BUNDLED_APPS; do
app=$(basename "$app_dir") [ -d "$DEST/apps/$app" ] || continue
[ -f "$app_dir/package.json" ] || continue
echo " $app" echo " $app"
cp -a "$app_dir" "$APPS_DIR/$app" cp -r "$DEST/apps/$app" "$APPS_DIR/"
quiet bun install --frozen-lockfile --cwd "$APPS_DIR/$app" || quiet bun install --cwd "$APPS_DIR/$app" if [ -f "$APPS_DIR/$app/package.json" ]; then
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 fi
rm -rf "$APPS_DIR/$app/.git"
done done
# ── Systemd ────────────────────────────────────────────── # ── Systemd ──────────────────────────────────────────────

View File

@ -298,21 +298,26 @@ router.get('/update', async c => {
} }
}) })
// Apply update and restart (delegates to install/install.sh) // Apply update and restart
// The script ends with `systemctl restart toes`, killing this process, router.post('/update', async c => {
// 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 script = join(projectRoot, 'install/install.sh') const pull = await Bun.spawn(['git', 'pull', 'origin', 'main'], { cwd: projectRoot }).exited
const proc = Bun.spawn(['bash', script], { cwd: projectRoot, stdout: 'ignore', stderr: 'ignore' }) if (pull !== 0) return c.json({ ok: false, error: 'git pull failed' }, 500)
proc.exited.then(code => { if (code !== 0) isUpdating = false })
.catch(() => { isUpdating = false }) 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)
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)
} }
}) })