Last active
August 3, 2024 14:33
-
-
Save obfusk/4e3bbad0059be45cb555c6ef67c08588 to your computer and use it in GitHub Desktop.
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 | |
set -euo pipefail | |
zipentry=META-INF/version-control-info.textproto | |
commit_from_zip() { | |
unzip -p -- "$1" "$zipentry" | grep revision | grep -Eo '[0-9a-f]+' | tail -1 | |
} | |
url="${1:-}" | |
if [ -z "$url" ]; then | |
read -r -p 'url> ' | |
url="$REPLY" | |
fi | |
if [ "${url:0:8}" = https:// ] || [ "${url:0:7}" = http:// ]; then | |
echo "url: $url" | |
tempdir="$( mktemp -d )" | |
[[ "$tempdir" = */tmp.* ]] | |
trap 'rm -- "$tempdir/tmp.apk" && rmdir -- "$tempdir"' EXIT | |
curl -sL --output "$tempdir/tmp.apk" -- "$url" | |
commit="$( commit_from_zip "$tempdir/tmp.apk" )" | |
else | |
echo "file: $url" | |
commit="$( commit_from_zip "$url" )" | |
fi | |
echo "commit: $commit" |
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 | |
set -euo pipefail | |
sha1_from_zip() { unzip -p -- "$1" "$zipentry" | sha1sum | cut -d' ' -f1; } | |
zipentry="${1:-}" url="${2:-}" | |
if [ -z "$zipentry" ]; then | |
read -r -p 'zipentry> ' | |
zipentry="$REPLY" | |
fi | |
if [ -z "$url" ]; then | |
read -r -p 'url> ' | |
url="$REPLY" | |
fi | |
if [ "${url:0:8}" = https:// ] || [ "${url:0:7}" = http:// ]; then | |
echo "url: $url" | |
tempdir="$( mktemp -d )" | |
[[ "$tempdir" = */tmp.* ]] | |
trap 'rm -- "$tempdir/tmp.apk" && rmdir -- "$tempdir"' EXIT | |
curl -sL --output "$tempdir/tmp.apk" -- "$url" | |
sha1="$( sha1_from_zip "$tempdir/tmp.apk" )" | |
else | |
echo "file: $url" | |
sha1="$( sha1_from_zip "$url" )" | |
fi | |
echo "zipentry: $zipentry" | |
echo "sha1: $sha1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment