-
Notifications
You must be signed in to change notification settings - Fork 0
feat(androidtv): add Projectivy deployment helper #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bakerboy448
wants to merge
4
commits into
main
Choose a base branch
from
feat/projectivy-deploy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1dccf15
feat(androidtv): add Projectivy deployment helper
bakerboy448 b3c1668
fix(androidtv): use verified Projectivy component
bakerboy448 79dc5e2
feat(androidtv): add pinned app fleet sync
bakerboy448 60fdfff
fix(androidtv): stage container ADB files safely
bakerboy448 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| #!/usr/bin/env bash | ||
| # Update pinned Android TV APKs when a device is reachable over network ADB. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| readonly ADB_CONTAINER="${ADB_CONTAINER:-androidtv-adb}" | ||
|
|
||
| usage() { | ||
| cat >&2 <<EOF | ||
| Usage: $0 <device-host> <manifest.tsv> | ||
|
|
||
| Manifest columns (tab-separated): package, minimum versionCode, source, SHA-256. | ||
| Use source "managed" and checksum "-" to audit a Play-managed package without | ||
| installing it. Otherwise source must be an APK URL with its pinned checksum. | ||
| Blank lines and lines beginning with # are ignored. Updates and downgrades must | ||
| be represented by a new pinned version and checksum; downgrades are refused. | ||
| EOF | ||
| exit 2 | ||
| } | ||
|
|
||
| [[ $# -eq 2 ]] || usage | ||
| readonly DEVICE_TARGET="$1:5555" | ||
| readonly MANIFEST="$2" | ||
| [[ -r "$MANIFEST" ]] || { | ||
| printf 'ERROR: manifest is not readable: %s\n' "$MANIFEST" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| declare -a adb_cmd | ||
| using_container=false | ||
| if command -v docker >/dev/null 2>&1 \ | ||
| && docker ps --format '{{.Names}}' 2>/dev/null | grep -Fxq "$ADB_CONTAINER"; then | ||
| adb_cmd=(docker exec "$ADB_CONTAINER" adb) | ||
| using_container=true | ||
| elif command -v adb >/dev/null 2>&1; then | ||
| adb_cmd=(adb) | ||
| else | ||
| printf 'ERROR: no running ADB container and no host adb executable\n' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| run_adb() { | ||
| "${adb_cmd[@]}" "$@" | ||
| } | ||
|
|
||
| tmp_dir="$(mktemp -d)" | ||
| declare -a container_apks=() | ||
| cleanup() { | ||
| run_adb disconnect "$DEVICE_TARGET" >/dev/null 2>&1 || true | ||
| if [[ "$using_container" == true && ${#container_apks[@]} -gt 0 ]]; then | ||
| docker exec "$ADB_CONTAINER" rm -f "${container_apks[@]}" >/dev/null 2>&1 || true | ||
| fi | ||
| rm -rf "$tmp_dir" | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| if ! timeout 15s "${adb_cmd[@]}" connect "$DEVICE_TARGET" >/dev/null; then | ||
| printf 'Device is offline or ADB is unavailable: %s\n' "$DEVICE_TARGET" >&2 | ||
| exit 75 | ||
| fi | ||
| device_state="$(run_adb -s "$DEVICE_TARGET" get-state 2>&1 || true)" | ||
| if [[ "$device_state" == *unauthorized* ]]; then | ||
| printf 'ERROR: ADB authorization is missing; approve the persistent client key on the TV\n' >&2 | ||
| exit 77 | ||
| fi | ||
| if ! timeout 15s "${adb_cmd[@]}" -s "$DEVICE_TARGET" wait-for-device; then | ||
| printf 'ERROR: timed out waiting for authorized ADB device %s\n' "$DEVICE_TARGET" >&2 | ||
| exit 75 | ||
| fi | ||
| device_state="$(run_adb -s "$DEVICE_TARGET" get-state 2>&1 || true)" | ||
| [[ "$device_state" == device ]] || { | ||
| printf 'ERROR: unexpected ADB state for %s: %s\n' "$DEVICE_TARGET" "$device_state" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| updates=0 | ||
| audit_failures=0 | ||
| while IFS=$'\t' read -r package target_version source expected_sha extra; do | ||
| [[ -z "$package" || "$package" == \#* ]] && continue | ||
| [[ -z "${extra:-}" && "$target_version" =~ ^[0-9]+$ ]] || { | ||
| printf 'ERROR: invalid manifest row for %s\n' "$package" >&2 | ||
| exit 1 | ||
| } | ||
|
|
||
| installed_version="$(run_adb -s "$DEVICE_TARGET" shell dumpsys package "$package" 2>/dev/null \ | ||
| | sed -n 's/.*versionCode=\([0-9][0-9]*\).*/\1/p' | head -n 1)" | ||
| installed_version="${installed_version:-0}" | ||
| if [[ "$source" == managed ]]; then | ||
| [[ "$expected_sha" == - ]] || { | ||
| printf 'ERROR: managed package %s must use checksum "-"\n' "$package" >&2 | ||
| exit 1 | ||
| } | ||
| if ((installed_version >= target_version && installed_version > 0)); then | ||
| printf 'Managed/current: %s (%s)\n' "$package" "$installed_version" | ||
| else | ||
| printf 'MANAGED ACTION NEEDED: %s is missing or below %s (installed: %s)\n' \ | ||
| "$package" "$target_version" "$installed_version" >&2 | ||
| audit_failures=$((audit_failures + 1)) | ||
| fi | ||
| continue | ||
| fi | ||
| [[ "$expected_sha" =~ ^[[:xdigit:]]{64}$ ]] || { | ||
| printf 'ERROR: invalid SHA-256 for %s\n' "$package" >&2 | ||
| exit 1 | ||
| } | ||
| if ((installed_version == target_version)); then | ||
| printf 'Current: %s (%s)\n' "$package" "$target_version" | ||
| continue | ||
| fi | ||
| if ((installed_version > target_version)); then | ||
| printf 'ERROR: refusing downgrade of %s from %s to %s\n' \ | ||
| "$package" "$installed_version" "$target_version" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| apk_path="$tmp_dir/${package}.apk" | ||
| curl --fail --location --silent --show-error "$source" --output "$apk_path" | ||
| printf '%s %s\n' "${expected_sha,,}" "$apk_path" | sha256sum --check --status || { | ||
| printf 'ERROR: checksum mismatch for %s\n' "$package" >&2 | ||
| exit 1 | ||
| } | ||
| printf 'Updating: %s (%s -> %s)\n' "$package" "$installed_version" "$target_version" | ||
| install_path="$apk_path" | ||
| if [[ "$using_container" == true ]]; then | ||
| install_path="/tmp/${package}-$$.apk" | ||
| docker cp "$apk_path" "$ADB_CONTAINER:$install_path" | ||
| container_apks+=("$install_path") | ||
| fi | ||
| run_adb -s "$DEVICE_TARGET" install -r -g "$install_path" | ||
| updates=$((updates + 1)) | ||
| done <"$MANIFEST" | ||
|
|
||
| printf 'Sync complete: %s update(s) installed\n' "$updates" | ||
| if ((audit_failures > 0)); then | ||
| printf 'Managed package audit: %s action(s) needed\n' "$audit_failures" >&2 | ||
| exit 3 | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| #!/usr/bin/env bash | ||
| # Install Projectivy Launcher on an Android TV device and select it as home. | ||
| # Uses ADB_CONTAINER (default: androidtv-adb) when running, otherwise adb. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| readonly PROJECTIVY_PACKAGE="com.spocky.projengmenu" | ||
| readonly PROJECTIVY_HOME="${PROJECTIVY_PACKAGE}/.ui.home.MainActivity" | ||
| readonly ADB_CONTAINER="${ADB_CONTAINER:-androidtv-adb}" | ||
|
|
||
| usage() { | ||
| cat >&2 <<EOF | ||
| Usage: $0 <device-host> [<apk-path>|--launcher-only|--backup <file>|--restore <file>] | ||
|
|
||
| The device must expose ADB over TCP and trust the selected ADB client key. | ||
| Set ADB_CONTAINER to use a running container other than androidtv-adb. | ||
| EOF | ||
| exit 2 | ||
| } | ||
|
|
||
| [[ $# -ge 1 ]] || usage | ||
| readonly DEVICE_HOST="$1" | ||
| readonly DEVICE_TARGET="${DEVICE_HOST}:5555" | ||
| APK_PATH="${2:-$(dirname "$0")/projectivy.apk}" | ||
| LAUNCHER_ONLY=false | ||
| RESTORE_PATH="" | ||
| BACKUP_PATH="" | ||
|
|
||
| case "${2:-}" in | ||
| "") ;; | ||
| --launcher-only) LAUNCHER_ONLY=true ;; | ||
| --restore) | ||
| LAUNCHER_ONLY=true | ||
| RESTORE_PATH="${3:?--restore needs a path}" | ||
| ;; | ||
| --backup) | ||
| LAUNCHER_ONLY=true | ||
| BACKUP_PATH="${3:?--backup needs a path}" | ||
| ;; | ||
| --*) | ||
| printf 'ERROR: unknown option: %s\n' "$2" >&2 | ||
| usage | ||
| ;; | ||
| esac | ||
|
|
||
| declare -a adb_cmd | ||
| using_container=false | ||
| container_tmp="" | ||
| if command -v docker >/dev/null 2>&1 \ | ||
| && docker ps --format '{{.Names}}' 2>/dev/null | grep -Fxq "$ADB_CONTAINER"; then | ||
| adb_cmd=(docker exec "$ADB_CONTAINER" adb) | ||
| using_container=true | ||
| container_tmp="/tmp/projectivy-deploy-$$" | ||
| docker exec "$ADB_CONTAINER" mkdir -p "$container_tmp" | ||
| printf 'Using ADB from container %s\n' "$ADB_CONTAINER" | ||
| elif command -v adb >/dev/null 2>&1; then | ||
| adb_cmd=(adb) | ||
| printf 'Using host ADB\n' | ||
| else | ||
| printf 'ERROR: no running ADB container and no host adb executable\n' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| run_adb() { | ||
| "${adb_cmd[@]}" "$@" | ||
| } | ||
|
|
||
| cleanup() { | ||
| run_adb disconnect "$DEVICE_TARGET" >/dev/null 2>&1 || true | ||
| if [[ "$using_container" == true ]]; then | ||
| docker exec "$ADB_CONTAINER" rm -rf "$container_tmp" >/dev/null 2>&1 || true | ||
| fi | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| printf 'Connecting to %s\n' "$DEVICE_TARGET" | ||
| run_adb connect "$DEVICE_TARGET" >/dev/null | ||
| run_adb -s "$DEVICE_TARGET" wait-for-device | ||
|
|
||
| device_name="$(run_adb -s "$DEVICE_TARGET" shell getprop ro.product.model 2>/dev/null | tr -d '\r' || true)" | ||
| printf 'Connected: %s\n' "${device_name:-unknown}" | ||
|
|
||
| if [[ "$LAUNCHER_ONLY" == false ]]; then | ||
| [[ -f "$APK_PATH" ]] || { | ||
| printf 'ERROR: APK not found at %s; use --launcher-only after store installation\n' "$APK_PATH" >&2 | ||
| exit 1 | ||
| } | ||
| install_path="$APK_PATH" | ||
| if [[ "$using_container" == true ]]; then | ||
| install_path="$container_tmp/projectivy.apk" | ||
| docker cp "$APK_PATH" "$ADB_CONTAINER:$install_path" | ||
| fi | ||
| run_adb -s "$DEVICE_TARGET" install -r -g "$install_path" | ||
| fi | ||
|
|
||
| if ! run_adb -s "$DEVICE_TARGET" shell pm list packages 2>/dev/null \ | ||
| | grep -Fq "package:${PROJECTIVY_PACKAGE}"; then | ||
| printf 'ERROR: Projectivy is not installed; install it first or provide an APK\n' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -n "$RESTORE_PATH" ]]; then | ||
| [[ -f "$RESTORE_PATH" ]] || { | ||
| printf 'ERROR: restore file not found: %s\n' "$RESTORE_PATH" >&2 | ||
| exit 1 | ||
| } | ||
| printf 'Restoring Projectivy configuration; confirm the prompt on the TV\n' | ||
| restore_path="$RESTORE_PATH" | ||
| if [[ "$using_container" == true ]]; then | ||
| restore_path="$container_tmp/projectivy.ab" | ||
| docker cp "$RESTORE_PATH" "$ADB_CONTAINER:$restore_path" | ||
| fi | ||
| run_adb -s "$DEVICE_TARGET" restore "$restore_path" | ||
| fi | ||
|
|
||
| if [[ -n "$BACKUP_PATH" ]]; then | ||
| printf 'Backing up Projectivy configuration; confirm the prompt on the TV\n' | ||
| backup_path="$BACKUP_PATH" | ||
| if [[ "$using_container" == true ]]; then | ||
| backup_path="$container_tmp/projectivy.ab" | ||
| fi | ||
| run_adb -s "$DEVICE_TARGET" backup -f "$backup_path" -noapk "$PROJECTIVY_PACKAGE" | ||
| if [[ "$using_container" == true ]]; then | ||
| docker cp "$ADB_CONTAINER:$backup_path" "$BACKUP_PATH" | ||
| fi | ||
| if [[ -r "$BACKUP_PATH" ]]; then | ||
| printf 'Backup written: %s bytes\n' "$(wc -c <"$BACKUP_PATH" | tr -d '[:space:]')" | ||
| else | ||
| printf 'Backup written: missing\n' | ||
| fi | ||
| exit 0 | ||
| fi | ||
|
|
||
| printf 'Setting Projectivy as the default launcher\n' | ||
| run_adb -s "$DEVICE_TARGET" shell cmd package set-home-activity "$PROJECTIVY_HOME" | ||
| printf 'Done. Press Home on the TV to verify Projectivy launches.\n' | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.