|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -exuo pipefail |
| 4 | +cd "$(dirname "$0")/../.." |
| 5 | + |
| 6 | +# Configuration |
| 7 | +SOURCE_FILE="obelisk-external.toml" |
| 8 | +TARGET_FILES=("obelisk-local-postgres.toml" "obelisk-local.toml" "obelisk-oci.toml") |
| 9 | + |
| 10 | +# Initialize fail flag |
| 11 | +EXIT_CODE=0 |
| 12 | + |
| 13 | +# Check if source file exists |
| 14 | +if [ ! -f "$SOURCE_FILE" ]; then |
| 15 | + echo "Error: Source file '$SOURCE_FILE' not found." |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +echo "Reading references from $SOURCE_FILE..." |
| 20 | + |
| 21 | +# Extract OCI values using grep and awk |
| 22 | +# 1. grep 'location.oci': gets the relevant lines |
| 23 | +# 2. awk -F'"': splits by quote and prints the 2nd column (the content inside quotes) |
| 24 | +REFERENCES=$(grep 'location.oci' "$SOURCE_FILE" | awk -F'"' '{print $2}') |
| 25 | + |
| 26 | +# Check if we found any references |
| 27 | +if [ -z "$REFERENCES" ]; then |
| 28 | + echo "No 'location.oci' entries found in source file." |
| 29 | + exit 0 |
| 30 | +fi |
| 31 | + |
| 32 | +# Iterate over each OCI reference found in the external config |
| 33 | +for OCI_REF in $REFERENCES; do |
| 34 | + echo "---------------------------------------------------" |
| 35 | + echo "Checking: $OCI_REF" |
| 36 | + |
| 37 | + for TARGET in "${TARGET_FILES[@]}"; do |
| 38 | + if [ ! -f "$TARGET" ]; then |
| 39 | + echo " [ERROR] File missing: $TARGET" |
| 40 | + EXIT_CODE=1 |
| 41 | + continue |
| 42 | + fi |
| 43 | + |
| 44 | + # grep -F: Matches fixed strings (prevents issues with dots/colons in URLs) |
| 45 | + # -q: Quiet mode (exit 0 if found, 1 if not) |
| 46 | + if grep -Fq "$OCI_REF" "$TARGET"; then |
| 47 | + echo " [OK] Found in $TARGET" |
| 48 | + else |
| 49 | + echo " [FAIL] MISSING in $TARGET" |
| 50 | + EXIT_CODE=1 |
| 51 | + fi |
| 52 | + done |
| 53 | +done |
| 54 | + |
| 55 | +echo "---------------------------------------------------" |
| 56 | + |
| 57 | +if [ $EXIT_CODE -eq 0 ]; then |
| 58 | + echo "SUCCESS: All external OCI references are present in target files." |
| 59 | + exit 0 |
| 60 | +else |
| 61 | + echo "FAILURE: Some OCI references are missing." |
| 62 | + exit 1 |
| 63 | +fi |
| 64 | + |
0 commit comments