|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +GITHUB_URL="https://github.com/goafabric" |
| 4 | +WORKDIR="/tmp/repos" # Temporary directory to clone repositories |
| 5 | +REPOLIST="$(pwd)/repos.txt" # List of repositories |
| 6 | + |
| 7 | +# Ensure the working directory exists |
| 8 | +mkdir -p "$WORKDIR" |
| 9 | +cd "$WORKDIR" || exit 1 |
| 10 | + |
| 11 | +# Loop through each repository in repos.txt |
| 12 | +while read -r repo; do |
| 13 | + echo "Processing repository: $repo" |
| 14 | + |
| 15 | + # Clone the repository (shallow clone for speed) |
| 16 | + git clone --depth 1 "$GITHUB_URL/$repo.git" "$repo" 2>/dev/null |
| 17 | + |
| 18 | + # Navigate into the repository |
| 19 | + cd "$repo" || continue |
| 20 | + |
| 21 | + # Ensure we are on the main branch |
| 22 | + git checkout main 2>/dev/null || git checkout master 2>/dev/null |
| 23 | + |
| 24 | + # Check if application.yaml exists |
| 25 | + FILE="src/main/resources/application.yml" |
| 26 | + if [[ -f "$FILE" ]]; then |
| 27 | + echo "Found inside $repo" |
| 28 | + |
| 29 | + # Extract the adapter block and process it: |
| 30 | + sed -n '/^adapter:/,/^[^ ]/p' "$FILE" | \ |
| 31 | + awk ' |
| 32 | + function trim(s) { sub(/^[ \t]+/, "", s); sub(/[ \t]+$/, "", s); return s } |
| 33 | + BEGIN { current_service="" } |
| 34 | + # Look for a key at 2-space indent that is “empty” (ends with a colon only) |
| 35 | + /^[ \t]{2}[a-zA-Z0-9_-]+:[ \t]*$/ { |
| 36 | + key = trim($0) |
| 37 | + sub(/:$/, "", key) |
| 38 | + # Skip common non-service keys (like "timeout") |
| 39 | + if (key != "timeout") { |
| 40 | + current_service = key |
| 41 | + } else { |
| 42 | + current_service = "" |
| 43 | + } |
| 44 | + next |
| 45 | + } |
| 46 | + # Look for a line at 4-space indent starting with "url:" |
| 47 | + /^[ \t]{4}url:[ \t]*/ { |
| 48 | + if (current_service != "") { |
| 49 | + line = trim($0) |
| 50 | + sub(/^url:[ \t]*/, "", line) |
| 51 | + print "adapter." current_service ".url=" line |
| 52 | + } |
| 53 | + } |
| 54 | + ' |
| 55 | + echo "-------------------------" |
| 56 | + fi |
| 57 | + |
| 58 | + # Cleanup and move back |
| 59 | + cd "$WORKDIR" |
| 60 | + rm -rf "$repo" # Remove cloned repo to save space |
| 61 | +done < "$REPOLIST" |
0 commit comments