blob: 157bbc5a612ac4e84080de2cedc29e57edf0f892 [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
Chirayu Desai27f28ec2018-02-22 02:45:46 +053039FDROID_APK=F-Droid.apk
Chirayu Desai93f4f412017-04-14 21:43:26 +053040PRIVEXT_APK=org.fdroid.fdroid.privileged_${VERSION}.apk
Hans-Christoph Steiner386c86d2018-03-21 17:46:54 +010041FPE_NAME=F-DroidPrivilegedExtension
Chirayu Desai93f4f412017-04-14 21:43:26 +053042
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/
Chirayu Desai52282152017-09-18 22:59:14 +053047cp app/src/main/permissions_org.fdroid.fdroid.privileged.xml $TMP_DIR/
Chirayu Desai93f4f412017-04-14 21:43:26 +053048
49if [ -z $BINARIES ] ; then
Hans-Christoph Steinerd3ba33b2017-04-21 22:33:36 +020050 cd $PROG_DIR
51 ./gradlew assemble$(echo $VARIANT | tr 'dr' 'DR')
52 OUT_DIR=$PROG_DIR/app/build/outputs/apk
53 if [ $VARIANT == "debug" ]; then
Hans-Christoph Steiner386c86d2018-03-21 17:46:54 +010054 cp $OUT_DIR/$FPE_NAME-debug.apk $TMP_DIR/$FPE_NAME.apk
55 elif [ -f $OUT_DIR/$FPE_NAME-release.apk ]; then
56 cp $OUT_DIR/$FPE_NAME-release.apk $TMP_DIR/$FPE_NAME.apk
Hans-Christoph Steinerd3ba33b2017-04-21 22:33:36 +020057 else
Hans-Christoph Steiner386c86d2018-03-21 17:46:54 +010058 echo "No signed debug or release APK found in $OUT_DIR!"
59 exit 1
Hans-Christoph Steinerd3ba33b2017-04-21 22:33:36 +020060 fi
Chirayu Desai93f4f412017-04-14 21:43:26 +053061else
Hans-Christoph Steiner6f972e02017-04-24 11:13:57 +020062 curl -L https://f-droid.org/repo/$PRIVEXT_APK > $TMP_DIR/$PRIVEXT_APK
63 curl -L https://f-droid.org/repo/${PRIVEXT_APK}.asc > $TMP_DIR/${PRIVEXT_APK}.asc
Hans-Christoph Steiner3fcb55e2017-04-21 13:39:55 +020064 $GPG --verify $TMP_DIR/${PRIVEXT_APK}.asc
Chirayu Desai93f4f412017-04-14 21:43:26 +053065 rm $TMP_DIR/${PRIVEXT_APK}.asc
Hans-Christoph Steiner386c86d2018-03-21 17:46:54 +010066 mv $TMP_DIR/$PRIVEXT_APK $TMP_DIR/$FPE_NAME.apk
Chirayu Desai93f4f412017-04-14 21:43:26 +053067fi
68
69# For both
Chirayu Desai27f28ec2018-02-22 02:45:46 +053070curl -L https://f-droid.org/$FDROID_APK > $TMP_DIR/$FDROID_APK
71curl -L https://f-droid.org/${FDROID_APK}.asc > $TMP_DIR/${FDROID_APK}.asc
Hans-Christoph Steiner3fcb55e2017-04-21 13:39:55 +020072$GPG --verify $TMP_DIR/${FDROID_APK}.asc
Chirayu Desai93f4f412017-04-14 21:43:26 +053073rm $TMP_DIR/${FDROID_APK}.asc
Hans-Christoph Steiner386c86d2018-03-21 17:46:54 +010074test -e $TMP_DIR/F-Droid.apk || mv $TMP_DIR/$FDROID_APK $TMP_DIR/F-Droid.apk
Chirayu Desai93f4f412017-04-14 21:43:26 +053075
76# Make zip
77if [ -z $BINARIES ]; then
Hans-Christoph Steiner386c86d2018-03-21 17:46:54 +010078 ZIPBASE=${FPE_NAME}-${GITVERSION}
Chirayu Desai93f4f412017-04-14 21:43:26 +053079else
Hans-Christoph Steiner386c86d2018-03-21 17:46:54 +010080 ZIPBASE=${FPE_NAME}FromBinaries-${GITVERSION}
Chirayu Desai93f4f412017-04-14 21:43:26 +053081fi
82if [ $VARIANT == "debug" ]; then
83 ZIP=${ZIPBASE}-debug.zip
84else
85 ZIP=${ZIPBASE}.zip
86fi
Hans-Christoph Steinerafd08662017-04-21 22:47:05 +020087OUT_DIR=$PROG_DIR/app/build/distributions
88mkdir -p $OUT_DIR
89[ -f $OUT_DIR/$ZIP ] && rm -f $OUT_DIR/$ZIP
Chirayu Desai93f4f412017-04-14 21:43:26 +053090pushd $TMP_DIR
Hans-Christoph Steinerafd08662017-04-21 22:47:05 +020091zip -r $OUT_DIR/$ZIP .
92popd