blob: b02a88a72217158297b2f22e0361ef5cd76e4333 [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
34VERSION=$(grep versionCode=\"\[[:digit:]]\*\" app/src/main/AndroidManifest.xml | cut -d \" -f 2)
35GITVERSION=$(git describe --tags --always)
36
37FDROID_APK=org.fdroid.fdroid_102250.apk
38PRIVEXT_APK=org.fdroid.fdroid.privileged_${VERSION}.apk
39
40# Collect files
41mkdir -p $TMP_DIR/META-INF/com/google/android/
42cp app/src/main/scripts/update-binary $TMP_DIR/META-INF/com/google/android/
43cp app/src/main/scripts/80-fdroid.sh $TMP_DIR/
44
45if [ -z $BINARIES ] ; then
46 $PROG_DIR/gradlew assemble$(echo $VARIANT | tr 'dr' 'DR')
47 if [ $VARIANT == "debug" ]; then
48 cp $PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}.apk $TMP_DIR/FDroidPrivilegedExtension.apk
49 elif [ -f PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}-signed.apk ]; then
50 cp PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}-signed.apk $TMP_DIR/FDroidPrivilegedExtension.apk
51 else
52 cp PROG_DIR/app/build/outputs/apk/FDroidPrivilegedExtension-${VARIANT}-unsigned.apk $TMP_DIR/FDroidPrivilegedExtension.apk
53 fi
54else
55 [ ! -f $TMP_DIR/$PRIVEXT_APK ] && curl -L https://f-droid.org/repo/$PRIVEXT_APK > $TMP_DIR/$PRIVEXT_APK
56 [ ! -f $TMP_DIR/${PRIVEXT_APK}.asc ] && curl -L https://f-droid.org/repo/${PRIVEXT_APK}.asc > $TMP_DIR/${PRIVEXT_APK}.asc
57 gpg --keyring $PROG_DIR/f-droid.org-signing-key.gpg --no-default-keyring --verify $TMP_DIR/${PRIVEXT_APK}.asc
58 rm $TMP_DIR/${PRIVEXT_APK}.asc
59 mv $TMP_DIR/$PRIVEXT_APK $TMP_DIR/FDroidPrivilegedExtension.apk
60fi
61
62# For both
63[ ! -f $TMP_DIR/$FDROID_APK ] && curl -L https://f-droid.org/repo/$FDROID_APK > $TMP_DIR/$FDROID_APK
64[ ! -f $TMP_DIR/${FDROID_APK}.asc ] && curl -L https://f-droid.org/repo/${FDROID_APK}.asc > $TMP_DIR/${FDROID_APK}.asc
65gpg --keyring $PROG_DIR/f-droid.org-signing-key.gpg --no-default-keyring --verify $TMP_DIR/${FDROID_APK}.asc
66rm $TMP_DIR/${FDROID_APK}.asc
67mv $TMP_DIR/$FDROID_APK $TMP_DIR/FDroid.apk
68
69# Make zip
70if [ -z $BINARIES ]; then
71 ZIPBASE=FDroidPrivilegedExtension-${GITVERSION}
72else
73 ZIPBASE=FDroidPrivilegedExtensionFromBinaries-${GITVERSION}
74fi
75if [ $VARIANT == "debug" ]; then
76 ZIP=${ZIPBASE}-debug.zip
77else
78 ZIP=${ZIPBASE}.zip
79fi
80mkdir -p $PROG_DIR/build
81[ -f $PROG_DIR/build/$ZIP ] && rm $PROG_DIR/build/$ZIP
82pushd $TMP_DIR
83zip -r $PROG_DIR/build/$ZIP .
84popd