blob: 651fbcafe270377272fb8de4196ba2d74f87b768 [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
Hans-Christoph Steinerd3ba33b2017-04-21 22:33:36 +020049 cd $PROG_DIR
50 ./gradlew assemble$(echo $VARIANT | tr 'dr' 'DR')
51 OUT_DIR=$PROG_DIR/app/build/outputs/apk
52 if [ $VARIANT == "debug" ]; then
53 cp $OUT_DIR/FDroidPrivilegedExtension-${VARIANT}.apk \
54 $TMP_DIR/FDroidPrivilegedExtension.apk
55 elif [ -f $OUT_DIR/FDroidPrivilegedExtension-${VARIANT}-signed.apk ]; then
56 cp $OUT_DIR/FDroidPrivilegedExtension-${VARIANT}-signed.apk \
57 $TMP_DIR/FDroidPrivilegedExtension.apk
58 else
59 cp $OUT_DIR/FDroidPrivilegedExtension-${VARIANT}-unsigned.apk \
60 $TMP_DIR/FDroidPrivilegedExtension.apk
61 fi
Chirayu Desai93f4f412017-04-14 21:43:26 +053062else
63 [ ! -f $TMP_DIR/$PRIVEXT_APK ] && curl -L https://f-droid.org/repo/$PRIVEXT_APK > $TMP_DIR/$PRIVEXT_APK
64 [ ! -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 +020065 $GPG --verify $TMP_DIR/${PRIVEXT_APK}.asc
Chirayu Desai93f4f412017-04-14 21:43:26 +053066 rm $TMP_DIR/${PRIVEXT_APK}.asc
67 mv $TMP_DIR/$PRIVEXT_APK $TMP_DIR/FDroidPrivilegedExtension.apk
68fi
69
70# For both
71[ ! -f $TMP_DIR/$FDROID_APK ] && curl -L https://f-droid.org/repo/$FDROID_APK > $TMP_DIR/$FDROID_APK
72[ ! -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 +020073$GPG --verify $TMP_DIR/${FDROID_APK}.asc
Chirayu Desai93f4f412017-04-14 21:43:26 +053074rm $TMP_DIR/${FDROID_APK}.asc
75mv $TMP_DIR/$FDROID_APK $TMP_DIR/FDroid.apk
76
77# Make zip
78if [ -z $BINARIES ]; then
79 ZIPBASE=FDroidPrivilegedExtension-${GITVERSION}
80else
81 ZIPBASE=FDroidPrivilegedExtensionFromBinaries-${GITVERSION}
82fi
83if [ $VARIANT == "debug" ]; then
84 ZIP=${ZIPBASE}-debug.zip
85else
86 ZIP=${ZIPBASE}.zip
87fi
Hans-Christoph Steinerafd08662017-04-21 22:47:05 +020088OUT_DIR=$PROG_DIR/app/build/distributions
89mkdir -p $OUT_DIR
90[ -f $OUT_DIR/$ZIP ] && rm -f $OUT_DIR/$ZIP
Chirayu Desai93f4f412017-04-14 21:43:26 +053091pushd $TMP_DIR
Hans-Christoph Steinerafd08662017-04-21 22:47:05 +020092zip -r $OUT_DIR/$ZIP .
93popd