Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Merge PR #201: refuse debloat lists that are not bare package names

Gathin2373b312f893fa
diff --cc tools/disable.sh
index cf6b22e20,9714e2fec..071eb4699
--- a/tools/disable.sh
+++ b/tools/disable.sh
@@@ -13,7 -13,18 +13,18 @@@ PY=tools/venv/bin/pytho
[ -x "$PY" ] || PY=tools/venv/Scripts/python.exe
export MSYS_NO_PATHCONV=1
[ -x "$PY" ] || { echo "run: python3 -m venv tools/venv && tools/venv/bin/pip install -r tools/requirements.txt"; exit 1; }
+ # Lists come from contributors, and the package name is pasted into a shell command on the TV.
+ # Refuse the whole list unless every entry is a bare package name (#165).
+ # Normalise first: Notepad on Windows saves a BOM and CRLF, and without this the first "# TV" line
+ # arrives as a package name and every entry keeps a trailing \r (#208).
-PKGS=$(awk 'NR==1{sub(/^\357\273\277/,"")} {sub(/\r$/,""); print}' "$LIST" \
++PKGS=$(LC_ALL=C awk 'NR==1{sub(/^\357\273\277/,"")} {sub(/\r$/,""); print}' "$LIST" \
+ | grep -vE '^\s*(#|$)' | sed -E 's/\s+#.*$//' | awk '{print $1}')
+ BAD=$(printf '%s\n' "$PKGS" | grep -vE '^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$' || true)
+ if [ -n "$BAD" ]; then
+ { echo "refusing $LIST: not a package name:"; printf '%s\n' "$BAD" | sed 's/^/ /'; } >&2
+ exit 1
+ fi
{
- grep -vE '^\s*(#|$)' "$LIST" | sed -E 's/\s+#.*$//' | awk '{print "pm disable-user --user 0 " $1}'
- printf '%s\n' "$PKGS" | sed 's/^/pm disable-user --user 0 /'
++ [ -n "$PKGS" ] && printf '%s\n' "$PKGS" | sed 's/^/pm disable-user --user 0 /'
echo "pm list packages -d"
} | "$PY" -I tools/tv.py --batch
diff --cc tools/restore.sh
index eb32e1b04,4b1e44f63..b073d80d6
--- a/tools/restore.sh
+++ b/tools/restore.sh
@@@ -13,8 -13,17 +13,17 @@@ STOCK="${2:-com.google.android.tvlaunch
PY=tools/venv/bin/python
[ -x "$PY" ] || PY=tools/venv/Scripts/python.exe
export MSYS_NO_PATHCONV=1
+ # Same check as disable.sh: the list is contributor-supplied and each entry becomes a shell
+ # command on the TV. A BOM and CRLF from a Windows editor are dropped first (#165, #208).
-PKGS=$(awk 'NR==1{sub(/^\357\273\277/,"")} {sub(/\r$/,""); print}' "$LIST" \
++PKGS=$(LC_ALL=C awk 'NR==1{sub(/^\357\273\277/,"")} {sub(/\r$/,""); print}' "$LIST" \
+ | grep -vE '^\s*(#|$)' | sed -E 's/\s+#.*$//' | awk '{print $1}')
+ BAD=$(printf '%s\n' "$PKGS" | grep -vE '^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)+$' || true)
+ if [ -n "$BAD" ]; then
+ { echo "refusing $LIST: not a package name:"; printf '%s\n' "$BAD" | sed 's/^/ /'; } >&2
+ exit 1
+ fi
{
- grep -vE '^\s*(#|$)' "$LIST" | sed -E 's/\s+#.*$//' | awk '{print "pm enable " $1}'
- printf '%s\n' "$PKGS" | sed 's/^/pm enable /'
++ [ -n "$PKGS" ] && printf '%s\n' "$PKGS" | sed 's/^/pm enable /'
echo "pm enable $STOCK"
# resolve the stock HOME component on the TV (Android 9 needs pkg/activity, not just pkg)
echo "cmd package set-home-activity --user 0 \$(cmd package resolve-activity --brief -a android.intent.action.MAIN -c android.intent.category.HOME $STOCK | tail -n 1)"