|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Cross-platform sed -i handling |
| 4 | +sedi() { |
| 5 | + # Usage: sedi 's/foo/bar/' filename |
| 6 | + if [[ "$(uname)" == "Darwin" ]]; then |
| 7 | + sed -i '' "$@" |
| 8 | + else |
| 9 | + sed -i "$@" |
| 10 | + fi |
| 11 | +} |
| 12 | + |
| 13 | +# Get the directory of this script |
| 14 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 15 | +PROJECT_ROOT="$SCRIPT_DIR/.." |
| 16 | +GRADLE_FILE="$PROJECT_ROOT/app/build.gradle.kts" |
| 17 | + |
| 18 | +ENABLE_FIREBASE=${1:-true} # Default to true if not provided |
| 19 | + |
| 20 | +# Check if the gradle file exists |
| 21 | +if [ ! -f "$GRADLE_FILE" ]; then |
| 22 | + echo "Error: $GRADLE_FILE not found. Please run this script from the project root or ensure the file exists." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Handle Firebase plugin lines |
| 27 | +if [ "$ENABLE_FIREBASE" = false ]; then |
| 28 | + # Comment out the lines if not already commented |
| 29 | + sedi '/^[[:space:]]*id("com.google.gms.google-services")/s/^/\/\/ /' "$GRADLE_FILE" |
| 30 | + sedi '/^[[:space:]]*id("com.google.firebase.crashlytics")/s/^/\/\/ /' "$GRADLE_FILE" |
| 31 | + # Remove duplicate comment markers if any |
| 32 | + sedi 's/^\(\/\/ \)*\/\//\/\//g' "$GRADLE_FILE" |
| 33 | +else |
| 34 | + # Uncomment the lines if commented |
| 35 | + sedi 's/^[[:space:]]*\/\/[[:space:]]*\(id("com.google.gms.google-services")\)/\1/' "$GRADLE_FILE" |
| 36 | + sedi 's/^[[:space:]]*\/\/[[:space:]]*\(id("com.google.firebase.crashlytics")\)/\1/' "$GRADLE_FILE" |
| 37 | +fi |
| 38 | + |
| 39 | +# Usage: |
| 40 | +# bash ./scripts/enableDisableFirebase.sh false # to comment out Firebase plugins |
| 41 | +# bash ./scripts/enableDisableFirebase.sh true # to uncomment Firebase plugins |
| 42 | +# Or make the script executable and run directly: |
| 43 | +# chmod +x ./scripts/enableDisableFirebase.sh |
| 44 | +# ./scripts/enableDisableFirebase.sh false |
0 commit comments