Skip to content
Open
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

- **One install or uninstall at a time.** The USB stick carried both the Engineering Mode
install and a `NEMESIS.data`, so on a unit with NEMESIS both could start the same install at
once, each swapping `app_process`. `install.sh` and `uninstall.sh` now take a lock first
(`/dev/.hmgapi-install`, gone at every restart, taken over when its holder has ended) and
refuse with "another HMG-API install or uninstall is running" while it's held. The stick no
longer has a `NEMESIS.data` or the NEMESIS package (HMG-API isn't installed alongside NEMESIS).

## 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
Expand Down
1 change: 1 addition & 0 deletions install/common/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ backup() {
}

capcheck
install_lock
log "HMG-API $VERSION install $(date)"

# the payload is whole
Expand Down
24 changes: 24 additions & 0 deletions install/common/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ HOOK_END="# HMGAPI_HOOK end"
log() { echo "$1"; echo "$1" >> "$LOG" 2>/dev/null; }
sum() { set -- $(md5 "$1" 2>/dev/null); echo "$1"; }

# One install or uninstall at a time. The USB stick can start one (Engineering Mode's DSP
# OTA) while NEMESIS offers the same package from it, and the app, adb and NEMESIS packages
# all call these scripts too. A folder on tmpfs (/dev): a run cut off by a power loss never
# blocks the next boot. Its pid file names the holder; one that's gone (that pid is no
# longer one of these scripts) is taken over. Given back when the script exits, however.
INSTALL_LOCK=$ROOT/dev/.hmgapi-install
install_lock() {
local p
[ -z "$ROOT" ] || mkdir -p "$ROOT/dev"
if ! mkdir "$INSTALL_LOCK" 2>/dev/null; then
p=$(cat "$INSTALL_LOCK/pid" 2>/dev/null)
# no pid yet: its holder may be between its mkdir and writing the pid; read it again
[ -n "$p" ] || { sleep 1; p=$(cat "$INSTALL_LOCK/pid" 2>/dev/null); }
if [ -n "$p" ] && [ "$p" != $$ ] && grep -q -e install.sh -e troubleShooter "/proc/$p/cmdline" 2>/dev/null; then
log "FAIL: another HMG-API install or uninstall is running (pid $p). Nothing was changed: wait for it to finish."
exit 1
fi
rm -rf "$INSTALL_LOCK"
mkdir "$INSTALL_LOCK" 2>/dev/null || { log "FAIL: another HMG-API install or uninstall just started. Nothing was changed: wait for it to finish."; exit 1; }
fi
echo $$ > "$INSTALL_LOCK/pid"
trap 'rm -rf "$INSTALL_LOCK"' EXIT
}

# NEMESIS 1.17's LivePatch puts its own shell script at /system/bin/app_process (its watchdog
# writes it again on every boot, LivePatch package or not) and runs app_process.real, which
# holds whatever binary it found there first: stock, or HMG-API's wrapper. Under that script
Expand Down
38 changes: 38 additions & 0 deletions install/common/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,44 @@ echo 999999 > "$D/state/hook-check.pid"
HC > /dev/null
check "hook-check: a stale lock (after a restart) doesn't stop it" "1" "$(grep -c 'HMGAPI_HOOK begin' "$T/system/etc/install-recovery.sh")"

# install_lock (lib.sh): one install or uninstall at a time
L="$T/dev/.hmgapi-install"
IL() { env ROOT="$T" LOG="$T/lock.log" $SH -c ". $PWD/lib.sh; install_lock; $1"; }
rm -rf "$L"
IL "echo held \$(cat $L/pid)" > "$T/lock.out" && r=0 || r=$?
check "install_lock: free: taken" "0 yes" "$r $(grep -q '^held [0-9]' "$T/lock.out" && echo yes)"
check "... and given back when the script exits" "no" "$([ -d "$L" ] && echo yes || echo no)"
printf 'sleep 5\n' > "$T/install.sh"
$SH "$T/install.sh" & hp=$!
sleep 0.3
if grep -q install.sh /proc/$hp/cmdline 2>/dev/null; then
mkdir -p "$L"; echo $hp > "$L/pid"
IL "echo got in" > "$T/lock.out" && r=0 || r=$?
check "install_lock: another install running: refused" "1" "$r"
check "... saying so, and nothing ran" "yes no" "$(grep -q 'another HMG-API install or uninstall is running' "$T/lock.out" && echo yes) $(grep -q 'got in' "$T/lock.out" && echo yes || echo no)"
check "... its lock left alone" "$hp" "$(cat "$L/pid")"
else
echo "skip install_lock: another install running (no /proc here)"
fi
kill $hp 2>/dev/null || true; wait $hp 2>/dev/null || true
mkdir -p "$L"; echo 999999 > "$L/pid"
IL "echo got in" > "$T/lock.out" && r=0 || r=$?
check "install_lock: a holder that's gone (a run cut off): taken over" "0 yes" "$r $(grep -q 'got in' "$T/lock.out" && echo yes)"
if [ -d /proc/self ]; then
# just taken by another run that hasn't written its pid yet: read again, then refused
printf 'sleep 5\n' > "$T/install.sh"; $SH "$T/install.sh" & hp=$!
rm -rf "$L"; mkdir -p "$L"; (sleep 0.3; echo $hp > "$L/pid") &
IL "echo got in" > "$T/lock.out" && r=0 || r=$?
check "install_lock: taken a moment ago, no pid yet: read again, refused" "1 no" "$r $(grep -q 'got in' "$T/lock.out" && echo yes || echo no)"
kill $hp 2>/dev/null || true; wait 2>/dev/null || true
else
echo "skip install_lock: taken a moment ago (no /proc here)"
fi
mkdir -p "$L"; echo $$ > "$L/pid"
IL "echo got in" > "$T/lock.out" && r=0 || r=$?
check "install_lock: its pid now another process (not an installer): taken over" "0" "$r"
rm -rf "$L"

# boot.sh: an apply that was cut off (or a trial) is rolled back, then one restart. A
# recover that fails part-way keeps its journal, so restarting on it would loop.
mkdir -p "$T/system/bin"
Expand Down
1 change: 1 addition & 0 deletions install/common/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ capcheck() {
exit 1
}
capcheck
install_lock
log "HMG-API uninstall $(date)"

# the zygote binaries the install wrapped: app_process unless it's NEMESIS 1.17's LivePatch script,
Expand Down
6 changes: 3 additions & 3 deletions install/usb/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ A. The head unit has nothing installed yet (no NEMESIS):
3. Messages show "HMG-API ... installing", then "HMG-API installed, restarting".
The OTA screen then shows error 684. That's expected: nothing is undone.

B. NEMESIS is installed: plug the stick in once Android is up and confirm the
install of "HMG-API".
B. NEMESIS is installed: HMG-API isn't installed alongside NEMESIS. This build
has no way to install on a unit with NEMESIS yet.

C. HMG-API is installed: the HMG-API app offers the update from HMGAPI/updates.
That folder also holds the mods (install them from the app).
Expand All @@ -23,7 +23,7 @@ backups). Every change HMG-API or its mods made goes back to stock.
The result is written to HMGAPI/install.log on the stick.

