diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 11ec9f8d..84f6142c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,12 +2,12 @@ # Everything else: one Open-HMG maintainer. * @Open-HMG/maintainers -# Root, signing, /system writes and CI: the maintainer. -/.github/ @VysseCodes @Open-HMG/releasers -/core/hmgapid/ @VysseCodes -/core/zygote/ @VysseCodes -/core/loader/ @VysseCodes -/install/ @VysseCodes -/tools/lpatch/ @VysseCodes -/SECURITY.md @VysseCodes -/CLAUDE.md @VysseCodes @Open-HMG/releasers +# Root, signing, /system writes and CI: the core team. +/.github/ @Open-HMG/core @Open-HMG/releasers +/core/hmgapid/ @Open-HMG/core +/core/zygote/ @Open-HMG/core +/core/loader/ @Open-HMG/core +/install/ @Open-HMG/core +/tools/lpatch/ @Open-HMG/core +/SECURITY.md @Open-HMG/core +/CLAUDE.md @Open-HMG/core @Open-HMG/releasers diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f898a92..83e1ab00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +- **A root service can read its own settings** (`HmgApi.settings()`, `saveSettings()`): the + daemon sees such a service as root, so the client names its mod (`HMGAPI_MOD`). +- **Catalogue:** Battery Watchdog 0.8.0 (zpoon), with its author key. + ## 1.1.0 (2026-11-28) 1.1.0-rc.10's code: only the version, this heading and the release notes changed. It is the diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5dae03f2..3f8780a8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,7 @@ Thanks for helping. Bug reports, Car Reports and ideas go in - Versions, release candidates and hotfixes (core and mods): [docs/releasing.md](docs/releasing.md). Don't change `HMGAPI_VERSION` or a mod's `"version"` in a feature PR: the release PR sets it. - The wiki lives in `wiki/`; changes there are published when merged. -- Who reviews what (`.github/CODEOWNERS`): VysseCodes reviews root, signing, `/system` +- Who reviews what (`.github/CODEOWNERS`): the core team (`@Open-HMG/core`) reviews root, signing, `/system` writes and CI (`.github/`, `core/hmgapid/`, `core/zygote/`, `core/loader/`, `install/`, `tools/lpatch/`, `SECURITY.md`, `CLAUDE.md`); everything else needs one of the Open-HMG maintainers. diff --git a/README.md b/README.md index 3bb7bf60..2b558ba0 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ # HMG-API +> [!IMPORTANT] +> **HMG-API is separating from NEMESIS.** This branch blocks installing or updating HMG-API alongside NEMESIS LivePatch. Existing and incomplete installations can be removed with an updated recovery package; see the compatibility and recovery instructions below. Read [the statement](https://github.com/Open-HMG/HMG-API/discussions/444), [#477](https://github.com/Open-HMG/HMG-API/issues/477), and [#397](https://github.com/Open-HMG/HMG-API/issues/397) for older installations and recovery background. + [![Support HMG-API](https://img.shields.io/badge/Support_HMG--API-%E2%9D%A4-bf3989?style=for-the-badge&logo=githubsponsors&logoColor=white)](https://github.com/Open-HMG/HMG-API/wiki/Support) > **HMG-API is free**, made by volunteers. If it saved you a dealer visit or made your drives nicer, please consider [supporting the people who build it](https://github.com/Open-HMG/HMG-API/wiki/Support): each maintainer has their own links there. It keeps the testing and new-car ports going. @@ -71,7 +74,11 @@ and the install starts again from the new firmware's doesn't work, car or firmware support (the Car Report's QR code fills it in), a new hook point, or an idea. Guides are in the [wiki](https://github.com/Open-HMG/HMG-API/wiki). -> **Status: [1.1.0](https://github.com/Open-HMG/HMG-API/releases/tag/v1.1.0).** It is the last release checked with NEMESIS (1.17.1): HMG-API is [separating from NEMESIS](https://github.com/Open-HMG/HMG-API/discussions/444). Tested on a US Kia EV6 (260507): the hook runtime, +> **Compatibility:** This branch blocks installing or updating HMG-API alongside NEMESIS LivePatch. Both systems modify the zygote and system files; bypassing LivePatch's read-only mounts does not establish safe coexistence. Uninstall remains available to recover existing and incomplete installations ([#477](https://github.com/Open-HMG/HMG-API/issues/477)). NEMESIS versions without LivePatch remain supported. +> +> For an incomplete installation, use a complete USB package built from this branch and create `HMGAPI/UNINSTALL` on the stick. It carries its own recovery uninstaller, so installing HMG-API again first is unnecessary. Recovery validates the stock backup and copies its result to `HMGAPI/install.log` on the stick. +> +> **Status: [1.1.0](https://github.com/Open-HMG/HMG-API/releases/tag/v1.1.0).** It was checked with NEMESIS (1.17.1) before the compatibility restriction above: HMG-API is [separating from NEMESIS](https://github.com/Open-HMG/HMG-API/discussions/444). Tested on a US Kia EV6 (260507): the hook runtime, > mods, the app, buttons, the side panel, Android Auto turn-by-turn and projection > events, the Car Report. CarPlay on HMG-API, the installers on a car without adb, and > other cars aren't tested yet. Leafia 1.x (HMG Leafia Plus) is the previous project. diff --git a/catalog/battery-watchdog.json b/catalog/battery-watchdog.json new file mode 100644 index 00000000..d00cece0 --- /dev/null +++ b/catalog/battery-watchdog.json @@ -0,0 +1,15 @@ +{ + "id": "battery-watchdog", + "name": "Battery Watchdog", + "description": "Keeps an eye on the 12V battery: logs its charge on every drive, shows drives and parked drops, and warns on the car's screen when it runs low or drains fast. Read-only: it never sends anything to the car.", + "authors": [ + "zpoon" + ], + "license": "MIT", + "uuid": "49624245-2eef-8b12-b385-823361d61309", + "version": "0.8.0", + "repo": "https://github.com/zpoon/gen5w-BatteryWatchdog", + "download": "https://github.com/zpoon/gen5w-BatteryWatchdog/releases/download/v0.8.0/battery-watchdog-0.8.0.zip", + "sha256": "1bd75b43e1260df5b3cc98c80040a3eeb9f99ca1cd61f4ca4ebec10cbdd8d728", + "hmgapi": ">=1.1.0" +} diff --git a/install/common/install-test.sh b/install/common/install-test.sh index dd8aa7da..a7b3c6cf 100644 --- a/install/common/install-test.sh +++ b/install/common/install-test.sh @@ -266,23 +266,10 @@ check "uninstalled, then a firmware update: the stale backup found, reset" "engi check "... new backup" "$(md5sum < $T/newfw)" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" unset HMGAPI_TEST_ENGINE -# NEMESIS 1.17's LivePatch: on every boot its watchdog writes its own script at app_process, and -# the first time keeps the binary it finds there as app_process.real (native/livepatch.c, -# lp_wrapper_install, called from svc.c whether or not a LivePatch package is installed) -NLP='#!/system/bin/sh -# NEMESIS LivePatch: apply patches before the zygote starts, then run the real binary. -case " $* " in -*" --zygote "*) [ -x /system/xbin/nemesis ] && /system/xbin/nemesis boot-apply ;; -esac -exec /system/bin/app_process.real "$@"' -nemesis_boot() { - grep -q '^# NEMESIS LivePatch' $R/system/bin/app_process || [ -f $R/system/bin/app_process.real ] \ - || cp $R/system/bin/app_process $R/system/bin/app_process.real - printf '%s\n' "$NLP" > $R/system/bin/app_process -} -# what the zygote start runs, NEMESIS's script and HMG-API's wrapper followed: the binary at the end -# (wherever each one is: a script or wrapper kept as a "stock copy" is followed too, and a chain -# that comes back on itself starts nothing) +# Keep the factory-reset and corrupt-backup regressions without LivePatch. +STK=$(md5sum < $T/newfw) +WRAPPERS="$(md5sum < $P/app_process | cut -c1-32)" +w5() { cp $P/app_process $T/w5; printf 'rc.5 /system/bin/app_process.hmgapi-stock\n' >> $T/w5; } chain() { local f=$R/system/bin/app_process n=0 while [ $n -lt 8 ]; do @@ -294,166 +281,6 @@ chain() { done echo "nothing: a loop" } -WRAPPERS="$(md5sum < $P/app_process | cut -c1-32)" -run $R/data/hmgapi/uninstall.sh -STK=$(md5sum < $T/newfw) -check "NEMESIS 1.17 cases start from stock" "$STK" "$(md5sum < $R/system/bin/app_process)" -NLPSUM=$(printf '%s\n' "$NLP" | md5sum) - -# (a) HMG-API first, then NEMESIS 1.17: NEMESIS keeps HMG-API's wrapper as app_process.real -run $P/install.sh $P -nemesis_boot -check "HMG-API, then NEMESIS 1.17: the zygote start ends at stock" "$STK" "$(chain)" -# an update under NEMESIS's script: the new wrapper goes where NEMESIS runs it -cp $P/app_process $T/wrapper.old; echo update >> $P/app_process; WRAPPERS="$WRAPPERS $(md5sum < $P/app_process | cut -c1-32)" -(cd $P && md5sum hmgapid lpatch app_process libhmgapi_hook.so hmgapi-hook.jar HmgApi.apk install.sh uninstall.sh lib.sh stock.txt app-pending.sh app-open.sh hook-check.sh boot.sh MAPS.md5 > MANIFEST) -run $P/install.sh $P -has "... an update under NEMESIS's script finishes" "installed. Restart the head unit" "$out" -check "... the new wrapper is app_process.real" "$(md5sum < $P/app_process)" "$(md5sum < $R/system/bin/app_process.real)" -check "... NEMESIS's script left as it is" "$NLPSUM" "$(md5sum < $R/system/bin/app_process)" -has "... install record: the wrapper's md5" "file $(md5sum < $P/app_process | cut -c1-32) /system/bin/app_process" "$(cat $R/data/hmgapi/installed.txt)" -nemesis_boot -check "... and after NEMESIS's next boot the zygote start still ends at stock" "$STK" "$(chain)" -run $R/data/hmgapi/uninstall.sh -has "... uninstall finishes" "HMG-API uninstalled" "$out" -check "... the stock binary is back in app_process.real" "$STK" "$(md5sum < $R/system/bin/app_process.real)" -check "... NEMESIS's script still there" "$NLPSUM" "$(md5sum < $R/system/bin/app_process)" -check "... HMG-API's stock copy gone" no "$([ -e $R/system/bin/app_process.hmgapi-stock ] && echo yes || echo no)" -nemesis_boot -check "... and after NEMESIS's next boot the zygote still starts: stock" "$STK" "$(chain)" - -# (b) NEMESIS 1.17 first (its script at app_process, stock in .real), then HMG-API -rm -rf $R/data/hmgapi -run $P/install.sh $P -has "NEMESIS 1.17, then HMG-API: installs (no unknown-app_process refusal)" "installed. Restart the head unit" "$out" -check "... the wrapper is app_process.real" "$(md5sum < $P/app_process)" "$(md5sum < $R/system/bin/app_process.real)" -check "... NEMESIS's script left as it is" "$NLPSUM" "$(md5sum < $R/system/bin/app_process)" -check "... stock kept beside it" "$STK" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)" -check "... the backup is the stock binary, not NEMESIS's script" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" -nemesis_boot -check "... the zygote start ends at stock" "$STK" "$(chain)" -run $R/data/hmgapi/uninstall.sh -has "... uninstall finishes" "HMG-API uninstalled" "$out" -check "... the stock binary is back in app_process.real" "$STK" "$(md5sum < $R/system/bin/app_process.real)" -nemesis_boot -check "... and after NEMESIS's next boot the zygote still starts: stock" "$STK" "$(chain)" - -# (d) an update by an older HMG-API under NEMESIS's script (#396 review): it wrote its wrapper over -# NEMESIS's script and left the wrapper before it in app_process.real. Before the next boot, this -# release's update, and then its uninstall, with no boot in between -mkdir -p $R/data/hmgapi; rm -rf $R/data/hmgapi -cp $T/wrapper.old $P/app_process # an older wrapper first -(cd $P && md5sum hmgapid lpatch app_process libhmgapi_hook.so hmgapi-hook.jar HmgApi.apk install.sh uninstall.sh lib.sh stock.txt app-pending.sh app-open.sh hook-check.sh boot.sh MAPS.md5 > MANIFEST) -run $P/install.sh $P # into .real, under NEMESIS's script -cp $P/app_process $T/wrapper.older; echo older >> $T/wrapper.older -cp $T/wrapper.older $R/system/bin/app_process.real # the wrapper before the old update... -cp $P/app_process $R/system/bin/app_process # ...and the old update's, over NEMESIS's script -WRAPPERS="$WRAPPERS $(md5sum < $T/wrapper.older | cut -c1-32)" -echo update >> $P/app_process; WRAPPERS="$WRAPPERS $(md5sum < $P/app_process | cut -c1-32)" -(cd $P && md5sum hmgapid lpatch app_process libhmgapi_hook.so hmgapi-hook.jar HmgApi.apk install.sh uninstall.sh lib.sh stock.txt app-pending.sh app-open.sh hook-check.sh boot.sh MAPS.md5 > MANIFEST) -run $P/install.sh $P -has "older update over NEMESIS's script, then this one: finishes" "installed. Restart the head unit" "$out" -check "... app_process.real gets the new wrapper (not left stale)" "$(md5sum < $P/app_process)" "$(md5sum < $R/system/bin/app_process.real)" -nemesis_boot -check "... after NEMESIS's next boot the new wrapper runs, then stock" "$(md5sum < $P/app_process)|$STK" "$(md5sum < $R/system/bin/app_process.real)|$(chain)" -# the same, then an uninstall before any boot -cp $T/wrapper.older $R/system/bin/app_process.real; cp $P/app_process $R/system/bin/app_process -run $R/data/hmgapi/uninstall.sh -has "... uninstall with no boot between finishes" "HMG-API uninstalled" "$out" -check "... app_process stock" "$STK" "$(md5sum < $R/system/bin/app_process)" -check "... app_process.real stock" "$STK" "$(md5sum < $R/system/bin/app_process.real)" -nemesis_boot -check "... and after NEMESIS's next boot the zygote still starts: stock" "$STK" "$(chain)" -# (e) the brick an older uninstall leaves on NEMESIS 1.17, caught before the next boot: stock over -# NEMESIS's script, .real still a wrapper, app_process.hmgapi-stock gone. Installing this release -# takes the stock bytes from app_process and wraps both -rm -rf $R/data/hmgapi -cp $T/newfw $R/system/bin/app_process; cp $T/wrapper.older $R/system/bin/app_process.real; rm -f $R/system/bin/app_process.hmgapi-stock -check "older uninstall's brick, before the boot: the zygote start would fail" "nothing: $R/system/bin/app_process.hmgapi-stock is gone" "$(nemesis_boot; chain)" -cp $T/newfw $R/system/bin/app_process -run $P/install.sh $P -has "... installing this release finishes" "installed. Restart the head unit" "$out" -check "... stock kept from app_process" "$STK" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)" -nemesis_boot -check "... and after NEMESIS's next boot the zygote start ends at stock" "$STK" "$(chain)" -run $R/data/hmgapi/uninstall.sh -nemesis_boot -check "... an uninstall after that leaves a starting zygote" "$STK" "$(chain)" -rm -f $R/system/bin/app_process.real; cp $T/newfw $R/system/bin/app_process -nemesis_boot - -# (f) #398 review: the wrapper is the same bytes from release to release (rc.7's and rc.8's are this -# one; (d) and (e) use a different older one, which hid this). An older uninstall on NEMESIS 1.17, -# then one restart: NEMESIS's script at app_process, .real this very wrapper, app_process.hmgapi-stock -# gone, /data/hmgapi/stock kept. Not an update: the stock copy comes back from the backup -rm -rf $R/data/hmgapi; cp $T/newfw $R/system/bin/app_process; rm -f $R/system/bin/app_process.real -run $P/install.sh $P; nemesis_boot -cp $T/newfw $R/system/bin/app_process; rm -f $R/system/bin/app_process.hmgapi-stock $R/data/hmgapi/installed.txt # the old uninstall -nemesis_boot # the restart that still works -check "old uninstall + one restart, same wrapper: the next restart would fail" "nothing: $R/system/bin/app_process.hmgapi-stock is gone" "$(chain)" -run $P/install.sh $P -has "... installing this release rebuilds the stock copy" "its stock copy is gone (an older uninstall, #397): putting it back" "$out" -has "... and finishes" "installed. Restart the head unit" "$out" -check "... the stock copy is stock" "$STK" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)" -check "... the backup kept (no firmware reset)" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" -nemesis_boot -check "... after NEMESIS's next boot the zygote start ends at stock" "$STK" "$(chain)" - -# (g) the same with /data/hmgapi purged (uninstall --purge): refused, nothing changed -rm -f $R/system/bin/app_process.hmgapi-stock; rm -rf $R/data/hmgapi -B4=$(tree) -run $P/install.sh $P -has "same, /data/hmgapi purged: refused, pointing at #397" "there's no stock backup to take it from, so nothing was changed" "$out" -has "... names #397" "issues/397" "$out" -check "... /system unchanged" "$B4" "$(tree)" -rm -f $R/system/bin/app_process.real; cp $T/newfw $R/system/bin/app_process; nemesis_boot - -# (h) without NEMESIS: our wrapper at app_process, app_process.hmgapi-stock gone, the backup kept -rm -f $R/system/bin/app_process.real; cp $T/newfw $R/system/bin/app_process; rm -rf $R/data/hmgapi -run $P/install.sh $P -rm -f $R/system/bin/app_process.hmgapi-stock -check "no NEMESIS, wrapper without its stock copy: the next start would fail" "nothing: $R/system/bin/app_process.hmgapi-stock is gone" "$(chain)" -run $P/install.sh $P -has "... installing rebuilds the stock copy" "its stock copy is gone (an older uninstall, #397): putting it back" "$out" -has "... and finishes" "installed. Restart the head unit" "$out" -check "... app_process is still the wrapper (no NEMESIS script written)" "$(md5sum < $P/app_process)" "$(md5sum < $R/system/bin/app_process)" -check "... the zygote start ends at stock" "$STK" "$(chain)" -run $R/data/hmgapi/uninstall.sh -check "... and an uninstall after that gives stock back" "$STK" "$(md5sum < $R/system/bin/app_process)" -nemesis_boot - -# (i) the same as (f) after an rc.5-or-older uninstall: the wrapper left in .real has other bytes -# (it still names app_process.hmgapi-stock, as every version's does). Rescued too, also when -# forced, and never taken for a stock build (#398 review: forcing dropped the stock backup) -w5() { cp $P/app_process $T/w5; printf 'rc.5 /system/bin/app_process.hmgapi-stock\n' >> $T/w5; } -old_uninstall_restart() { # installed under NEMESIS's script, then an rc.5 uninstall, then a restart - rm -rf $R/data/hmgapi; cp $T/newfw $R/system/bin/app_process; rm -f $R/system/bin/app_process.real - run $P/install.sh $P; nemesis_boot - w5; cp $T/w5 $R/system/bin/app_process.real - cp $T/newfw $R/system/bin/app_process; rm -f $R/system/bin/app_process.hmgapi-stock $R/data/hmgapi/installed.txt - nemesis_boot -} -old_uninstall_restart -run $P/install.sh $P -has "rc.5 uninstall + one restart (older wrapper): rebuilds the stock copy" "its stock copy is gone (an older uninstall, #397): putting it back" "$out" -check "... the stock copy is stock" "$STK" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)" -check "... the backup kept" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" -check "... the new wrapper in app_process.real" "$(md5sum < $P/app_process)" "$(md5sum < $R/system/bin/app_process.real)" -nemesis_boot -check "... after NEMESIS's next boot the zygote start ends at stock" "$STK" "$(chain)" -old_uninstall_restart -HMGAPI_FORCE=1 run $P/install.sh $P -has "... forced: rescued the same way" "its stock copy is gone (an older uninstall, #397): putting it back" "$out" -check "... forced: the stock backup kept, not replaced by the wrapper" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" -check "... forced: the stock copy is stock" "$STK" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)" -old_uninstall_restart -rm -rf $R/data/hmgapi -B4=$(tree) -HMGAPI_FORCE=1 run $P/install.sh $P -has "... purged and forced: refused, pointing at #397" "there's no stock backup to take it from, so nothing was changed" "$out" -check "... /system unchanged" "$B4" "$(tree)" -rm -f $R/system/bin/app_process.real; cp $T/newfw $R/system/bin/app_process; nemesis_boot - # (j) a factory reset wipes /data (HMG-API's backups included) while HMG-API stays on /system, no # NEMESIS. Reinstalling the same version: the backup comes from the stock copy, not the wrapper rm -f $R/system/bin/app_process.real; cp $T/newfw $R/system/bin/app_process; rm -rf $R/data/hmgapi @@ -486,191 +313,149 @@ HMGAPI_FORCE=1 run $P/install.sh $P has "stock copy that is a wrapper: refused even forced" "is itself an HMG-API wrapper, so nothing was changed" "$out" check "... /system unchanged" "$B4" "$(tree)" cp $T/newfw $R/system/bin/app_process.hmgapi-stock; run $R/data/hmgapi/uninstall.sh -rm -f $R/system/bin/app_process.real $R/system/bin/app_process.hmgapi-stock; cp $T/newfw $R/system/bin/app_process; rm -rf $R/data/hmgapi; nemesis_boot +rm -f $R/system/bin/app_process.real $R/system/bin/app_process.hmgapi-stock; cp $T/newfw $R/system/bin/app_process; rm -rf $R/data/hmgapi -# (n) NEMESIS 1.17 first, then a release before #396 installed with FORCE (it refused NEMESIS's -# script as an unknown app_process): it kept the script as its stock copy and backup and wrote its -# wrapper over the script. The stock binary is only in .real. rc.9 took that for an update and -# wrote its wrapper over .real: wrapper -> script -> wrapper, no zygote (#397, a Korean K5) -w5; WRAPPERS="$WRAPPERS $(md5sum < $T/w5 | cut -c1-32)" -unset HMGAPI_FORCE # HMGAPI_FORCE=1 run (a function) leaves it set after it in bash 3.2's sh (macOS) -forced_old() { # $1: the stock binary NEMESIS finds - rm -rf $R/data/hmgapi; rm -f $R/system/bin/app_process.real $R/system/bin/app_process.hmgapi-stock - cp "$1" $R/system/bin/app_process; nemesis_boot - mkdir -p $R/data/hmgapi/stock/system/bin $R/data/hmgapi/state - cp $R/system/bin/app_process $R/data/hmgapi/stock/system/bin/app_process - cp $R/system/bin/app_process $R/system/bin/app_process.hmgapi-stock - cp $T/w5 $R/system/bin/app_process - printf 'version 1.0.2\nfile %s /system/bin/app_process\n' "$(md5sum < $T/w5 | cut -c1-32)" > $R/data/hmgapi/installed.txt - echo '{"files": {}, "settings": {}}' > $R/data/hmgapi/state/files.json -} -forced_old $T/newfw -check "forced older install over NEMESIS's script: still starts (wrapper, script, stock)" "$STK" "$(chain)" -check "... its stock copy is NEMESIS's script" "$NLPSUM" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)" -for boot in no yes; do - forced_old $T/newfw; [ $boot = yes ] && nemesis_boot +# Directory preflight: a destination that cannot take a new file must stop the +# installer before hmgapid/lpatch go in (#477). Directory permissions simulate +# read-only mounts without privileged mounts; root skips these checks. +run $R/data/hmgapi/uninstall.sh --purge +for d in bin lib framework etc; do + chmod a-w $R/system/$d + if [ -w $R/system/$d ]; then + chmod u+w $R/system/$d + echo "skip unwritable $d (root can write despite mode bits)" + continue + fi + B4=$(tree) run $P/install.sh $P - has "... (restart since: $boot) this release sees the script" "is NEMESIS LivePatch's script, not stock (an older release installed with FORCE, #397)" "$out" - has "... and finishes" "installed. Restart the head unit" "$out" - check "... not taken for a firmware update (the engine's backups stay)" "" "$(echo "$out" | grep 'a firmware update replaced' || true)" - check "... the stock copy is stock, from .real" "$STK" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)" - check "... the backup is stock" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" - check "... the wrapper is app_process.real" "$(md5sum < $P/app_process)" "$(md5sum < $R/system/bin/app_process.real)" - check "... the zygote start ends at stock" "$STK" "$(chain)" - nemesis_boot - check "... and after NEMESIS's next boot" "$STK" "$(chain)" - run $R/data/hmgapi/uninstall.sh - has "... the uninstall finishes" "HMG-API uninstalled" "$out" - check "... stock in .real, NEMESIS's script at app_process" "$STK|$NLPSUM" "$(md5sum < $R/system/bin/app_process.real)|$(md5sum < $R/system/bin/app_process)" - nemesis_boot - check "... and the zygote still starts" "$STK" "$(chain)" + check "unwritable $d: install fails" 1 $rc + has "... names the destination" "can't write /system/$d" "$out" + check "... /system unchanged" "$B4" "$(tree)" + check "... no install record" no "$([ -f $R/data/hmgapi/installed.txt ] && echo yes || echo no)" + chmod u+w $R/system/$d + rm -rf $R/data/hmgapi done -# the same on a build stock.txt doesn't know (the Korean K5's): refused unless forced, then from .real -{ printf '\177ELF'; head -c 9000 /dev/urandom; } > $T/kfw; chmod 755 $T/kfw; KST=$(md5sum < $T/kfw) -forced_old $T/kfw; nemesis_boot -B4=$(tree) + +# NEMESIS 1.17+ writes this script even without a LivePatch mod. Installing or +# updating HMG-API must refuse before backups, remounts or /system writes, with +# no FORCE escape hatch. Older NEMESIS was covered by the installs above. +NLP='#!/system/bin/sh +# NEMESIS LivePatch: apply patches before the zygote starts, then run the real binary. +exec /system/bin/app_process.real "$@"' +nemesis_boot() { + [ -f $R/system/bin/app_process.real ] || cp $R/system/bin/app_process $R/system/bin/app_process.real + printf '%s\n' "$NLP" > $R/system/bin/app_process +} +STK=$(md5sum < $T/newfw) +# A complete pre-existing install, then NEMESIS: recovery still restores .real. run $P/install.sh $P -has "... unknown build in .real: refused" "app_process.real md5 $(echo $KST | cut -c1-32) isn't a known stock build, so nothing was changed" "$out" -check "... /system unchanged" "$B4" "$(tree)" -HMGAPI_FORCE=1 run $P/install.sh $P; unset HMGAPI_FORCE -has "... forced: installs" "installed. Restart the head unit" "$out" -check "... the stock copy and backup are .real's binary, not the script" "$KST|$KST" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)|$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" +check "setup: installed without LivePatch" 0 $rc nemesis_boot -check "... the zygote start ends at that binary" "$KST" "$(chain)" -# NEMESIS uninstalled since the forced install: its uninstall moved app_process.real back to -# app_process (native/livepatch.c lp_wrapper_remove; usb_bundle/uninstall_nemesis.sh), so the stock -# binary is there, .real is gone, and the stock copy and backup are still the script. Refusing this -# left one way out, the older release's own uninstall, which asks for FORCE and then writes the -# script over app_process with NEMESIS gone: no zygote. Installed again from app_process instead -for build in known unknown; do - if [ $build = known ]; then f=$T/newfw; want=$STK; else f=$T/kfw; want=$KST; fi - forced_old $f; nemesis_boot; mv $R/system/bin/app_process.real $R/system/bin/app_process - check "forced older install, NEMESIS uninstalled since ($build build): still starts (stock at app_process)" "$want" "$(chain)" - if [ $build = unknown ]; then - B4=$(tree) - run $P/install.sh $P - has "... ($build) refused unless forced, naming app_process" "app_process md5 $(echo $want | cut -c1-32) isn't a known stock build, so nothing was changed" "$out" - check "... ($build) /system unchanged" "$B4" "$(tree)" - HMGAPI_FORCE=1 run $P/install.sh $P; unset HMGAPI_FORCE - else - run $P/install.sh $P - fi - has "... ($build) this release sees the script and installs from app_process" "installing again from app_process, the stock binary" "$out" - has "... ($build) and finishes" "installed. Restart the head unit" "$out" - check "... ($build) not taken for a firmware update" "" "$(echo "$out" | grep 'a firmware update replaced' || true)" - check "... ($build) the stock copy and backup are the stock binary" "$want|$want" "$(md5sum < $R/system/bin/app_process.hmgapi-stock)|$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" - check "... ($build) the wrapper is app_process, and no app_process.real was made" "$(md5sum < $P/app_process)|no" "$(md5sum < $R/system/bin/app_process)|$([ -e $R/system/bin/app_process.real ] && echo yes || echo no)" - check "... ($build) the zygote start ends at stock" "$want" "$(chain)" - if [ $build = unknown ]; then - B4=$(tree) - run $R/data/hmgapi/uninstall.sh - has "... ($build) the uninstall refuses an unknown backup, asking for the line" "isn't a known stock build, so nothing was changed and HMG-API is still installed. HMG-API only takes app_process builds it has checked, and this one isn't checked yet. Please open an issue at https://github.com/Open-HMG/HMG-API/issues/new/choose with this line, your car and its head unit software version (e.g. 260507), and we'll help you finish the uninstall." "$out" - check "... ($build) and names no way to force it" "" "$(echo "$out" | grep -i 'HMGAPI_FORCE\|HMGAPI/FORCE' || true)" - check "... ($build) /system unchanged" "$B4" "$(tree)" - export HMGAPI_FORCE=1 # the maintainers' override over adb - fi - run $R/data/hmgapi/uninstall.sh; unset HMGAPI_FORCE - has "... ($build) the uninstall finishes" "HMG-API uninstalled" "$out" - check "... ($build) and gives stock back at app_process" "$want" "$(md5sum < $R/system/bin/app_process)" -done -# what rc.9 left: the wrapper in .real, the stock copy and backup NEMESIS's script. Nothing stock is -# left on the unit: refused even when forced, nothing changed -forced_old $T/kfw; nemesis_boot; cp $P/app_process $R/system/bin/app_process.real -check "rc.9 over a forced older install: no zygote" "nothing: a loop" "$(chain)" -B4=$(tree) -HMGAPI_FORCE=1 run $P/install.sh $P; unset HMGAPI_FORCE -has "... this release refuses, even forced" "is NEMESIS LivePatch's script (an older release installed with FORCE), and app_process.real isn't a stock binary either, so nothing was changed" "$out" -check "... /system unchanged" "$B4" "$(tree)" -# ... and its uninstall doesn't send the owner back to installing: it says no stock app_process is -# left and what that takes (#406 review: the two used to point at each other) -cp $P/uninstall.sh $P/lib.sh $P/stock.txt $R/data/hmgapi/ -HMGAPI_FORCE=1 run $R/data/hmgapi/uninstall.sh; unset HMGAPI_FORCE -has "... the uninstall on that unit: refused, even forced, saying nothing stock is left" "no other stock app_process is left on this unit" "$out" -has "... and that installing again can't help, but the stock file or the firmware can" "Installing HMG-API again can't bring the stock file back. It needs the stock app_process of this exact firmware build" "$out" -check "... not the old advice to install again first" "" "$(echo "$out" | grep 'Install this HMG-API release again first' || true)" -check "... /system unchanged" "$B4" "$(tree)" -# an empty app_process.real (a copy NEMESIS didn't finish) is no stock binary either, forced or not: -# forcing copied its zero bytes into the stock copy and the backup, and put the wrapper over it -forced_old $T/kfw; nemesis_boot; : > $R/system/bin/app_process.real -B4=$(tree) -HMGAPI_FORCE=1 run $P/install.sh $P; unset HMGAPI_FORCE -has "empty app_process.real: refused, even forced" "and app_process.real isn't a stock binary either, so nothing was changed" "$out" -check "... /system unchanged" "$B4" "$(tree)" -# an uninstall never puts NEMESIS's script back as stock, even forced (it would run itself in -# .real): the stock bytes come from the stock copy the wrapper runs -script_backup() { - forced_old $T/newfw; nemesis_boot; cp $P/app_process $R/system/bin/app_process.real; cp $T/newfw $R/system/bin/app_process.hmgapi-stock - cp $P/uninstall.sh $P/lib.sh $P/stock.txt $R/data/hmgapi/; mkdir -p $R/data/hmgapi/hook -} for force in 0 1; do - script_backup - HMGAPI_FORCE=$force run $R/data/hmgapi/uninstall.sh; unset HMGAPI_FORCE - has "uninstall with NEMESIS's script as the backup (FORCE=$force): the stock copy goes back, not the script" "the stock bytes come from /system/bin/app_process.hmgapi-stock instead" "$out" - has "... (FORCE=$force) and it finishes" "HMG-API uninstalled" "$out" - check "... (FORCE=$force) stock in .real, NEMESIS's script at app_process" "$STK|$NLPSUM" "$(md5sum < $R/system/bin/app_process.real)|$(md5sum < $R/system/bin/app_process)" - nemesis_boot - check "... (FORCE=$force) the zygote still starts" "$STK" "$(chain)" + B4=$(tree) + record=$(cat $R/data/hmgapi/installed.txt) + HMGAPI_FORCE=$force run $P/install.sh $P; unset HMGAPI_FORCE + check "LivePatch update (FORCE=$force): refused" 1 $rc + has "... explains incompatibility and recovery" "NEMESIS LivePatch and HMG-API cannot safely run together" "$out" + check "... /system unchanged" "$B4" "$(tree)" + check "... install record unchanged" "$record" "$(cat $R/data/hmgapi/installed.txt)" +done +run $P/uninstall.sh +has "LivePatch: uninstall still works" "HMG-API uninstalled" "$out" +check "... stock binary restored in .real" "$STK" "$(md5sum < $R/system/bin/app_process.real)" +check "... NEMESIS's script preserved" "$NLP" "$(cat $R/system/bin/app_process)" +rm -rf $R/data/hmgapi +for state in normal overwritten missing-real; do + cp $T/newfw $R/system/bin/app_process.real; printf '%s\n' "$NLP" > $R/system/bin/app_process + case $state in + overwritten) cp $P/app_process $R/system/bin/app_process ;; + missing-real) rm $R/system/bin/app_process.real ;; + esac + B4=$(tree); : > $T/nemesis.log + HMGAPI_FORCE=1 run $P/install.sh $P; unset HMGAPI_FORCE + check "LivePatch fresh install ($state): refused even forced" 1 $rc + has "... identifies LivePatch" "NEMESIS LivePatch and HMG-API cannot safely run together" "$out" + check "... /system unchanged" "$B4" "$(tree)" + check "... no backups or install record" no "$([ -e $R/data/hmgapi/stock ] || [ -e $R/data/hmgapi/installed.txt ] && echo yes || echo no)" + check "... no NEMESIS remount attempted" "" "$(cat $T/nemesis.log)" done -script_backup -run $P/install.sh $P -has "... installing again takes the backup again" "app_process backup: NEMESIS LivePatch's script, not stock" "$out" -check "... now stock" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" -run $R/data/hmgapi/uninstall.sh -has "... and then the uninstall finishes" "HMG-API uninstalled" "$out" -nemesis_boot -check "... the zygote still starts" "$STK" "$(chain)" -# (o) #406 review: an install that fails or is cut off while copying the backup. The copy went -# straight to the backup's name, so a short file stayed there; the next install kept it ("once"), -# the uninstall refused it as an unknown build and named HMGAPI_FORCE, and the forced uninstall put -# the short file into app_process.real and removed the stock copy: no zygote -forced_old $T/newfw; nemesis_boot -printf '#!/bin/sh\ncase "$2" in */data/hmgapi/stock/system/bin/app_process*) head -c 16 "$1" > "$2"; exit 1 ;; esac\nexec /bin/cp "$@"\n' > $T/bin/cp; chmod +x $T/bin/cp -B4=$(tree) -run $P/install.sh $P -rm -f $T/bin/cp -has "backup copy fails part-way: the install stops" "FAIL: backup /system/bin/app_process" "$out" -check "... /system unchanged" "$B4" "$(tree)" -check "... and no short file is left as the backup" "" "$(ls $R/data/hmgapi/stock/system/bin/)" -# ... the short file itself, as a release before this left it: taken again from what it's a copy of -head -c 16 $T/newfw > $R/data/hmgapi/stock/system/bin/app_process -run $P/install.sh $P -has "a short backup from an install that was cut off: taken again" "app_process backup: not the bytes of /system/bin/app_process.real (a copy that was cut off?): taking it again" "$out" -has "... and the install finishes" "installed. Restart the head unit" "$out" -check "... the backup is the stock binary" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" -# ... on an update too (the backup is checked against the stock copy the wrapper runs) -head -c 16 $T/newfw > $R/data/hmgapi/stock/system/bin/app_process -run $P/install.sh $P -has "... on an update: taken again from the stock copy" "app_process backup: not the bytes of /system/bin/app_process.hmgapi-stock (a copy that was cut off?): taking it again" "$out" -check "... the backup is the stock binary" "$STK" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" -# ... and the uninstall never puts a short backup back, forced or not: the stock copy goes back -for force in 0 1; do - head -c 16 $T/newfw > $R/data/hmgapi/stock/system/bin/app_process - cp -r $R $T/keep - HMGAPI_FORCE=$force run $R/data/hmgapi/uninstall.sh; unset HMGAPI_FORCE - has "uninstall with a short backup (FORCE=$force): the stock copy goes back" "isn't the bytes of app_process.hmgapi-stock (a copy that was cut off?): the stock bytes come from /system/bin/app_process.hmgapi-stock instead" "$out" - has "... (FORCE=$force) and it finishes" "HMG-API uninstalled" "$out" - check "... (FORCE=$force) stock in .real" "$STK" "$(md5sum < $R/system/bin/app_process.real)" - nemesis_boot - check "... (FORCE=$force) the zygote still starts" "$STK" "$(chain)" - [ $force = 1 ] || { rm -rf $R; mv $T/keep $R; } +# Package recovery of the exact partial install from #477, using real uninstall +# code and a NEMESIS stub that requires the recovery-only remount flag. A .real +# stock binary and untouched boot scripts must stay byte-identical. +cp $R/system/xbin/nemesis $T/nemesis.old +cat > $R/system/xbin/nemesis <<'NEM' +#!/bin/sh +echo "$*" >> "$ROOT/remount.log" +case "$*" in + 'remount rw --bypass-livepatch') [ "$OLD_NEMESIS" != 1 ] ;; + 'remount rw') [ "$OLD_NEMESIS" = 1 ] ;; + 'remount ro') exit 0 ;; + *) exit 1 ;; +esac +NEM +chmod +x $R/system/xbin/nemesis +partial_install() { + rm -rf $R/data/hmgapi + mkdir -p $R/data/hmgapi/stock/system/bin $R/data/hmgapi/hook + cp $T/newfw $R/system/bin/app_process.real + printf '%s\n' "$NLP" > $R/system/bin/app_process + cp $T/newfw $R/data/hmgapi/stock/system/bin/app_process + cp $P/hmgapid $R/system/bin/hmgapid; cp $P/lpatch $R/system/bin/lpatch + : > $R/remount.log +} +REPO=$PWD +# The existing P already is the payload; give the package a payload/ beside scripts. +PKG=$T/package; mkdir -p $PKG; ln -s $P $PKG/payload +# Use an absolute script path; the package's current directory selects its payload. +preuninstall() { + set +e + out=$(cd $PKG && env PATH="$T/bin:$PATH" ROOT=$R CAPCHECK=0 HMGAPI_TEST_REMOUNT=1 $SH "$REPO/install/nemesis/scripts/preuninstall.sh" 2>&1) + rc=$?; set -e +} +for old in 0 1; do + partial_install; export OLD_NEMESIS=$old + IR=$(md5sum < $R/system/etc/install-recovery.sh); QB=$(md5sum < $R/system/etc/qb_runtime.sh) + preuninstall + check "partial install (old NEMESIS=$old): package uninstall succeeds" 0 $rc + has "... identifies incomplete install" "install is incomplete" "$out" + check "... daemon and patcher removed" no "$([ -e $R/system/bin/hmgapid ] || [ -e $R/system/bin/lpatch ] && echo yes || echo no)" + check "... stock .real preserved" "$STK" "$(md5sum < $R/system/bin/app_process.real)" + check "... LivePatch script preserved" "$NLP" "$(cat $R/system/bin/app_process)" + check "... boot scripts untouched" "$IR|$QB" "$(md5sum < $R/system/etc/install-recovery.sh)|$(md5sum < $R/system/etc/qb_runtime.sh)" + has "... bypass requested for recovery" "remount rw --bypass-livepatch" "$(cat $R/remount.log)" + has "... ordinary ro remount restores farms" "remount ro" "$(cat $R/remount.log)" done -rm -rf $T/keep -# (p) another tool's script at app_process (not NEMESIS's, no .real): never kept as the stock copy, -# forced or not. It would work until that tool rewrote or removed its script -rm -rf $R/data/hmgapi; rm -f $R/system/bin/app_process.real $R/system/bin/app_process.hmgapi-stock -printf '#!/system/bin/sh\n# some other tool\nexec /system/bin/app_process.orig "$@"\n' > $R/system/bin/app_process -B4=$(tree) -HMGAPI_FORCE=1 run $P/install.sh $P; unset HMGAPI_FORCE -has "another tool's script at app_process: refused, even forced" "isn't a stock binary (an HMG-API wrapper, NEMESIS LivePatch's script, another script or an empty file)" "$out" +unset OLD_NEMESIS +for bad in missing script truncated unknown; do + partial_install + case $bad in + missing) rm $R/data/hmgapi/stock/system/bin/app_process ;; + script) printf '%s\n' "$NLP" > $R/data/hmgapi/stock/system/bin/app_process; cp $P/app_process $R/system/bin/app_process.real ;; + truncated) head -c 16 $T/newfw > $R/data/hmgapi/stock/system/bin/app_process ;; + unknown) printf '\177ELFunknown' > $R/data/hmgapi/stock/system/bin/app_process ;; + esac + B4=$(tree); preuninstall + check "partial recovery with $bad backup: fails (package must stay)" 1 $rc + check "... /system unchanged" "$B4" "$(tree)" + check "... no remount before validation" "" "$(cat $R/remount.log)" +done +partial_install; mv $PKG/payload $PKG/payload.away +B4=$(tree); preuninstall +check "partial recovery without package payload: fails" 1 $rc check "... /system unchanged" "$B4" "$(tree)" -rm -f $R/system/bin/app_process.real $R/system/bin/app_process.hmgapi-stock; cp $T/newfw $R/system/bin/app_process; rm -rf $R/data/hmgapi; nemesis_boot - -# (c) NEMESIS's script with no app_process.real: refused, nothing changed -rm -f $R/system/bin/app_process.real; rm -rf $R/data/hmgapi -B4=$(tree) -run $P/install.sh $P -has "NEMESIS's script without app_process.real refused" "app_process.real, the binary it runs, is missing, so nothing was changed" "$out" +mv $PKG/payload.away $PKG/payload +rm -f $R/system/bin/hmgapid $R/system/bin/lpatch; rm -rf $R/data/hmgapi +B4=$(tree); preuninstall +check "no installation: package uninstall is a no-op" 0 $rc check "... /system unchanged" "$B4" "$(tree)" -cp $T/wrapper.old $P/app_process +# Registered packages have no payload; a complete install uses the on-unit script. +rm -f $R/system/bin/app_process.real; cp $T/newfw $R/system/bin/app_process +cp $T/nemesis.old $R/system/xbin/nemesis +run $P/install.sh $P +mv $PKG/payload $PKG/payload.away +preuninstall +check "registered package: on-unit uninstall works" 0 $rc +check "... stock app_process restored" "$STK" "$(md5sum < $R/system/bin/app_process)" +mv $PKG/payload.away $PKG/payload exit $fail diff --git a/install/common/install.sh b/install/common/install.sh index bc889914..7d99af3f 100644 --- a/install/common/install.sh +++ b/install/common/install.sh @@ -76,6 +76,14 @@ backup() { capcheck log "HMG-API $VERSION install $(date)" +# LivePatch and HMG-API both own the zygote and patched system files. A writable +# LivePatch farm does not make coexistence safe (#477). Also catch an older +# HMG-API that overwrote NEMESIS's script but left the binary it runs in .real. +# Refuse updates too, even with FORCE; uninstall remains available for recovery. +if nemesis_livepatch || { [ -x "$ROOT/system/xbin/nemesis" ] && [ -e "$ROOT/system/bin/app_process.real" ]; }; then + fail "NEMESIS LivePatch and HMG-API cannot safely run together. Installation and updates are blocked; nothing on /system was changed. To remove an existing or incomplete HMG-API installation, use the uninstall option. See https://github.com/Open-HMG/HMG-API/issues/477" +fi + # the payload is whole while read m f; do [ -n "$f" ] || continue @@ -257,6 +265,16 @@ backup /system/etc/qb_runtime.sh remount rw || fail "can't remount /system rw (needs NEMESIS or a running hmgapid)" REMOUNTED=1 +# Check every destination before putting any runtime files on /system. A +# successful remount alone does not prove that each directory accepts writes. +for d in /system/bin /system/lib /system/framework /system/etc; do + t=$ROOT$d/.hmgapi-write-test-$$ + if (set -C; : > "$t") 2>/dev/null; then + rm -f "$t" || fail "can't remove the write check in $d; no runtime files were installed" + else + fail "can't write $d; no runtime files were installed on /system. See https://github.com/Open-HMG/HMG-API/issues/477" + fi +done put hmgapid /system/bin/hmgapid 755 shell put lpatch /system/bin/lpatch 755 shell put libhmgapi_hook.so /system/lib/libhmgapi_hook.so 644 root diff --git a/install/common/uninstall.sh b/install/common/uninstall.sh index 4b9ac981..979e8d11 100644 --- a/install/common/uninstall.sh +++ b/install/common/uninstall.sh @@ -16,8 +16,16 @@ ROOT=${ROOT:-} D=$ROOT/data/hmgapi LOG=$D/install.log remount() { - [ -n "$ROOT" ] && return 0 - if [ -x /system/xbin/nemesis ] && nemesis remount "$1" >/dev/null 2>&1; then return 0; fi + [ -n "$ROOT" ] && [ "$HMGAPI_TEST_REMOUNT" != 1 ] && return 0 + # Recovery only: take down LivePatch's read-only farms to remove HMG-API. + # Installing alongside LivePatch is refused, regardless of remount support. + if [ -x "$ROOT/system/xbin/nemesis" ]; then + if [ "$1" = rw ]; then + "$ROOT/system/xbin/nemesis" remount rw --bypass-livepatch >/dev/null 2>&1 && return 0 + fi + "$ROOT/system/xbin/nemesis" remount "$1" >/dev/null 2>&1 && return 0 + fi + [ -n "$ROOT" ] && return 1 $ROOT/system/bin/hmgapid remount "$1" >/dev/null 2>&1 && return 0 mount -o remount,"$1" /system >/dev/null 2>&1 # works in the DSP OTA's process (USB uninstall) } diff --git a/install/nemesis/scripts/preuninstall.sh b/install/nemesis/scripts/preuninstall.sh index 2805d36b..34d79636 100644 --- a/install/nemesis/scripts/preuninstall.sh +++ b/install/nemesis/scripts/preuninstall.sh @@ -22,6 +22,25 @@ case $caller in exit 0 fi ;; esac -[ -f "${ROOT:-}/data/hmgapi/installed.txt" ] && [ -f "${ROOT:-}/data/hmgapi/uninstall.sh" ] || { echo "HMG-API isn't installed"; exit 0; } export HMGAPI_FROM_NEMESIS=1 # uninstall.sh: NEMESIS is unlisting it already, no NEMESIS sync -exec sh "${ROOT:-}/data/hmgapi/uninstall.sh" +if [ -f "${ROOT:-}/data/hmgapi/installed.txt" ] && [ -f "${ROOT:-}/data/hmgapi/uninstall.sh" ]; then + # Prefer this package's recovery code, including the LivePatch remount fix. + [ -f ./payload/uninstall.sh ] && exec sh ./payload/uninstall.sh + exec sh "${ROOT:-}/data/hmgapi/uninstall.sh" +fi +# #477: copying the hook library failed after hmgapid and lpatch were installed, +# before installed.txt and the on-unit uninstaller existed. Use the package's +# uninstaller: it validates the stock binary before touching /system and keeps +# NEMESIS's zygote script. A failure must keep the package listed for recovery. +if [ -e "${ROOT:-}/system/bin/hmgapid" ] || [ -e "${ROOT:-}/system/bin/lpatch" ] \ + || [ -e "${ROOT:-}/system/bin/app_process.hmgapi-stock" ] \ + || [ -f "${ROOT:-}/data/hmgapi/installed.txt" ]; then + if [ -f ./payload/uninstall.sh ] && [ -s "${ROOT:-}/data/hmgapi/stock/system/bin/app_process" ]; then + echo "HMG-API's install is incomplete: removing it with the package's uninstaller" + exec sh ./payload/uninstall.sh + fi + echo "HMG-API files remain, but the recovery uninstaller or stock backup is missing. Nothing was removed. See https://github.com/Open-HMG/HMG-API/issues/477" + exit 1 +fi +echo "HMG-API isn't installed" +exit 0 diff --git a/install/nemesis/sync-test.sh b/install/nemesis/sync-test.sh index 1d6f4762..d9425684 100644 --- a/install/nemesis/sync-test.sh +++ b/install/nemesis/sync-test.sh @@ -193,8 +193,13 @@ D=$R/data/nemesis/apps/hmgapi o=$(cd $D && env HMGAPI_NEMESIS_SYNC=1 ROOT=$R $SH scripts/preuninstall.sh 2>&1) has "HMG-API's preuninstall, list-only: does nothing" "list only, nothing uninstalled" "$o" rm $R/data/hmgapi/installed.txt +set +e; o=$(cd $D && env ROOT=$R $SH scripts/preuninstall.sh uninstall 2>&1); r=$?; set -e +check "... daemon without installed.txt or recovery payload: refuses to unlist" 1 $r +has "... explains that recovery is needed" "HMG-API files remain" "$o" +mv $R/system/bin/hmgapid $T/hmgapid.keep o=$(cd $D && env ROOT=$R $SH scripts/preuninstall.sh uninstall 2>&1) has "... uninstalled already (uninstall.sh left in /data/hmgapi): nothing to do" "HMG-API isn't installed" "$o" +mv $T/hmgapid.keep $R/system/bin/hmgapid set +e; o=$(cd $D && env ROOT=$R $SH scripts/postinstall.sh 2>&1); r=$?; set -e has "a listing package without HMG-API installed: says to install HMG-API" "isn't installed: install HMG-API's own download" "$o" check "... and fails" 1 $r diff --git a/install/usb/test.sh b/install/usb/test.sh old mode 100755 new mode 100644 index a78605a7..8d3df3ec --- a/install/usb/test.sh +++ b/install/usb/test.sh @@ -184,4 +184,38 @@ rm $R/data/local/tmp/nemesis/stage/hmgapi/NEMESIS.data # left over from an int CWD=$A; run scripts/preuninstall.sh; CWD= has "NEMESIS uninstall: uninstalled (a leftover stage doesn't stop it)" "HMG-API uninstalled" "$out" check "/system byte-identical to stock again" "$BEFORE" "$(tree)" +# #477: USB recovery must work without installed.txt or the on-unit uninstaller. +NLP='#!/system/bin/sh +# NEMESIS LivePatch: apply patches before the zygote starts, then run the real binary. +exec /system/bin/app_process.real "$@"' +cp $R/system/bin/app_process $R/system/bin/app_process.real +printf '%s\n' "$NLP" > $R/system/bin/app_process +rm -rf $R/data/hmgapi +mkdir -p $R/data/hmgapi/stock/system/bin $R/data/hmgapi/hook +cp $R/system/bin/app_process.real $R/data/hmgapi/stock/system/bin/app_process +cp $P/hmgapid $R/system/bin/hmgapid; cp $P/lpatch $R/system/bin/lpatch +B4=$(tree) +run $TS +check "LivePatch: stick install refuses" 1 $rc +has "... explains incompatibility in the stick log" "NEMESIS LivePatch and HMG-API cannot safely run together" "$(cat $S/HMGAPI/install.log)" +check "... /system unchanged" "$B4" "$(tree)" +: > $S/HMGAPI/UNINSTALL +run $TS +check "partial install: USB uninstall succeeds" 0 $rc +has "... recovery log copied to the stick" "HMG-API uninstalled" "$(cat $S/HMGAPI/install.log)" +check "... daemon and patcher removed" no "$([ -e $R/system/bin/hmgapid ] || [ -e $R/system/bin/lpatch ] && echo yes || echo no)" +check "... NEMESIS script preserved" "$NLP" "$(cat $R/system/bin/app_process)" +check "... stock .real preserved" "$(md5sum < $R/data/hmgapi/stock/system/bin/app_process)" "$(md5sum < $R/system/bin/app_process.real)" +check "... recovery staging removed" no "$([ -e $R/data/local/tmp/hmgapi-usb ] && echo yes || echo no)" +cp $P/hmgapid $R/system/bin/hmgapid +rm $R/data/hmgapi/stock/system/bin/app_process +B4=$(tree); run $TS +check "partial install without backup: USB recovery fails" 1 $rc +check "... /system unchanged" "$B4" "$(tree)" +mv $P $P.away +run $TS +check "partial install without recovery payload: refuses" 1 $rc +has "... asks for the full download" "recovery payload is missing" "$out" +check "... /system unchanged" "$B4" "$(tree)" +mv $P.away $P exit $fail diff --git a/install/usb/troubleShooter b/install/usb/troubleShooter old mode 100755 new mode 100644 index a65670ed..3998d899 --- a/install/usb/troubleShooter +++ b/install/usb/troubleShooter @@ -8,8 +8,11 @@ # HMGAPI/UNINSTALL uninstall instead (HMGAPI/UNINSTALL-PURGE: also /data/hmgapi) # Copies its log to HMGAPI/install.log, shows the result, and restarts the unit. # Toolbox and mksh only: the unit has no busybox. ROOT and HMGAPI_USB_DIRS: off-car tests. -export PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin${PATH:+:$PATH} -export LD_LIBRARY_PATH=/vendor/lib:/system/lib +# ROOT is an off-car test tree: keep its tool stand-ins ahead of the host tools. +if [ -z "${ROOT:-}" ]; then + export PATH=/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin${PATH:+:$PATH} + export LD_LIBRARY_PATH=/vendor/lib:/system/lib +fi umask 077 ROOT=${ROOT:-} STAGE=$ROOT/data/local/tmp/hmgapi-usb @@ -55,17 +58,32 @@ fi # stick file back, uncomment this line and the one in install/nemesis/scripts/postinstall.sh #[ -f "$U/HMGAPI/FORCE" ] && export HMGAPI_FORCE=1 if [ -f "$U/HMGAPI/UNINSTALL" ] || [ -f "$U/HMGAPI/UNINSTALL-PURGE" ]; then - if [ ! -f "$ROOT/data/hmgapi/uninstall.sh" ]; then + UNINSTALL=$ROOT/data/hmgapi/uninstall.sh + P=$U/HMGAPI/install/payload + # A failed install (#477) can leave binaries without an on-unit uninstaller. + # Prefer the stick's current recovery code for both full and partial installs. + if [ -f "$ROOT/data/hmgapi/installed.txt" ] || [ -e "$ROOT/system/bin/hmgapid" ] \ + || [ -e "$ROOT/system/bin/lpatch" ] || [ -e "$ROOT/system/bin/app_process.hmgapi-stock" ]; then + if [ -f "$P/uninstall.sh" ] && [ -f "$P/lib.sh" ] && [ -s "$P/stock.txt" ]; then + rm -r "$STAGE" 2>/dev/null + mkdir -p "${STAGE%/*}" && cp -r "$P" "$STAGE" || { toast "HMG-API: can't copy the recovery payload. Nothing was changed."; finish 1; } + UNINSTALL=$STAGE/uninstall.sh + elif [ ! -f "$UNINSTALL" ]; then + toast "HMG-API files remain, but the recovery payload is missing. Copy the complete HMG-API download to this stick. Nothing was changed." + finish 1 + fi + fi + if [ ! -f "$UNINSTALL" ]; then toast "HMG-API isn't installed. Nothing was changed." finish 1 fi toast "HMG-API: uninstalling..." PURGE= [ -f "$U/HMGAPI/UNINSTALL-PURGE" ] && PURGE=--purge - sh "$ROOT/data/hmgapi/uninstall.sh" $PURGE > "$STAGE.log" 2>&1 + sh "$UNINSTALL" $PURGE > "$STAGE.log" 2>&1 rc=$? cp "$STAGE.log" "$U/HMGAPI/install.log" 2>/dev/null - rm -f "$STAGE.log" + rm -rf "$STAGE"; rm -f "$STAGE.log" if [ $rc = 0 ]; then toast "HMG-API uninstalled, restarting." elif grep -q "isn't a known stock build" "$U/HMGAPI/install.log" 2>/dev/null; then toast "$UNKNOWN_TOAST" else toast "HMG-API uninstall failed: see HMGAPI/install.log on the stick."; fi diff --git a/maps/authors.json b/maps/authors.json index d0deef38..46383a29 100644 --- a/maps/authors.json +++ b/maps/authors.json @@ -25,6 +25,12 @@ "https://github.com/lemoyneiv/hmgapi-comfort", "https://github.com/lemoyneiv/hmgapi-tile-manager" ] + }, + "49624245-2eef-8b12-b385-823361d61309": { + "name": "zpoon", + "repos": [ + "https://github.com/zpoon/gen5w-BatteryWatchdog" + ] } } } diff --git a/wiki/Supported-cars.md b/wiki/Supported-cars.md index 02817589..ff0085e1 100644 --- a/wiki/Supported-cars.md +++ b/wiki/Supported-cars.md @@ -17,14 +17,9 @@ the parts that change the car's own apps stay off, and the app says which. | Kia Telluride | USA | 260507 | made on an owner's car by HMG-API's own mapper (351 of 351 hook points); waiting for a check on a car | | Kia Niro EV | USA | 260507 | made on 3 owners' cars by HMG-API's own mapper (343 of 351 hook points: the 8 newest need a Car Report from 1.1.0 or newer); waiting for a check on a car | | Kia Carnival | USA | 260507 | made on an owner's car by HMG-API's own mapper (343 of 351 hook points: the 8 newest need a Car Report from 1.1.0 or newer); waiting for a check on a car | -<<<<<<< HEAD +| Hyundai Palisade | USA | 260507 | 351 of 391 hook points: original 343 checked on the owner's car; eight more resolved off-car; 40 newer points need mapping; status remains mapped, pending a current vehicle check | | Hyundai Palisade | USA | 260903 | made on an owner's car by HMG-API's own mapper (351 of 391 hook points, from an rc.3 Car Report, #54: the 40 newest need a Car Report from 1.1.0-rc.5 or newer); waiting for a check on a car | | Hyundai Ioniq 6 | Canada and USA | 260206 | ✅ checked on a Canadian car (351 hook points), from a Car Report and stock Bluetooth settings files; all 391 from rc.5 Car Reports of a Canadian and a US car, which agree (#354, #319) | -======= -| Hyundai Palisade | USA | 260507 | 351 of 391 hook points: original 343 checked on the owner's car; eight more resolved off-car; 40 newer points need mapping; status remains mapped, pending a current vehicle check | -| Hyundai Palisade | USA | 260903 | made on an owner's car by HMG-API's own mapper (343 of 351 hook points: the 8 newest need a Car Report from 1.1.0 or newer); waiting for a check on a car | -| Hyundai Ioniq 6 | Canada and USA | 260206 | ✅ checked on a Canadian car (351 of 351 hook points), from a Car Report and stock Bluetooth settings files; a US car on 260206 has the same 18 stock files (#319) | ->>>>>>> origin/main | Hyundai Ioniq 6 | USA | 260507 | all 351 hook points, from stock files and an rc.3 Car Report (#253); waiting for a check on a car | | Hyundai Elantra (and Hybrid), Sonata (and Hybrid), Santa Fe (and Hybrid, Plug-in Hybrid), Kona, Kona Electric, Ioniq (Electric, Hybrid, Plug-in Hybrid), Venue, Veloster N, Palisade 2020-22 | USA | 260507 | 351 of 351 hook points found in stock files; waiting for a check on a car | | Kia K5, Sorento (and Hybrid, Plug-in Hybrid), Stinger, Soul, Seltos 2021, Niro 2020-22 (EV, Hybrid, Plug-in Hybrid), Cadenza, Telluride 2020-21 | USA | 260507 | 351 of 351 hook points found in stock files; waiting for a check on a car |