Skip to content

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

tools: theme.sh reads one argument, a theme folder or --reset

xbsheng2951d7066362
diff --git a/tools/theme.ps1 b/tools/theme.ps1
index d536b4f03..6b8877aa4 100644
--- a/tools/theme.ps1
+++ b/tools/theme.ps1
@@ -3,11 +3,23 @@
#
# Usage: tools\theme.ps1 -TvHost 192.168.1.50 themes\aurora
# tools\theme.ps1 -TvHost 192.168.1.50 -Reset
+#
+# One argument, and -Reset takes none: both together are refused rather than one of them dropped (below).
+# Exit status as in theme.sh: 0 the theme is on the TV, or the reset ran; 1 the theme could not be pushed; 2 the
+# command line is not one theme folder or -Reset, so nothing was sent.
param(
[Parameter(Position = 0)][string]$Theme,
[switch]$Reset,
[string]$TvHost = $env:TV_HOST
)
+# theme.sh judges its own command line here, and this is the same judgement: -Reset removes the theme from the
+# TV and a folder pushes it, so `-Reset themes\aurora` used to take the reset branch and throw the folder away
+# (the theme the reader named was removed instead of pushed), while `themes\aurora -Reset` pushed the theme and
+# ignored the reset. Nothing is sent for either.
+if ($Theme -and $Reset) {
+ [Console]::Error.WriteLine("theme.ps1 takes one argument, a theme folder or -Reset: $Theme would not have been used, and -Reset removes the theme from the TV while a folder pushes it, so the two cannot share a command line. Nothing was sent to the TV.")
+ exit 2
+}
$ErrorActionPreference = 'Stop'
$OutputEncoding = New-Object System.Text.UTF8Encoding $false
if (-not $TvHost) { throw 'pass -TvHost <tv ip> or set $env:TV_HOST' }
@@ -58,7 +70,7 @@ if ($Reset) {
Write-Host 'reset'
exit 0
}
-if (-not $Theme) { throw 'usage: theme.ps1 <theme folder> | -Reset' }
+if (-not $Theme) { [Console]::Error.WriteLine('usage: theme.ps1 <theme folder> | -Reset'); exit 2 }
$config = Join-Path $Theme 'config.json'
if (-not (Test-Path $config)) { throw "no config.json in $Theme" }
try { $themeJson = Get-Content $config -Raw | ConvertFrom-Json } catch { throw "$config is not valid JSON" }
diff --git a/tools/theme.sh b/tools/theme.sh
index bfe64bb4c..1db38a240 100755
--- a/tools/theme.sh
+++ b/tools/theme.sh
@@ -5,6 +5,10 @@
#
# Usage: TV_HOST=192.168.1.50 tools/theme.sh themes/aurora
# TV_HOST=192.168.1.50 tools/theme.sh --reset # remove the overlay, back to config.xml
+#
+# One argument, and --reset takes none: a second word is refused rather than dropped (see below). Exit status:
+# 0 the theme is on the TV, or the reset ran; 1 the theme could not be pushed; 2 the command line is not one
+# theme folder or --reset, so nothing was sent.
set -euo pipefail
# Resolve the theme folder against the caller's directory before moving into tools/.
# Git Bash's pwd says /c/Users/..., which the Windows Python cannot open; pwd -W gives C:/Users/... (as in disable.sh).
@@ -17,6 +21,24 @@ case "$THEME_ARG" in
/*|[A-Za-z]:[\\/]*) THEME_ARG="$(cd "$THEME_ARG" 2>/dev/null && { pwd -W 2>/dev/null || pwd; } || printf '%s' "$THEME_ARG")" ;;
*) THEME_ARG="$(pwd -W 2>/dev/null || pwd)/$THEME_ARG" ;;
esac
+# A theme folder or --reset, and nothing else. The first word alone decided everything the script did, so
+# `theme.sh --reset themes/aurora` matched the reset branch on that word and threw the folder away: the theme
+# the reader named was removed from the TV instead of pushed, and the run answered "reset" with exit 0 (the
+# undo hint this script prints is what people copy, so appending the folder to it is an easy line to type).
+# The same line the other way round, `theme.sh themes/aurora --reset`, pushed the theme and ignored the
+# --reset the reader asked for. Both are answered here, before TV_HOST is required and before anything is
+# sent: a command line this script cannot read should not reach a TV.
+if [ -z "$THEME_ARG" ]; then
+ echo "usage: theme.sh <theme folder> | --reset" >&2
+ exit 2
+fi
+if [ "$#" -gt 1 ]; then
+ shift
+ echo "theme.sh takes one argument, a theme folder or --reset: $* would not have been used, and --reset" \
+ "removes the theme from the TV while a folder pushes it, so the two cannot share a command line." \
+ "Nothing was sent to the TV." >&2
+ exit 2
+fi
cd "$(dirname "$0")"
: "${TV_HOST:?set TV_HOST to the TV IP address, e.g. TV_HOST=192.168.1.50 $0 themes/aurora}"
PY=venv/bin/python