|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +read -p "Keystore path [./release-key.jks]: " USER_KEYSTORE_PATH |
| 6 | +KEYSTORE_PATH="${USER_KEYSTORE_PATH:-./release-key.jks}" |
| 7 | +KEYSTORE_ABS_PATH=$(realpath $KEYSTORE_PATH) |
| 8 | + |
| 9 | +if [[ ! -f "$KEYSTORE_ABS_PATH" ]]; then |
| 10 | + echo "Keystore file not found at: $KEYSTORE_ABS_PATH" |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +echo "Enter keystore credentials:" |
| 15 | +read -p "Key alias: " KEY_ALIAS |
| 16 | +read -s -p "Keystore password: " KEYSTORE_PASSWORD; echo |
| 17 | + |
| 18 | +rm -rf build |
| 19 | +mkdir -p build |
| 20 | +for appdir in */ ; do |
| 21 | + if [[ -f "$appdir/config.json" && -f "$appdir/gradlew" ]]; then |
| 22 | + echo "====================================" |
| 23 | + echo "Building app in: $appdir" |
| 24 | + |
| 25 | + cd "$appdir" |
| 26 | + |
| 27 | + # Read config |
| 28 | + FLAG=$(jq -r '.flag' config.json) |
| 29 | + FILES=$(jq -r '.files[]' config.json) |
| 30 | + |
| 31 | + # Placeholder build |
| 32 | + echo "Building placeholder version..." |
| 33 | + ./gradlew clean assembleRelease \ |
| 34 | + -Pandroid.injected.signing.store.file=$KEYSTORE_ABS_PATH \ |
| 35 | + -Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \ |
| 36 | + -Pandroid.injected.signing.key.alias=$KEY_ALIAS \ |
| 37 | + -Pandroid.injected.signing.key.password=$KEYSTORE_PASSWORD |
| 38 | + |
| 39 | + cp app/build/outputs/apk/release/app-release.apk "../build/${appdir%/}-placeholder.apk" |
| 40 | + |
| 41 | + echo -e "\n\n" |
| 42 | + # Flagged build |
| 43 | + echo "Replacing placeholder string with actual flag..." |
| 44 | + for file in $FILES; do |
| 45 | + echo "Modifying file: $file" |
| 46 | + sed -i "s/DROIDGROUND_FLAG_PLACEHOLDER/${FLAG//\//\\/}/g" "$file" |
| 47 | + done |
| 48 | + |
| 49 | + echo "" |
| 50 | + echo "Building flagged version..." |
| 51 | + ./gradlew clean assembleRelease \ |
| 52 | + -Pandroid.injected.signing.store.file=$KEYSTORE_ABS_PATH \ |
| 53 | + -Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \ |
| 54 | + -Pandroid.injected.signing.key.alias=$KEY_ALIAS \ |
| 55 | + -Pandroid.injected.signing.key.password=$KEYSTORE_PASSWORD |
| 56 | + |
| 57 | + cp app/build/outputs/apk/release/app-release.apk "../build/${appdir%/}-flag.apk" |
| 58 | + |
| 59 | + echo "Restoring modified source files..." |
| 60 | + git restore . |
| 61 | + |
| 62 | + cd .. |
| 63 | + echo "Finished building: $appdir" |
| 64 | + echo |
| 65 | + fi |
| 66 | +done |
| 67 | + |
| 68 | +echo "All builds complete. APKs are in the \"build\" folder." |
0 commit comments