Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Script to prepare an update.zip containing F-Droid and the Privileged Extension. |
| 4 | |
| 5 | set -e |
| 6 | |
| 7 | PROG_DIR=$(dirname $(realpath $0)) |
| 8 | |
| 9 | TMP_DIR=$(mktemp -d -t fdroidprivext.tmp.XXXXXXXX) |
| 10 | trap "rm -rf $TMP_DIR" EXIT |
| 11 | |
| 12 | function error() { |
| 13 | echo "*** ERROR: " $@ |
| 14 | usage |
| 15 | } |
| 16 | |
| 17 | function usage() { |
| 18 | cat << EOFU |
| 19 | Usage: $0 variant [binaries] |
| 20 | where: |
| 21 | - variant is one of: debug, release |
| 22 | - binaries is set for using prebuilt apks, |
| 23 | not set by default. |
| 24 | EOFU |
| 25 | exit 1 |
| 26 | } |
| 27 | |
| 28 | # Parse input |
| 29 | VARIANT="$1" |
| 30 | [[ -z "$VARIANT" ]] && error "Missing variant" |
| 31 | |
| 32 | BINARIES="$2" |
| 33 | |
Hans-Christoph Steiner | 3fcb55e | 2017-04-21 13:39:55 +0200 | [diff] [blame] | 34 | GPG="gpg --keyring $PROG_DIR/f-droid.org-signing-key.gpg --no-default-keyring --trust-model always" |
| 35 | |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 36 | VERSION=$(grep versionCode=\"\[[:digit:]]\*\" app/src/main/AndroidManifest.xml | cut -d \" -f 2) |
| 37 | GITVERSION=$(git describe --tags --always) |
| 38 | |
Hans-Christoph Steiner | 8705996 | 2017-04-21 13:21:10 +0200 | [diff] [blame] | 39 | # TODO this should be FDroid.apk once 102350 is there |
| 40 | FDROID_APK=org.fdroid.fdroid_102350.apk |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 41 | PRIVEXT_APK=org.fdroid.fdroid.privileged_${VERSION}.apk |
| 42 | |
| 43 | # Collect files |
| 44 | mkdir -p $TMP_DIR/META-INF/com/google/android/ |
| 45 | cp app/src/main/scripts/update-binary $TMP_DIR/META-INF/com/google/android/ |
| 46 | cp app/src/main/scripts/80-fdroid.sh $TMP_DIR/ |
| 47 | |
| 48 | if [ -z $BINARIES ] ; then |
Hans-Christoph Steiner | d3ba33b | 2017-04-21 22:33:36 +0200 | [diff] [blame] | 49 | 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 Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 62 | else |
| 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 Steiner | 3fcb55e | 2017-04-21 13:39:55 +0200 | [diff] [blame] | 65 | $GPG --verify $TMP_DIR/${PRIVEXT_APK}.asc |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 66 | rm $TMP_DIR/${PRIVEXT_APK}.asc |
| 67 | mv $TMP_DIR/$PRIVEXT_APK $TMP_DIR/FDroidPrivilegedExtension.apk |
| 68 | fi |
| 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 Steiner | 3fcb55e | 2017-04-21 13:39:55 +0200 | [diff] [blame] | 73 | $GPG --verify $TMP_DIR/${FDROID_APK}.asc |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 74 | rm $TMP_DIR/${FDROID_APK}.asc |
| 75 | mv $TMP_DIR/$FDROID_APK $TMP_DIR/FDroid.apk |
| 76 | |
| 77 | # Make zip |
| 78 | if [ -z $BINARIES ]; then |
| 79 | ZIPBASE=FDroidPrivilegedExtension-${GITVERSION} |
| 80 | else |
| 81 | ZIPBASE=FDroidPrivilegedExtensionFromBinaries-${GITVERSION} |
| 82 | fi |
| 83 | if [ $VARIANT == "debug" ]; then |
| 84 | ZIP=${ZIPBASE}-debug.zip |
| 85 | else |
| 86 | ZIP=${ZIPBASE}.zip |
| 87 | fi |
Hans-Christoph Steiner | afd0866 | 2017-04-21 22:47:05 +0200 | [diff] [blame^] | 88 | OUT_DIR=$PROG_DIR/app/build/distributions |
| 89 | mkdir -p $OUT_DIR |
| 90 | [ -f $OUT_DIR/$ZIP ] && rm -f $OUT_DIR/$ZIP |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 91 | pushd $TMP_DIR |
Hans-Christoph Steiner | afd0866 | 2017-04-21 22:47:05 +0200 | [diff] [blame^] | 92 | zip -r $OUT_DIR/$ZIP . |
| 93 | popd |