Skip to content

Instantly share code, notes, and snippets.

@nutrino
Created January 27, 2025 00:02
Show Gist options
  • Save nutrino/0542fa8d73c2f82953a378734b32b480 to your computer and use it in GitHub Desktop.
Save nutrino/0542fa8d73c2f82953a378734b32b480 to your computer and use it in GitHub Desktop.
adb shell pm list packages -3 > wear-os-packages-out.txt
mkdir ~/wear-os-backup
#!/bin/zsh
set -x
BACKUP_DIR=~/wear-os-backup
PACKAGE_LIST_FILE=~/wear-os-packages-out.txt
ADB_PATH=~/Library/Android/sdk/platform-tools/adb
# Create a backup directory
mkdir -p "$BACKUP_DIR"
# Backup APKs (including split APKs)
while read -r line; do
package="${line#package:}" # Remove "package:" prefix
echo "Processing package: $package"
# Get all APK paths for the package
apk_paths=$($ADB_PATH shell pm path "$package" 2>/dev/null | sed 's/package://')
echo "$apk_paths"
# Check if APK paths exist
if [ -z "$apk_paths" ]; then
echo " Warning: No APKs found for $package. Skipping..."
continue
fi
# Create a subdirectory for the package (to avoid filename collisions)
package_dir="$BACKUP_DIR/$package"
mkdir -p "$package_dir"
# Pull all APKs for this package
echo "$apk_paths" | while read -r apk_path; do
echo " Pulling: $apk_path"
$ADB_PATH pull "$apk_path" "$package_dir/"
if [ $? -ne 0 ]; then
echo " Error: Failed to pull $apk_path"
fi
done
done < $PACKAGE_LIST_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment