blob: f99a3e390ff84ebb0e21cb1e0f0276bbb4d0de29 [file] [log] [blame]
Chirayu Desai93f4f412017-04-14 21:43:26 +05301#!/bin/bash
2#
3# Script to prepare an update.zip containing F-Droid and the Privileged Extension.
4
5set -e
6
7PROG_DIR=$(dirname $(realpath $0))
8
9TMP_DIR=$(mktemp -d -t fdroidprivext.tmp.XXXXXXXX)
10trap "rm -rf $TMP_DIR" EXIT
11
12function error() {
13 echo "*** ERROR: " $@
14 usage
15}
16
17function usage() {
18 cat << EOFU
19Usage: $0 variant [binaries]
20where:
21 - variant is one of: debug, release
22 - binaries is set for using prebuilt apks,
23 not set by default.
24EOFU
25 exit 1
26}
27
28# Parse input
29VARIANT="$1"
30[[ -z "$VARIANT" ]] && error "Missing variant"
31
32BINARIES="$2"
33
Hans-Christoph Steiner3fcb55e2017-04-21 13:39:55 +020034GPG="gpg --keyring $PROG_DIR/f-droid.org-signing-key.gpg --no-default-keyring --trust-model always"
35
Chirayu Desai93f4f412017-04-14 21:43:26 +053036VERSION=$(grep versionCode=\"\[[:digit:]]\*\" app/src/main/AndroidManifest.xml | cut -d \" -f 2)
37GITVERSION=$(git describe --tags --always)
38
Hans-Christoph Steiner87059962017-04-21 13:21:10 +020039# TODO this should be FDroid.apk once 102350 is there
40FDROID_APK=org.fdroid.fdroid_102350.apk
Chirayu Desai93f4f412017-04-14 21:43:26 +053041PRIVEXT_APK=org.fdroid.fdroid.privileged_${VERSION}.apk
42
43# Collect files
44mkdir -p $TMP_DIR/META-INF/com/google/android/
45cp app/src/main/scripts/update-binary $TMP_DIR/META-INF/com/google/android/
46cp app/src/main/scripts/80-fdroid.sh $TMP_DIR/
47
48if [ -z $BINARIES ] ; then
49 $PROG_DIR/gradlew assemble$(echo $VARIANT | tr 'dr' 'DR')
50 if [ $VARIANT == "debug" ]; then
51 cp $PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}.apk $TMP_DIR/FDroidPrivilegedExtension.apk
52 elif [ -f PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}-signed.apk ]; then
53 cp PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}-signed.apk $TMP_DIR/FDroidPrivilegedExtension.apk
54 else
55 cp PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}-unsigned.apk $TMP_DIR/FDroidPrivilegedExtension.apk
56 fi
57else
58 [ ! -f $TMP_DIR/$PRIVEXT_APK ] && curl -L https://f-droid.org/repo/$PRIVEXT_APK > $TMP_DIR/$PRIVEXT_APK
59 [ ! -f $TMP_DIR/${PRIVEXT_APK}.asc ] && curl -L https://f-droid.org/repo/${PRIVEXT_APK}.asc > $TMP_DIR/${PRIVEXT_APK}.asc
Hans-Christoph Steiner3fcb55e2017-04-21 13:39:55 +020060 $GPG --verify $TMP_DIR/${PRIVEXT_APK}.asc
Chirayu Desai93f4f412017-04-14 21:43:26 +053061 rm $TMP_DIR/${PRIVEXT_APK}.asc
62 mv $TMP_DIR/$PRIVEXT_APK $TMP_DIR/FDroidPrivilegedExtension.apk
63fi
64
65# For both
66[ ! -f $TMP_DIR/$FDROID_APK ] && curl -L https://f-droid.org/repo/$FDROID_APK > $TMP_DIR/$FDROID_APK
67[ ! -f $TMP_DIR/${FDROID_APK}.asc ] && curl -L https://f-droid.org/repo/${FDROID_APK}.asc > $TMP_DIR/${FDROID_APK}.asc
Hans-Christoph Steiner3fcb55e2017-04-21 13:39:55 +020068$GPG --verify $TMP_DIR/${FDROID_APK}.asc
Chirayu Desai93f4f412017-04-14 21:43:26 +053069rm $TMP_DIR/${FDROID_APK}.asc
70mv $TMP_DIR/$FDROID_APK $TMP_DIR/FDroid.apk
71
72# Make zip
73if [ -z $BINARIES ]; then
74 ZIPBASE=FDroidPrivilegedExtension-${GITVERSION}
75else
76 ZIPBASE=FDroidPrivilegedExtensionFromBinaries-${GITVERSION}
77fi
78if [ $VARIANT == "debug" ]; then
79 ZIP=${ZIPBASE}-debug.zip
80else
81 ZIP=${ZIPBASE}.zip
82fi
83mkdir -p $PROG_DIR/build
84[ -f $PROG_DIR/build/$ZIP ] && rm $PROG_DIR/build/$ZIP
85pushd $TMP_DIR
86zip -r $PROG_DIR/build/$ZIP .
87popd