23279b95 Andy McCall 8 days ago ↶
1
2
3
4
5
6
7
8
set -euo pipefail
9
b64 = $ { KEYSTORE_B64 :- /run/secrets/android-keystore }
10
password = $ { PASSWORD_FILE :- /run/secrets/android-keystore-password }
11
firebase = $ { FIREBASE_CONFIG :- /run/secrets/firebase-config }
12
for f in " $ b64 " " $ password " ; do
13
[ - s " $ f " ] || { echo " release-check: no $ f : the job needs the android-keystore secrets" >& 2 ; exit 1 ; }
14
done
15
16
keys = $ ( mktemp - d)
17
trap ' rm -rf "$keys"' EXIT
18
chmod 700 " $ keys "
19
base64 - d " $ b64 " > " $ keys /release.p12" || { echo " release-check: the android-keystore secret is not base64 (base64 -w0 FILE.p12)" >& 2 ; exit 1 ; }
20
echo " release-check: keystore sha256 $ ( sha256sum < " $ keys /release.p12" | cut - d' ' - f1) "
21
keytool = $ ( command - v keytool || ( ls /opt/gradle-home/jdks/* /bin/keytool 2 > /dev/null || true ) | head - 1)
22
if [ - z " $ keytool " ] ; then
23
echo " release-check: no keytool here, so the password is not checked" >& 2
24
else
25
26
tr - d ' \r' < " $ password " | sed - e ' s/^[[:space:]]*//' - e ' s/[[:space:]]*$//' | head - c 4096 > " $ keys /pass"
27
" $ keytool " - list - keystore " $ keys /release.p12" - storetype PKCS12 - storepass :file " $ keys /pass" 2 >& 1 \
28
| grep - E ' PrivateKeyEntry|SHA-256\)' \
29
|| { echo " release-check: the android-keystore-password secret does not open the android-keystore secret, or it holds no key" >& 2 ; exit 1 ; }
30
" $ keytool " - list - keystore " $ keys /release.p12" - storetype PKCS12 - storepass :file " $ keys /pass" 2 > /dev/null | grep - q ' ^oxygenhub,' \
31
|| { echo " release-check: the keystore has no entry named oxygenhub, which the build signs with" >& 2 ; exit 1 ; }
32
33
34
" $ keytool " - certreq - alias oxygenhub - keystore " $ keys /release.p12" - storetype PKCS12 \
35
- storepass :file " $ keys /pass" - keypass :file " $ keys /pass" > /dev/null 2 > " $ keys /certreq.err" \
36
|| { echo " release-check: the key oxygenhub cannot be read with the keystore's password, as signing needs: $ ( head - c 300 " $ keys /certreq.err" ) " >& 2 ; exit 1 ; }
37
echo " release-check: the key oxygenhub opens with the password"
38
if [ " $ ( wc - l < " $ password " ) " - gt 1 ] ; then
39
echo " release-check: the password secret has more than one line; the build reads all of it" >& 2
40
fi
41
fi
42
43
if [ - s " $ firebase " ] ; then
44
if command - v python3 > /dev/null ; then
45
python3 - I - c ' import json,sys; json.load(open(sys.argv[1]))' " $ firebase " 2 > /dev/null \
46
|| { echo " release-check: the firebase-config secret is not whole JSON (is its last } missing?)" >& 2 ; exit 1 ; }
47
elif [ " $ ( tr - d ' [:space:]' < " $ firebase " | tail - c 1) " != " }" ] ; then
48
echo " release-check: the firebase-config secret does not end with } (is its last line missing?)" >& 2
49
exit 1
50
fi
51
echo " release-check: firebase-config reads as JSON"
52
else
53
echo " release-check: no $ firebase : a release takes no alerts" >& 2
54
fi
55
echo " release-check: ok"