Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ folders; (4) size: each skin is 7.8 MB, so the package grows by about 16 MB.
3. Runs each package's `install.sh -y -n -t <target>` or `uninstall.sh`, checks the exit status and that the plugin-list entry exists (`file=` and `uid`).
4. On any failure: restore the settings and the folders, mark the item failed with the log tail on screen, start MPC.
5. On success: refresh the manifest and history, start MPC.

Since 1.4.0 (roadmap items 1 to 3; the update screen tried on a Live III, the rest offline only):
- **Snapshots.** A folder of 48 MB or less (`PM_SNAP_KB`) is copied to RAM as before. A bigger one is not copied when its installer stages the new folder beside the old one and swaps it in at the end (every `install.sh` since 2026-09-29, told by `STAGE=` in it), or when it is a removal. The old folder stays in place until that swap. If such an install fails after the swap, the files in place are kept and `MPC.settings` is put back. Only an older installer still gets the copy beside the folder.
- **Journal.** `apply.sh` writes `<base>/.openmpcpm-journal` on the settings drive (not `/tmp`, which a reboot empties): its own pid, then `begin`/`end` per step (tab-separated). It is deleted before MPC starts. `src/recover.sh` (embedded as `src/recover_sh.h`, `vst/gen_recover.py`) finishes or undoes a step that began and never ended. A folder in place is kept as it is; a missing one is put back from the safety copy, the installer's `.<folder>.old` or the failed folder; leftovers are removed; a cut-off skin swap is put back. It only renames and deletes, so it is safe with MPC running. The Manager runs it at start, and `apply.sh` runs it first. It does nothing while the `apply.sh` that wrote the journal still runs (the background server refreshes during an apply). What it did shows once: `The last update did not finish. <name>: interrupted ...`.
- **Progress.** `apply.sh` writes `/tmp/openmpc-pm/progress` (step, of, act, id, version) before each step. While a journal exists, `/api/state` carries it as `apply` and the web page shows the step.
- **Update screen.** `src/splash.c` (`openmpc-pm-splash`, static, in the `bgserver/` and `bgserver-gen1/` payloads; `vst/build_splash.sh`) draws that progress on the MPC's own display while MPC is stopped. `apply.sh` runs a copy in `/tmp/openmpc-pm` (a self-update replaces the plugin folder) with `/tmp/openmpc-pm/names` (id, name) once MPC is stopped, and stops it, plus `az0x-splashctl drop-display`, before it starts MPC. MPC fails to start ("Failed to initialise display") while anything else holds the display, so:
- Where Akai's `az0x-splash` runs (Gen2 MPC OS 3.x: `/usr/bin/az0x-splashctl`, `/run/az0x-splash-control`), each frame is a 1280x800 landscape PNG shown with `az0x-splashctl show-image --drop`: Akai's splash turns it for the panel and lets go of the display at once, so nothing is held between frames. The default `--keep` blocks MPC until `drop-display` (Live III, 2026-11-21).
- Elsewhere it takes DRM master itself (or gives up at once), sets the panel's mode with one dumb buffer and draws portrait panels turned 90 degrees as force-shadow does (`PM_SPLASH_ROT` overrides).
- Either way it exits when MPC runs (an older installer can start it), when `apply.sh` dies, when the progress file goes and after an hour. `--ppm OUT[.png]` renders one frame offline (tests/run.sh `splash`).
- Verified on the Live III (3.10.1) by hand: frames, the pulse at about 80 ms a frame, and MPC starting straight after `--drop` frames. The direct-display path still needs a device without `az0x-splash`.