Take the stick out afterwards: with it in, the head unit can try to start
wired Android Auto, and NEMESIS offers the install again.
wired Android Auto.

Only for the cars and firmware HMG-API supports (see the compatibility page).
On anything else HMG-API stays off and says why.
11 changes: 5 additions & 6 deletions install/usb/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ has() { case "$3" in *"$2"*) echo "ok $1" ;; *) echo "FAIL $1: wanted [$2] i
# whose own NEMESIS.data names them
ini() { unzip -p "$1" "$2" | grep "^$3=" | head -1 | cut -d= -f2-; }
relok() { case "$1" in ''|/*|*..*|*[\;\|\&\`\$\'\"\(\)\<\>]*) echo no ;; *) echo yes ;; esac; }
# the USB stick: the DSP OTA route only. NEMESIS reading a NEMESIS.data on it would offer the same
# package while the DSP route runs: two installs at once
n=${UZ##*/}
check "$n: NEMESIS.data says install" install "$(ini "$UZ" NEMESIS.data type)"
rel=$(ini "$UZ" NEMESIS.data path)
check "$n: path= is one NEMESIS takes ($rel)" yes "$(relok "$rel")"
check "$n: path= is in the zip" "$rel" "$(unzip -Z1 "$UZ" | grep -x "$rel" || true)"
unzip -p "$UZ" "$rel" > $T/inner.zip
check "$n: the package it installs is HMG-API's" hmgapi "$(ini $T/inner.zip NEMESIS.data id)"
check "$n: no NEMESIS.data (NEMESIS doesn't offer a second install)" "" "$(unzip -Z1 "$UZ" | grep -x NEMESIS.data || true)"
check "$n: no NEMESIS package on it" "" "$(unzip -Z1 "$UZ" | grep -x HMGAPI/install/hmgapi.zip || true)"
check "$n: the DSP OTA entry and the payload" "HMGAPI/install/payload/install.sh ota_package.tar" "$(unzip -Z1 "$UZ" | grep -x -e ota_package.tar -e HMGAPI/install/payload/install.sh | LC_ALL=C sort | tr '\n' ' ' | sed 's/ $//')"
# the NEMESIS download: a Package Store list (type=list, NEMESIS 1.16; StoreList.parseList):
# [package.0], [package.1], ... with no gaps, each a path= to a package on the stick, HMG-API first
n=${NB##*/}
Expand Down
7 changes: 3 additions & 4 deletions tools/mkinstallers.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh
# Make HMG-API's install downloads in out/dist/:
# hmgapi-<v>-usb.zip a USB stick: DSP OTA (nothing installed yet), NEMESIS
# (NEMESIS.data type=install) and the app (HMGAPI/updates)
# hmgapi-<v>-usb.zip a USB stick: DSP OTA (install, update, uninstall) and the app
# (HMGAPI/updates). No NEMESIS.data: NEMESIS offering the same
# package from the stick could start a second install at once
# hmgapi-<v>-nemesis.zip for NEMESIS 1.16 or newer: unzipped onto a stick, its
# NEMESIS.data (type=list) opens NEMESIS's Package Store on
# packages/hmgapi.zip (the package itself, NEMESIS.data
Expand Down Expand Up @@ -92,8 +93,6 @@ with tarfile.open(sys.argv[2], "w", format=tarfile.GNU_FORMAT) as t:
t.addfile(i, io.BytesIO(data))
PY
cp -r out/payload "$U/HMGAPI/install/payload"
cp "$W/hmgapi.zip" "$U/HMGAPI/install/hmgapi.zip"
printf '[nemesis]\nversion=1.0\ntype=install\npath=HMGAPI/install/hmgapi.zip\n' > "$U/NEMESIS.data"
RK=${HMGAPI_RELEASE_KEY:-$HOME/hmg-private/keys/leafia-release.key}
if [ -f "$RK" ]; then
cp "$(tools/mkrelease.sh "$RK" | tail -1)" "$U/HMGAPI/updates/"
Expand Down