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 |
| 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 |
| 57 | else |
| 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 Steiner | 3fcb55e | 2017-04-21 13:39:55 +0200 | [diff] [blame^] | 60 | $GPG --verify $TMP_DIR/${PRIVEXT_APK}.asc |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 61 | rm $TMP_DIR/${PRIVEXT_APK}.asc |
| 62 | mv $TMP_DIR/$PRIVEXT_APK $TMP_DIR/FDroidPrivilegedExtension.apk |
| 63 | fi |
| 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 Steiner | 3fcb55e | 2017-04-21 13:39:55 +0200 | [diff] [blame^] | 68 | $GPG --verify $TMP_DIR/${FDROID_APK}.asc |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 69 | rm $TMP_DIR/${FDROID_APK}.asc |
| 70 | mv $TMP_DIR/$FDROID_APK $TMP_DIR/FDroid.apk |
| 71 | |
| 72 | # Make zip |
| 73 | if [ -z $BINARIES ]; then |
| 74 | ZIPBASE=FDroidPrivilegedExtension-${GITVERSION} |
| 75 | else |
| 76 | ZIPBASE=FDroidPrivilegedExtensionFromBinaries-${GITVERSION} |
| 77 | fi |
| 78 | if [ $VARIANT == "debug" ]; then |
| 79 | ZIP=${ZIPBASE}-debug.zip |
| 80 | else |
| 81 | ZIP=${ZIPBASE}.zip |
| 82 | fi |
| 83 | mkdir -p $PROG_DIR/build |
| 84 | [ -f $PROG_DIR/build/$ZIP ] && rm $PROG_DIR/build/$ZIP |
| 85 | pushd $TMP_DIR |
| 86 | zip -r $PROG_DIR/build/$ZIP . |
| 87 | popd |