#!/bin/bash
# Restore packages removed during the debloat session.
# Usage: restore.sh                 -> restore everything in removed.txt
#        restore.sh com.whatsapp    -> restore specific packages
export PATH="$HOME/Library/Android/sdk/platform-tools:$PATH"
SERIAL="${WATCH_SERIAL:?set WATCH_SERIAL to your watch adb serial (see adb devices)}"
DIR="$(cd "$(dirname "$0")" && pwd)"

pkgs=("$@")
if [ ${#pkgs[@]} -eq 0 ]; then
  while IFS= read -r line; do pkgs+=("$line"); done < "$DIR/removed.txt"
fi

for p in "${pkgs[@]}"; do
  [ -z "$p" ] && continue
  r=$(adb -s "$SERIAL" shell "cmd package install-existing $p" 2>&1 | tr -d '\r')
  printf '%-60s %s\n' "$p" "$r"
done
