release-zapstore.sh raw
1 #!/usr/bin/env bash
2 # Publish the current release APK to Zapstore.
3 # Requires: zsp in PATH, the release APK built, zapstore.env with SIGN_WITH,
4 # and the debug signing keystore at android/app/debug.keystore.
5 #
6 # Usage:
7 # ./scripts/release-zapstore.sh
8
9 set -euo pipefail
10
11 cd "$(dirname "$0")/.."
12
13 ENV_FILE="zapstore.env"
14 if [[ ! -f "$ENV_FILE" ]]; then
15 echo "Missing $ENV_FILE — create it with:"
16 echo ' echo SIGN_WITH=<your-nsec> > zapstore.env'
17 echo ' (file is gitignored)'
18 exit 1
19 fi
20
21 # shellcheck disable=SC1090
22 source "$ENV_FILE"
23
24 if [[ -z "${SIGN_WITH:-}" ]]; then
25 echo "SIGN_WITH is empty in $ENV_FILE"
26 exit 1
27 fi
28
29 export SIGN_WITH
30
31 APK="android/app/build/outputs/apk/release/app-release.apk"
32 if [[ ! -f "$APK" ]]; then
33 echo "Release APK not found at $APK"
34 echo "Build it first: ./gradlew assembleRelease"
35 exit 1
36 fi
37
38 KEYSTORE="android/app/debug.keystore"
39 P12="android/app/debug.p12"
40 KEYSTORE_PASS="android"
41
42 if [[ ! -f "$KEYSTORE" ]]; then
43 echo "Keystore not found at $KEYSTORE"
44 exit 1
45 fi
46
47 # ── Convert JKS → PKCS12 (zsp requires PKCS12) ─────────────────────────
48 if [[ ! -f "$P12" ]]; then
49 echo "→ Converting keystore to PKCS12..."
50 keytool -importkeystore \
51 -srckeystore "$KEYSTORE" \
52 -destkeystore "$P12" \
53 -srcstoretype JKS -deststoretype PKCS12 \
54 -srcstorepass "$KEYSTORE_PASS" -deststorepass "$KEYSTORE_PASS" \
55 -srcalias androiddebugkey -destalias androiddebugkey \
56 -noprompt 2>/dev/null
57 fi
58
59 export KEYSTORE_PASSWORD="$KEYSTORE_PASS"
60
61 # ── Run a zsp command that needs TTY via script+expect. ─────────────────
62 # Writes a one-shot expect script to a temp file, invokes expect with it.
63 zsp_auto() {
64 local title="$1"
65 local zsp_cmd="$2"
66 echo "→ $title..."
67 local tmp
68 tmp=$(mktemp)
69 cat > "$tmp" << EOF
70 set timeout 300
71 spawn /bin/bash -c {script -q -c '@ZSP_CMD@' /dev/null}
72 expect {Choose an option:}
73 send "\r"
74 expect {
75 {Published successfully} {}
76 {already exists on} {
77 puts stderr "Already published."
78 exit 0
79 }
80 eof {}
81 }
82 expect eof
83 EOF
84 sed -i "s#@ZSP_CMD@#$zsp_cmd#g" "$tmp"
85 expect -f "$tmp" 2>/dev/null
86 rm -f "$tmp"
87 }
88
89 # ── Link APK signing cert → Nostr identity ─────────────────────────────
90 zsp_auto "Linking signing certificate to Nostr identity" \
91 "zsp identity --link-key $P12"
92
93 # ── Publish release ──────────────────────────────────────────────────
94 echo
95 echo " APK: $(du -h "$APK" | cut -f1)"
96 echo " SHA256: $(sha256sum "$APK" | awk '{print $1}')"
97 echo
98
99 zsp_auto "Publishing Warden to Zapstore" \
100 "zsp publish --skip-preview --skip-metadata --overwrite-release --skip-certificate-linking zapstore.yaml"
101
102 rm -f "$P12"
103
104 echo
105 echo "Done. Check https://zapstore.dev"
106