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 | |
Chirayu Desai | 27f28ec | 2018-02-22 02:45:46 +0530 | [diff] [blame] | 39 | FDROID_APK=F-Droid.apk |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 40 | PRIVEXT_APK=org.fdroid.fdroid.privileged_${VERSION}.apk |
Hans-Christoph Steiner | 386c86d | 2018-03-21 17:46:54 +0100 | [diff] [blame] | 41 | FPE_NAME=F-DroidPrivilegedExtension |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 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/ |
Chirayu Desai | 5228215 | 2017-09-18 22:59:14 +0530 | [diff] [blame] | 47 | cp app/src/main/permissions_org.fdroid.fdroid.privileged.xml $TMP_DIR/ |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 48 | |
| 49 | if [ -z $BINARIES ] ; then |
Hans-Christoph Steiner | d3ba33b | 2017-04-21 22:33:36 +0200 | [diff] [blame] | 50 | 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 Steiner | 386c86d | 2018-03-21 17:46:54 +0100 | [diff] [blame] | 54 | 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 Steiner | d3ba33b | 2017-04-21 22:33:36 +0200 | [diff] [blame] | 57 | else |
Hans-Christoph Steiner | 386c86d | 2018-03-21 17:46:54 +0100 | [diff] [blame] | 58 | echo "No signed debug or release APK found in $OUT_DIR!" |
| 59 | exit 1 |
Hans-Christoph Steiner | d3ba33b | 2017-04-21 22:33:36 +0200 | [diff] [blame] | 60 | fi |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 61 | else |
Hans-Christoph Steiner | 6f972e0 | 2017-04-24 11:13:57 +0200 | [diff] [blame] | 62 | 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 Steiner | 3fcb55e | 2017-04-21 13:39:55 +0200 | [diff] [blame] | 64 | $GPG --verify $TMP_DIR/${PRIVEXT_APK}.asc |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 65 | rm $TMP_DIR/${PRIVEXT_APK}.asc |
Hans-Christoph Steiner | 386c86d | 2018-03-21 17:46:54 +0100 | [diff] [blame] | 66 | mv $TMP_DIR/$PRIVEXT_APK $TMP_DIR/$FPE_NAME.apk |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 67 | fi |
| 68 | |
| 69 | # For both |
Chirayu Desai | 27f28ec | 2018-02-22 02:45:46 +0530 | [diff] [blame] | 70 | curl -L https://f-droid.org/$FDROID_APK > $TMP_DIR/$FDROID_APK |
| 71 | curl -L https://f-droid.org/${FDROID_APK}.asc > $TMP_DIR/${FDROID_APK}.asc |
Hans-Christoph Steiner | 3fcb55e | 2017-04-21 13:39:55 +0200 | [diff] [blame] | 72 | $GPG --verify $TMP_DIR/${FDROID_APK}.asc |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 73 | rm $TMP_DIR/${FDROID_APK}.asc |
Hans-Christoph Steiner | 386c86d | 2018-03-21 17:46:54 +0100 | [diff] [blame] | 74 | test -e $TMP_DIR/F-Droid.apk || mv $TMP_DIR/$FDROID_APK $TMP_DIR/F-Droid.apk |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 75 | |
| 76 | # Make zip |
| 77 | if [ -z $BINARIES ]; then |
Hans-Christoph Steiner | 386c86d | 2018-03-21 17:46:54 +0100 | [diff] [blame] | 78 | ZIPBASE=${FPE_NAME}-${GITVERSION} |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 79 | else |
Hans-Christoph Steiner | 386c86d | 2018-03-21 17:46:54 +0100 | [diff] [blame] | 80 | ZIPBASE=${FPE_NAME}FromBinaries-${GITVERSION} |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 81 | fi |
| 82 | if [ $VARIANT == "debug" ]; then |
| 83 | ZIP=${ZIPBASE}-debug.zip |
| 84 | else |
| 85 | ZIP=${ZIPBASE}.zip |
| 86 | fi |
Hans-Christoph Steiner | afd0866 | 2017-04-21 22:47:05 +0200 | [diff] [blame] | 87 | OUT_DIR=$PROG_DIR/app/build/distributions |
| 88 | mkdir -p $OUT_DIR |
| 89 | [ -f $OUT_DIR/$ZIP ] && rm -f $OUT_DIR/$ZIP |
Chirayu Desai | 93f4f41 | 2017-04-14 21:43:26 +0530 | [diff] [blame] | 90 | pushd $TMP_DIR |
Hans-Christoph Steiner | afd0866 | 2017-04-21 22:47:05 +0200 | [diff] [blame] | 91 | zip -r $OUT_DIR/$ZIP . |
| 92 | popd |