Files
emulator-tools/install.sh
T
irisandClaude Opus 5 5d77599f3f Collect the emulator tooling into one repo
ui-trace, the adb wrapper and its device recorder were loose files under
~/.local, and each Android checkout carried its own copy of the same
emulator boot sequence. This puts them together, with an install script that
symlinks them back so editing the repo is editing what runs.

Two things are new rather than moved. `emu` is the emulator lifecycle --
name, serial, list, up, down -- keyed on the AVD named after the enclosing
checkout, which is the rule that lets several sessions work here at once;
and `adb` now fills in `-s` from that same rule, because with two emulators
attached a bare `adb shell pm list packages` comes back empty rather than
failing, which reads as the app being uninstalled rather than the question
being ambiguous.

`emu up` refuses when the machine has no room. On 2026-08-30 an emulator
started with 2.8 GB available invoked the OOM killer, and what it took was
not the emulator that had just started: it walked the user slice and killed
pipewire, dbus-broker and another session's emulator first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-30 13:06:17 -04:00

56 lines
2.2 KiB
Bash
Executable File

#!/bin/sh
# Puts these tools where a shell and an agent will find them, by symlink.
#
# Symlinks rather than copies so that editing the repo is editing what runs --
# the alternative is a second copy that drifts, which is exactly what this
# repo was made to end (ui-trace, the adb wrapper and three near-identical
# emulator boot sequences all lived in different places).
#
# Idempotent: run it again after a pull, or after adding a command.
set -eu
here=$(cd "$(dirname "$0")" && pwd)
bindir=${BINDIR:-$HOME/.local/bin}
sharedir=${SHAREDIR:-$HOME/.local/share}
mkdir -p "$bindir" "$sharedir"
for target in "$here"/bin/*; do
name=$(basename "$target")
link="$bindir/$name"
# A real file here is the pre-repo copy of one of these tools. Kept, once,
# under .bak: it is somebody's working state until they have looked at it,
# and a tool that silently deletes the thing it replaces is one nobody can
# undo.
if [ -e "$link" ] && [ ! -L "$link" ]; then
echo "install: keeping the existing $name as $name.bak"
mv "$link" "$link.bak"
fi
ln -sfn "$target" "$link"
echo "install: $link -> $target"
done
# The device recorder's source and build script, which ui-trace reads from a
# fixed path and rebuilds when the source is newer than the jar. Linked as a
# directory so a rebuild lands in the repo rather than beside it.
if [ -e "$sharedir/ui-trace" ] && [ ! -L "$sharedir/ui-trace" ]; then
echo "install: keeping the existing share/ui-trace as ui-trace.bak"
mv "$sharedir/ui-trace" "$sharedir/ui-trace.bak"
fi
ln -sfn "$here/share/ui-trace" "$sharedir/ui-trace"
echo "install: $sharedir/ui-trace -> $here/share/ui-trace"
case ":$PATH:" in
*":$bindir:"*) ;;
*) echo "install: note -- $bindir is not on PATH" ;;
esac
# The adb wrapper only wins if it comes before the SDK's own on PATH. Said
# rather than fixed: which shell profile to edit is not this script's to
# decide, and getting it wrong is a broken login shell.
real=$(command -v adb 2>/dev/null || true)
if [ "$real" != "$bindir/adb" ]; then
echo "install: note -- 'adb' resolves to $real, not $bindir/adb;"
echo " put $bindir before the SDK's platform-tools on PATH."
fi