Last active
July 21, 2024 21:41
-
-
Save jzallas/c176c161c9fc3fc9702eb8ea71f0ac47 to your computer and use it in GitHub Desktop.
Samsung check updates
This file contains 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
#!/bin/bash | |
# Retrieve the list of packages | |
packages=$(adb shell pm list packages | sed 's/package://') | |
# Convert the packages to an array | |
IFS=$'\n' read -d '' -r -a package_array <<< "$packages" | |
total_packages=${#package_array[@]} | |
mismatches=() | |
# Loop through each package | |
for index in "${!package_array[@]}"; do | |
package=${package_array[$index]} | |
# Keep the console updated with the progress | |
printf "\r[%d of %d] Checking for updates [%d]..." "$((index + 1))" "${total_packages}" "${#mismatches[@]}" | |
# Fetch the remote version from samsung | |
api_version=$(curl -Ls "https://galaxystore.samsung.com/api/detail/${package}" | jq -r '.DetailMain.contentBinaryVersion') | |
api_version="$(echo "${api_version}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" | |
# Fetch the local version from dumpsys | |
dumpsys_version=$(adb shell dumpsys package "${package}" | grep versionName | sed 's/versionName=//') | |
dumpsys_version="$(echo "${dumpsys_version}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" | |
# Only proceed if api_version is not null or the string "null" | |
if [[ -n "$api_version" && "$api_version" != "null" ]]; then | |
# Compare the versions and notify if different | |
if [[ "$api_version" != "$dumpsys_version" ]]; then | |
# Store the mismatch details | |
mismatches+=("$package|$api_version|$dumpsys_version") | |
fi | |
fi | |
# idk if this api supports batching, so just wait between checks to prevent rate-limiting or robot detection | |
sleep 1 | |
done | |
# Iterate over the mismatches and ask for updates | |
for mismatch in "${mismatches[@]}"; do | |
IFS='|' read -r package api_version dumpsys_version <<< "$mismatch" | |
# Display mismatch details and ask for update | |
echo "Package: ${package}" | |
echo "API Version: ${api_version}" | |
echo "Dumpsys Version: ${dumpsys_version}" | |
read -rp "Update? (y/n): " response | |
if [[ "$response" == "y" ]]; then | |
echo "Updating ${package}..." | |
# Fetch the deeplink URL | |
deeplink_url=$(curl -Ls "https://galaxystore.samsung.com/api/detail/${package}" | jq -r '.DetailMain.deeplinkUrl') | |
if [[ -n "$deeplink_url" && "$deeplink_url" != "null" ]]; then | |
echo "Opening deeplink URL: ${deeplink_url}" | |
# Open the deeplink URL on the Android device | |
adb shell am start -a android.intent.action.VIEW -d "${deeplink_url}" | |
else | |
echo "Deeplink URL not found for ${package}." | |
fi | |
else | |
echo "Skipping update for ${package}." | |
fi | |
done |
@electriquo unfortunately I'm too busy to maintain/review contributions. You're welcome to copy/pasta and maintain it yourself (or contribute back to apkupdater).
That aside, thanks for doing the original homework on the api calls
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jzallas What are your thoughts on transitioning it from a gist to a repository so that we can all contribute?