Files
smom-dbis-138/scripts/deployment/merge-env-fragment.sh
zaragoza444 5fc98ed803
Some checks failed
CI/CD Pipeline / Solidity Contracts (push) Failing after 1m37s
CI/CD Pipeline / Security Scanning (push) Successful in 2m33s
CI/CD Pipeline / Lint and Format (push) Failing after 53s
CI/CD Pipeline / Terraform Validation (push) Failing after 26s
CI/CD Pipeline / Kubernetes Validation (push) Successful in 23s
Deploy ChainID 138 / Deploy ChainID 138 (push) Failing after 44s
Validation / validate-genesis (push) Has started running
Validation / validate-terraform (push) Has been cancelled
Validation / validate-kubernetes (push) Has been cancelled
Validation / validate-smart-contracts (push) Has been cancelled
Validation / validate-security (push) Has been cancelled
Validation / validate-documentation (push) Has been cancelled
Verify Deployment / Verify Deployment (push) Failing after 1m3s
fix: normalize CRLF in deploy .env and safe env merge helper
Prevent Fineract connection failures when .env is uploaded from Windows, and add merge-env-fragment.sh to update keys without wiping existing vars.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 18:35:00 -07:00

34 lines
957 B
Bash

#!/usr/bin/env bash
# Merge KEY=VALUE lines from a fragment file into target .env (replace existing keys).
set -euo pipefail
TARGET="${1:?target .env path}"
FRAGMENT="${2:?fragment file path}"
touch "$TARGET"
tmp="$(mktemp)"
if [[ -f "$TARGET" ]]; then
cp "$TARGET" "$tmp"
else
: > "$tmp"
fi
while IFS= read -r line || [[ -n "$line" ]]; do
line="${line//$'\r'/}"
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
key="${line%%=*}"
[[ "$key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
grep -v "^${key}=" "$tmp" > "${tmp}.new" || true
mv "${tmp}.new" "$tmp"
printf '%s\n' "$line" >> "$tmp"
done < "$FRAGMENT"
if grep -q '^OMNL_FINERACT_USER=' "$tmp" && ! grep -q '^OMNL_FINERACT_USERNAME=' "$tmp"; then
u="$(grep '^OMNL_FINERACT_USER=' "$tmp" | cut -d= -f2-)"
printf 'OMNL_FINERACT_USERNAME=%s\n' "$u" >> "$tmp"
fi
mv "$tmp" "$TARGET"
tr -d '\r' <"$TARGET" >"${TARGET}.lf" && mv "${TARGET}.lf" "$TARGET"
chmod 600 "$TARGET"