The restart path must not be compiled out on aarch64 (poloq's `#ifdef __arm__` turned the apply into a dry run: PR #12 fixes it; keep a test that fails if the aarch64 build takes the dry-run branch).

## 8. Testing
Expand Down
99 changes: 84 additions & 15 deletions src/manager.c

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions src/recover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh
# Finish or undo an apply that was cut off (MPC switched off, power cut): run by the Plugin Manager at start and by apply.sh
# before it begins. Regenerate src/recover_sh.h with vst/gen_recover.py after editing.
# sh recover.sh JOURNAL RESULT
# JOURNAL is written by apply.sh, one tab-separated line per event:
# pid <pid of apply.sh> first line
# begin <id> <folder> <act> a step starts (<id> "theme": <folder> is the Manager's own folder, its skin is being swapped)
# end <id> that step finished, whatever its outcome (apply.sh already rolled it back if it failed)
# For every step begun and not ended, only renames and deletes of the Manager's and the installers' own leftovers are done,
# so this is safe while MPC runs. A folder that is in place is kept as it is (old or new version); a missing one is put back
# from the newest complete copy there is. One line per step goes to RESULT ("id|fail|interrupted: ..."), shown at next start.
# Nothing is done while the apply.sh that wrote the journal still runs (APPLY_PID: the apply.sh running this, never that one).
J=$1; RES=$2
[ -f "$J" ] || exit 0
TAB=$(printf '\t')
pid=$(sed -n "s/^pid$TAB\\([0-9][0-9]*\\)\$/\\1/p" "$J" | head -n 1)
if [ -n "$pid" ] && [ "$pid" != "${APPLY_PID:-}" ] && [ -r "/proc/$pid/cmdline" ] && tr '\0' ' ' < "/proc/$pid/cmdline" | grep -q 'apply\.sh'; then
echo "recover: apply.sh ($pid) is still running, nothing done"; exit 0
fi
ver() { sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' "$1/mpc-plugin.json" 2>/dev/null | head -n 1; }
open=$(awk -F"$TAB" '$1 == "begin" { b[$2] = $0; o[++n] = $2 } $1 == "end" { delete b[$2] } END { for (i = 1; i <= n; i++) if (o[i] in b) { print b[o[i]]; delete b[o[i]] } }' "$J")
printf '%s\n' "$open" | while IFS="$TAB" read -r tag id dir act; do
[ "$tag" = begin ] && [ -n "$id" ] || continue
if [ "$id" = theme ]; then # the skin swap: "Plugin Skins" -> .skin.old, .skin.new -> "Plugin Skins"
T=$dir; what="the skin was left as it was"
if [ ! -d "$T/Plugin Skins" ] && [ -d "$T/.skin.old" ]; then mv "$T/.skin.old" "$T/Plugin Skins" && what="the skin was put back"; fi
[ -d "$T/Plugin Skins" ] && rm -rf "$T/.skin.new" "$T/.skin.old"
echo "recover: theme: $what"
continue
fi
[ -n "$dir" ] || { echo "$id|fail|interrupted: nothing was changed" >> "$RES"; continue; }
p=${dir%/*}; b=${dir##*/}
snap="$p/.pm-snap-$id"; old="$p/.$b.old"; bad="$p/.pm-failed-$id"
what=""
if [ ! -d "$dir" ]; then # the folder is gone: the newest complete copy goes back (a safety copy, the installer's old folder, the failed one)
if [ -d "$snap" ] && [ -f "$snap.done" ]; then mv "$snap" "$dir" && rm -f "$snap.done" && what="put back from the safety copy"
elif [ -d "$old" ]; then mv "$old" "$dir" && what="put back as it was"
elif [ -d "$bad" ]; then mv "$bad" "$dir" && what="put back (the files of the cut-off update)"
fi
fi
if [ -d "$dir" ]; then
rm -rf "$p/.$b.new" "$old" "$bad"
[ -e "$snap" ] && rm -rf "$snap" "$snap.done"
v=$(ver "$dir")
[ -n "$what" ] || what="its folder is in place"
echo "$id|fail|interrupted (was the MPC switched off?): $what${v:+, now $v}" >> "$RES"
elif [ "$act" = remove ]; then
rm -rf "$p/.$b.new"
echo "$id|ok|remove" >> "$RES"
else
rm -rf "$p/.$b.new"
if [ -e "$snap" ]; then echo "$id|fail|interrupted: its folder is missing; an incomplete copy is at $snap" >> "$RES"
else echo "$id|fail|interrupted: its folder is missing, install it again" >> "$RES"; fi
fi
echo "recover: $id: ${what:-folder missing}"
done
rm -f "$J"
exit 0
60 changes: 60 additions & 0 deletions src/recover_sh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* src/recover.sh (finish or undo a cut-off apply), run at start and by apply.sh; regenerate with vst/gen_recover.py */
static const char RECOVER_SH[] =
"#!/bin/sh\n"
"# Finish or undo an apply that was cut off (MPC switched off, power cut): run by the Plugin Manager at start and by apply.sh\n"
"# before it begins. Regenerate src/recover_sh.h with vst/gen_recover.py after editing.\n"
"# sh recover.sh JOURNAL RESULT\n"
"# JOURNAL is written by apply.sh, one tab-separated line per event:\n"
"# pid <pid of apply.sh> first line\n"
"# begin <id> <folder> <act> a step starts (<id> \"theme\": <folder> is the Manager's own folder, its skin is being swapped)\n"
"# end <id> that step finished, whatever its outcome (apply.sh already rolled it back if it failed)\n"
"# For every step begun and not ended, only renames and deletes of the Manager's and the installers' own leftovers are done,\n"
"# so this is safe while MPC runs. A folder that is in place is kept as it is (old or new version); a missing one is put back\n"
"# from the newest complete copy there is. One line per step goes to RESULT (\"id|fail|interrupted: ...\"), shown at next start.\n"
"# Nothing is done while the apply.sh that wrote the journal still runs (APPLY_PID: the apply.sh running this, never that one).\n"
"J=$1; RES=$2\n"
"[ -f \"$J\" ] || exit 0\n"
"TAB=$(printf '\\t')\n"
"pid=$(sed -n \"s/^pid$TAB\\\\([0-9][0-9]*\\\\)\\$/\\\\1/p\" \"$J\" | head -n 1)\n"
"if [ -n \"$pid\" ] && [ \"$pid\" != \"${APPLY_PID:-}\" ] && [ -r \"/proc/$pid/cmdline\" ] && tr '\\0' ' ' < \"/proc/$pid/cmdline\" | grep -q 'apply\\.sh'; then\n"
" echo \"recover: apply.sh ($pid) is still running, nothing done\"; exit 0\n"
"fi\n"
"ver() { sed -n 's/.*\"version\": *\"\\([^\"]*\\)\".*/\\1/p' \"$1/mpc-plugin.json\" 2>/dev/null | head -n 1; }\n"
"open=$(awk -F\"$TAB\" '$1 == \"begin\" { b[$2] = $0; o[++n] = $2 } $1 == \"end\" { delete b[$2] } END { for (i = 1; i <= n; i++) if (o[i] in b) { print b[o[i]]; delete b[o[i]] } }' \"$J\")\n"
"printf '%s\\n' \"$open\" | while IFS=\"$TAB\" read -r tag id dir act; do\n"
" [ \"$tag\" = begin ] && [ -n \"$id\" ] || continue\n"
" if [ \"$id\" = theme ]; then # the skin swap: \"Plugin Skins\" -> .skin.old, .skin.new -> \"Plugin Skins\"\n"
" T=$dir; what=\"the skin was left as it was\"\n"
" if [ ! -d \"$T/Plugin Skins\" ] && [ -d \"$T/.skin.old\" ]; then mv \"$T/.skin.old\" \"$T/Plugin Skins\" && what=\"the skin was put back\"; fi\n"
" [ -d \"$T/Plugin Skins\" ] && rm -rf \"$T/.skin.new\" \"$T/.skin.old\"\n"
" echo \"recover: theme: $what\"\n"
" continue\n"
" fi\n"
" [ -n \"$dir\" ] || { echo \"$id|fail|interrupted: nothing was changed\" >> \"$RES\"; continue; }\n"
" p=${dir%/*}; b=${dir##*/}\n"
" snap=\"$p/.pm-snap-$id\"; old=\"$p/.$b.old\"; bad=\"$p/.pm-failed-$id\"\n"
" what=\"\"\n"
" if [ ! -d \"$dir\" ]; then # the folder is gone: the newest complete copy goes back (a safety copy, the installer's old folder, the failed one)\n"
" if [ -d \"$snap\" ] && [ -f \"$snap.done\" ]; then mv \"$snap\" \"$dir\" && rm -f \"$snap.done\" && what=\"put back from the safety copy\"\n"
" elif [ -d \"$old\" ]; then mv \"$old\" \"$dir\" && what=\"put back as it was\"\n"
" elif [ -d \"$bad\" ]; then mv \"$bad\" \"$dir\" && what=\"put back (the files of the cut-off update)\"\n"
" fi\n"
" fi\n"
" if [ -d \"$dir\" ]; then\n"
" rm -rf \"$p/.$b.new\" \"$old\" \"$bad\"\n"
" [ -e \"$snap\" ] && rm -rf \"$snap\" \"$snap.done\"\n"
" v=$(ver \"$dir\")\n"
" [ -n \"$what\" ] || what=\"its folder is in place\"\n"
" echo \"$id|fail|interrupted (was the MPC switched off?): $what${v:+, now $v}\" >> \"$RES\"\n"
" elif [ \"$act\" = remove ]; then\n"
" rm -rf \"$p/.$b.new\"\n"
" echo \"$id|ok|remove\" >> \"$RES\"\n"
" else\n"
" rm -rf \"$p/.$b.new\"\n"
" if [ -e \"$snap\" ]; then echo \"$id|fail|interrupted: its folder is missing; an incomplete copy is at $snap\" >> \"$RES\"\n"
" else echo \"$id|fail|interrupted: its folder is missing, install it again\" >> \"$RES\"; fi\n"
" fi\n"
" echo \"recover: $id: ${what:-folder missing}\"\n"
"done\n"
"rm -f \"$J\"\n"
"exit 0\n";
Loading
Loading