summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/publish-apk17
1 files changed, 14 insertions, 3 deletions
diff --git a/bin/publish-apk b/bin/publish-apk
index 91b4705..faf6db8 100755
--- a/bin/publish-apk
+++ b/bin/publish-apk
@@ -39,10 +39,21 @@ ACTUAL_HOST=$(hostname)
|| die "host is '$ACTUAL_HOST', expected '$EXPECT_HOST'. Build and test here, publish there."
[ -f "$APK" ] || die "no such file: $APK"
+
# An .apk is a zip; an HTML error page or a truncated copy is not.
-head -c 2 "$APK" | grep -q "PK" || die "$APK is not a zip archive — not a real APK"
-unzip -l "$APK" 2>/dev/null | grep -q "AndroidManifest.xml" \
- || die "$APK has no AndroidManifest.xml — not an APK"
+#
+# Deliberately NOT `... | grep -q`: under `set -o pipefail` grep exits on its first match and
+# SIGPIPEs the producer, so the pipeline reports failure on a file that is perfectly valid.
+# This script hit exactly that on a real 112MB APK -- the trap is in this repo's own README,
+# and it still caught me. Capture first, test second.
+MAGIC=$(head -c 2 "$APK")
+[ "$MAGIC" = "PK" ] || die "$APK is not a zip archive — not a real APK"
+
+LISTING=$(unzip -l "$APK" 2>/dev/null)
+case "$LISTING" in
+ *AndroidManifest.xml*) ;;
+ *) die "$APK has no AndroidManifest.xml — not an APK" ;;
+esac
[ -d "$DEST_DIR" ] || die "no such directory: $DEST_DIR"
DEST="$DEST_DIR/$NAME"